[TYPO3-mvc] Model validator: How to tie a validation error to a property in extbase >= 1.4?

Patrick Schriner patrick.schriner at diemedialen.de
Tue Mar 20 10:49:57 CET 2012


Hi,

I found this:

http://typo3.comnex.net/2011/11/eigener-validator-fr-modelproperty-mit-bersetzung-bzw-eigener-fehlermeldung-extbase-14-practise/

If I understand  
http://git.typo3.org/TYPO3v4/CoreProjects/MVC/extbase.git?a=commitdiff;h=d75874a69c683a61e3114a34c2f28f2b23030d5a  
correctly, you are supposed to write a validate() method, which (combined  
with the above) would look like this:

(Bit of guesswork here - I'm not sure whether you are supposed to  
implement Tx_Extbase_Validation_Validator_AbstractObjectValidator)

public function validate($object) {
	$this->result = new Tx_Extbase_Error_Result();
	$this->result->forProperty('blub')
                 ->addError(new  
Tx_Extbase_Error_Error(Tx_Extbase_Utility_Localization::translate('error.'  
. $property . 'Empty.message', 'myextension'), time())));
	return $this->result;
}

This is just drycoding guesswork, but might help?

-

On a side note: Some of the changes don't make sense to me:

Why was

+ public function validate($value) {
+               $this->result = new Tx_Extbase_Error_Result();
+               $this->isValid($value);
+               return $this->result;
+       }

introduced in Tx_Extbase_Validation_Validator_AbstractValidator, when all  
isValid() methods are marked as deprecated?

On Mon, 19 Mar 2012 17:13:10 +0100, Oliver Klee  
<typo3-german-02 at oliverklee.de> wrote:

> Hi all,
>
> I'm currently trying to find out how to tie a validation error to a
> certain field in my model validator. As of extbase 1.4, $this->errors
> and Tx_Extbase_Validation_PropertyError are deprecated, and so this code
> uses deprecated code:
>
> class Tx_Foo_Domain_Validator_CoffeeValidator extends
> Tx_Extbase_Validation_Validator_AbstractValidator {
> 	public function isValid($model) {
> 		$this->errors = array();
> 		$this->errors['name'] = new
> Tx_Extbase_Validation_PropertyError('name', 1331893182);
> ...
>
> On the wiki page about 1.4, the part about the new validation API is
> still marked as missing:
> <http://forge.typo3.org/projects/typo3v4-mvc/wiki/Extbase_Version_14>
>
> So, what's the proper way to add validation errors for certain model
> field in my model validator in extbase >= 1.4 (while still using the old
> property mapper)?
>
> Thanks,
>
>
> Oli

-- 
Patrick Schriner


More information about the TYPO3-project-typo3v4mvc mailing list