Issue Bug Closed

#62500Validator based on DataType of controller-action argument is added twice

Michael Grundkötter 10/27/14, 17:33 updated 02/14/15, 23:16

Description

When I add a default validator for a model class and put it into Classes/Domain/Validator/MyClassValidator it gets added to the validation chain by the action controller automatically. The problem is, that when I combine this with property annotations that also do some validation, this thing gets added twice. In the method

\TYPO3\CMS\Extbase\Mvc\Controller\ActionController::initializeActionMethodValidators

there is this line of code that adds the domain validator for the first time:

$parameterValidators = $this->validatorResolver->buildMethodArgumentsValidatorConjunctions(get_class($this), $this->actionMethodName, $methodParameters);

Beneath that, it is also inside “$baseValidatorConjunction” and so it is added as a separate validator AND as a part of the conjunction. Thus, all the validation is done twice and of course, the error messages also appear twice.

$baseValidatorConjunction = $this->validatorResolver->getBaseValidatorConjunction($argument->getDataType());
if (count($baseValidatorConjunction) > 0) {
    $validator->addValidator($baseValidatorConjunction);
}
$argument->setValidator($validator);

I managed to fix that by altering the code like that:

if (count($baseValidatorConjunction) > 0) {
    $argument->setValidator($baseValidatorConjunction);
} else {
    $argument->setValidator($validator);
}

But I guess this solution is not the best as it is ignoring everything that has been set as validator before. Even if it’s not just this domain validator class.

Reviews 0

No change resolves or names this issue in its commit message, and no comment links one.