Project

General

Profile

Actions

Bug #62500

closed

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

Added by Michael Grundkötter over 9 years ago. Updated about 9 years ago.

Status:
Closed
Priority:
Should have
Assignee:
-
Category:
Extbase
Target version:
-
Start date:
2014-10-27
Due date:
% Done:

0%

Estimated time:
TYPO3 Version:
6.2
PHP Version:
5.5
Tags:
Complexity:
Is Regression:
No
Sprint Focus:

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.


Related issues 1 (0 open1 closed)

Related to TYPO3 Core - Bug #52607: Domain Model validators are executed twiceClosedAlexander Schnitzler2013-10-08

Actions
Actions #1

Updated by Alexander Schnitzler about 9 years ago

  • Status changed from New to Closed

Please see related issue and if possible, review the patch. :)

Actions

Also available in: Atom PDF