[TYPO3-mvc] Complex validation scenario

François Suter fsu-lists at cobweb.ch
Mon Jun 27 09:54:55 CEST 2011


Hi,

As a follow-up to this thread, I wanted to post the solution I found 
which finally suits my needs. I discovered by digging (and digging, and 
digging) into the Extbase source code, that it was possible to register 
a custom validator for your model. How to achieve this is described in 
the phpDoc of 
Tx_Extbase_Validation_ValidatorResolver::buildBaseValidatorConjunction()
(which is actually still FLOW3 comments ;-) ).

I'm not exactly sure what validator class your custom validator is 
supposed to inherit from. I chose to extend 
Tx_Extbase_Validation_Validator_GenericObjectValidator.

The method you *must* override is isValid(), which will receive not the 
usual arguments object, but the model object itself. This was really 
fine with me, as it's exactly what I needed ;-)

With the model object available, I could implement any rule I wanted and 
- more importantly - issue errors that are then merged the other 
validation errors, which means that they can be handled exactly the same 
way in Fluid. This is the really good part. During the various tries I 
made, I found several places where I could put my custom validation and 
issue errors, but none where they would fit within the general error 
handling and reporting scheme. With the custom model validator, they do.

Cheers

-- 
Francois Suter
Cobweb Development Sarl - http://www.cobweb.ch


More information about the TYPO3-project-typo3v4mvc mailing list