protected function _recursivelyPrepareForm(IfwPsn_Vendor_Zend_Form $form) { $belongsTo = $form instanceof IfwPsn_Vendor_Zend_Form ? $form->getElementsBelongTo() : null; $elementContent = ''; $separator = $this->getSeparator(); $translator = $form->getTranslator(); $view = $form->getView(); foreach ($form as $item) { $item->setView($view)->setTranslator($translator); if ($item instanceof IfwPsn_Vendor_Zend_Form_Element) { $item->setBelongsTo($belongsTo); } elseif (!empty($belongsTo) && $item instanceof IfwPsn_Vendor_Zend_Form) { if ($item->isArray()) { $name = $this->mergeBelongsTo($belongsTo, $item->getElementsBelongTo()); $item->setElementsBelongTo($name, true); } else { $item->setElementsBelongTo($belongsTo, true); } $this->_recursivelyPrepareForm($item); } elseif (!empty($belongsTo) && $item instanceof IfwPsn_Vendor_Zend_Form_DisplayGroup) { foreach ($item as $element) { $element->setBelongsTo($belongsTo); } } } }
/** * @param array $data * @return bool * @throws IfwPsn_Vendor_Zend_Form_Exception */ public function isValid($data) { if ($this->hasNonce() && !$this->verifyNonce()) { $this->_validNonce = false; return false; } return parent::isValid($data); }
/** * Recurse through a form object, rendering errors * * @param IfwPsn_Vendor_Zend_Form $form * @param IfwPsn_Vendor_Zend_View_Interface $view * @return string */ protected function _recurseForm(IfwPsn_Vendor_Zend_Form $form, IfwPsn_Vendor_Zend_View_Interface $view) { $content = ''; $custom = $form->getCustomMessages(); if ($this->getShowCustomFormErrors() && count($custom)) { $content .= $this->getMarkupListItemStart() . $view->formErrors($custom, $this->getOptions()) . $this->getMarkupListItemEnd(); } foreach ($form->getElementsAndSubFormsOrdered() as $subitem) { if ($subitem instanceof IfwPsn_Vendor_Zend_Form_Element && !$this->getOnlyCustomFormErrors()) { $messages = $subitem->getMessages(); if (count($messages)) { $subitem->setView($view); $content .= $this->getMarkupListItemStart() . $this->renderLabel($subitem, $view) . $view->formErrors($messages, $this->getOptions()) . $this->getMarkupListItemEnd(); } } else { if ($subitem instanceof IfwPsn_Vendor_Zend_Form && !$this->ignoreSubForms()) { $markup = $this->_recurseForm($subitem, $view); if (!empty($markup)) { $content .= $this->getMarkupListStart() . $markup . $this->getMarkupListEnd(); } } } } return $content; }
/** * Retrieve translator object * * @return IfwPsn_Vendor_Zend_Translate_Adapter|null */ public function getTranslator() { if ($this->translatorIsDisabled()) { return null; } if (null === $this->_translator) { require_once IFW_PSN_LIB_ROOT . 'IfwPsn/Vendor/Zend/Form.php'; return IfwPsn_Vendor_Zend_Form::getDefaultTranslator(); } return $this->_translator; }
/** * Validate element value * * If a translation adapter is registered, any error messages will be * translated according to the current locale, using the given error code; * if no matching translation is found, the original message will be * utilized. * * Note: The *filtered* value is validated. * * @param mixed $value * @param mixed $context * @return boolean */ public function isValid($value, $context = null) { $this->setValue($value); $value = $this->getValue(); if (('' === $value || null === $value) && !$this->isRequired() && $this->getAllowEmpty()) { return true; } if ($this->isRequired() && $this->autoInsertNotEmptyValidator() && !$this->getValidator('NotEmpty')) { $validators = $this->getValidators(); $notEmpty = array('validator' => 'NotEmpty', 'breakChainOnFailure' => true); array_unshift($validators, $notEmpty); $this->setValidators($validators); } // Find the correct translator. IfwPsn_Vendor_Zend_Validate_Abstract::getDefaultTranslator() // will get either the static translator attached to IfwPsn_Vendor_Zend_Validate_Abstract // or the 'IfwPsn_Vendor_Zend_Translate' from IfwPsn_Vendor_Zend_Registry. if (IfwPsn_Vendor_Zend_Validate_Abstract::hasDefaultTranslator() && !IfwPsn_Vendor_Zend_Form::hasDefaultTranslator()) { $translator = IfwPsn_Vendor_Zend_Validate_Abstract::getDefaultTranslator(); if ($this->hasTranslator()) { // only pick up this element's translator if it was attached directly. $translator = $this->getTranslator(); } } else { $translator = $this->getTranslator(); } $this->_messages = array(); $this->_errors = array(); $result = true; $isArray = $this->isArray(); foreach ($this->getValidators() as $key => $validator) { if (method_exists($validator, 'setTranslator')) { if (method_exists($validator, 'hasTranslator')) { if (!$validator->hasTranslator()) { $validator->setTranslator($translator); } } else { $validator->setTranslator($translator); } } if (method_exists($validator, 'setDisableTranslator')) { $validator->setDisableTranslator($this->translatorIsDisabled()); } if ($isArray && is_array($value)) { $messages = array(); $errors = array(); if (empty($value)) { if ($this->isRequired() || !$this->isRequired() && !$this->getAllowEmpty()) { $value = ''; } } foreach ((array) $value as $val) { if (!$validator->isValid($val, $context)) { $result = false; if ($this->_hasErrorMessages()) { $messages = $this->_getErrorMessages(); $errors = $messages; } else { $messages = array_merge($messages, $validator->getMessages()); $errors = array_merge($errors, $validator->getErrors()); } } } if ($result) { continue; } } elseif ($validator->isValid($value, $context)) { continue; } else { $result = false; if ($this->_hasErrorMessages()) { $messages = $this->_getErrorMessages(); $errors = $messages; } else { $messages = $validator->getMessages(); $errors = array_keys($messages); } } $result = false; $this->_messages = array_merge($this->_messages, $messages); $this->_errors = array_merge($this->_errors, $errors); if ($validator->zfBreakChainOnFailure) { break; } } // If element manually flagged as invalid, return false if ($this->_isErrorForced) { return false; } return $result; }
/** * Set global default translator object * * @param IfwPsn_Vendor_Zend_Translate|IfwPsn_Vendor_Zend_Translate_Adapter|null $translator * @return void */ public static function setDefaultTranslator($translator = null) { if (null === $translator) { self::$_translatorDefault = null; } elseif ($translator instanceof IfwPsn_Vendor_Zend_Translate_Adapter) { self::$_translatorDefault = $translator; } elseif ($translator instanceof IfwPsn_Vendor_Zend_Translate) { self::$_translatorDefault = $translator->getAdapter(); } else { require_once IFW_PSN_LIB_ROOT . 'IfwPsn/Vendor/Zend/Form/Exception.php'; throw new IfwPsn_Vendor_Zend_Form_Exception('Invalid translator specified'); } }