[TYPO3-mvc] What kind of Validator do i need

Philipp philippwrann at gmx.at
Tue Oct 8 15:14:24 CEST 2013


Hi,

i created an extension that provides some base-classes you can extend (those are contact-request objects). Because i cant validate an interface or abstract class i need to validate a request manually. So i though i write my own validator for mapping my object into the configured target class.

Short scribble for the scenario:
My extension: Contact
 - Domain
 - - Model
- - - Request

Other Extension
- Domain
- - Model
- - - SpecialRequest extends Request

with typoscript i add a new "key" with some configs. Ther a key "special" is configured to use that Model.
So i have a newRequest and createRequest action in my Contact Extension.

The createAction has this annotation:
/**
* Save the new request and send it
* @param array $request
* @validate $request \Vendor\Contact\Domain\Validator\RequestValidator
*/
public function createAction($request) { }

The RequestValidator extends the class \TYPO3\CMS\Extbase\Validation\Validator\AbstractValidator

There i have my isValid() method:
/**
 * @param array $form
 * @return \bool
 */
public function isValid($form) {
	$className = $this->requestService->getModelName($form['key']);
	$this->requestService->convert($form);
	$validatorResolver = $this->objectManager->get('TYPO3\\CMS\\Extbase\\Validation\\ValidatorResolver');
	/* @var $validatorResolver \TYPO3\CMS\Extbase\Validation\ValidatorResolver */
	$validator = $validatorResolver->getBaseValidatorConjunction($className);
	/* @var $validator \TYPO3\CMS\Extbase\Validation\Validator\ConjunctionValidator */
	$result = $validator->validate($form);
	$this->result = $result;
	$this->errors = $result->getFlattenedErrors();
}

Now the problem is (since 6.1) that the validation works on the one hand, but on the other my request has no errors, so the form.errors viewHelper does not display anything. Thats pretty annoying.

Do you understand my Problem?
Do i have to extend the GenericObjectValidator instead? But i pass an array as argument, otherwise i would not be able to modify it in any format i want...


More information about the TYPO3-project-typo3v4mvc mailing list