[TYPO3-mvc] yes, nested objects validation is a missing feature at current extbase version (1.3)

Eric S. Auchterberge endurans at gmail.com
Mon Aug 15 15:32:05 CEST 2011


Thanks you Steffen for such snippet based answer, which provided fast
guidance to use getBaseValidatorConjunction().

Notice that the clause:

   if(!is_object($value) || $value instanceof
Tx_YourExtensionName_Domain_Model_YourModelName) {
                       return FALSE;
               }

must be:

   if(!is_object($value) || !($value instanceof
Tx_YourExtensionName_Domain_Model_YourModelName)) {
                       return FALSE;
               }

Regards,
Eric



On Thu, Aug 11, 2011 at 5:04 AM, Steffen Ritter <info at rs-websystems.de>wrote:

> Does anybody can suggest a proven approach to workaround this?
>>
> YES :) write your own Model-Validator, which calls the validators to the
> subojbects, and add theire errors as propertyErrors....
>
> class Tx_Rs***_Domain_Validator_**OrderValidator extends
> Tx_Extbase_Validation_**Validator_AbstractValidator {
>
>        /**
>         * @var $objectManager Tx_Extbase_Object_**ObjectManager
>         */
>        protected $objectManager;
>
>        public function injectObjectManager(Tx_**Extbase_Object_ObjectManager
> $objMgr) {
>                $this->objectManager = $objMgr;
>        }
>        /**
>         * Checks if the given value is valid according to the validator.
>         *
>         * If at least one error occurred, the result is FALSE and any
> errors can
>         * be retrieved through the getErrors() method.
>         *
>         * Note that all implementations of this method should set
> $this->errors() to an
>         * empty array before validating.
>         *
>         * @param mixed $value The value that should be validated
>         * @return boolean TRUE if the value is valid, FALSE if an error
> occured
>         */
>        public function isValid($value) {
>                if(!is_object($value) || $value instanceof
> Tx_Rs***_Domain_Model_Order) {
>                        return FALSE;
>                }
>
>                $addressValidator = $this->objectManager->get('Tx_**
> Extbase_Validation_**ValidatorResolver')->**getBaseValidatorConjunction('*
> *Tx_Rs***_Domain_Model_**OrderAddress');
>                if (!$addressValidator->isValid($**value->getBillAddress()))
> {
>                        $this->errors[] = $this->createPropertyError('**billAddress',
> $addressValidator->getErrors()**);
>                }
>
>                return count($this->errors) == 0;
>        }
>
>        /**
>         * @param string $propertyName
>         * @param array $errors
>         * @return Tx_Extbase_Validation_**PropertyError
>         */
>        protected function createPropertyError($**propertyName, array
> $errors) {
>                $error = new Tx_Extbase_Validation_**
> PropertyError($propertyName);
>                $error->addErrors($errors);
>                return $error;
>
>        }
> }
> ______________________________**_________________
> TYPO3-project-typo3v4mvc mailing list
> TYPO3-project-typo3v4mvc@**lists.typo3.org<TYPO3-project-typo3v4mvc at lists.typo3.org>
> http://lists.typo3.org/cgi-**bin/mailman/listinfo/typo3-**
> project-typo3v4mvc<http://lists.typo3.org/cgi-bin/mailman/listinfo/typo3-project-typo3v4mvc>
>


More information about the TYPO3-project-typo3v4mvc mailing list