how to use validationResover

90 Views Asked by At

Like shown here I want to use the validationResolver to dynamically validate user inputs in my App. Therefore I want to proove, if a condition is true in my controller. If the condition is true, I want to validate with an own validator.

For that I tried that:

public function createAction(Object $newObject) { 
    $TS = $newObject->getSomeProperty();
    $ABT = $newObject->getSomeOtherProperty();
    if ($TS === 'specialvalue') {
          $validatorResolver->createValidator('Your.Package:Foo'));
    }

But I get (of course) an 500-exception:

#1: Notice: Undefined variable: validatorResolver in /var/www...

Please give me a hint how to use the $validatorResolver.

1

There are 1 best solutions below

0
On BEST ANSWER

I did it now this way:

public function createAction(Object $newObject) {
    $TS = $newObject->getSomeProperty();
    $ABT = $newObject->getSomeOtherProperty();
    if ($ABT === 'specialvalue') {
        $validatorResolver = new \TYPO3\Flow\Validation\ValidatorResolver();
        $customValidator = $validatorResolver->createValidator('Your.Package:Foo');
        $result = $customValidator->validate($TS);

        if ($result->hasErrors()) {
             $this->flashMessageContainer->addMessage(new \TYPO3\Flow\Error\Error('Here you can type in the error message!'));
            $this->errorAction()->forwardToReferringRequest();
        }

    }
    ....
    ....
}