Skip to content
This repository has been archived by the owner on Mar 1, 2023. It is now read-only.

Commit

Permalink
[TASK] Initialize validator messages before validation
Browse files Browse the repository at this point in the history
This allows more flexibility for the messages initialization; for
instance you can dynamically build the messages list in the method
`initializeObject()` of your validator, then they will be processed just
before the validation actually runs.
  • Loading branch information
romm committed Aug 11, 2017
1 parent 2c4763f commit a47a142
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions Classes/Validation/Validator/AbstractValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
use Romm\Formz\Form\FormInterface;
use Romm\Formz\Service\MessageService;
use Romm\Formz\Validation\DataObject\ValidatorDataObject;
use TYPO3\CMS\Extbase\Error\Result;

abstract class AbstractValidator extends \TYPO3\CMS\Extbase\Validation\Validator\AbstractValidator
{
Expand Down Expand Up @@ -96,11 +97,30 @@ final public function __construct(array $options = [], ValidatorDataObject $data

$this->dataObject = $dataObject;
$this->form = $dataObject->getFormObject()->getForm();
}

/**
* @param mixed $value
* @return Result
*/
public function validate($value)
{
/*
* Messages are initialized just before the validation actually runs,
* and not in the constructor.
*
* This allows more flexibility for the messages initialization; for
* instance you can dynamically build the messages list in the method
* `initializeObject()` of your validator, then they will be processed
* just below.
*/
$this->messages = MessageService::get()->filterMessages(
$this->dataObject->getValidation()->getMessages(),
$this->supportedMessages,
(bool)$this->supportsAllMessages
);

return parent::validate($value);
}

/**
Expand Down

0 comments on commit a47a142

Please sign in to comment.