File indexing completed on 2025-03-02 05:29:24

0001 <?php
0002 /**
0003  * Zend Framework
0004  *
0005  * LICENSE
0006  *
0007  * This source file is subject to the new BSD license that is bundled
0008  * with this package in the file LICENSE.txt.
0009  * It is also available through the world-wide-web at this URL:
0010  * http://framework.zend.com/license/new-bsd
0011  * If you did not receive a copy of the license and are unable to
0012  * obtain it through the world-wide-web, please send an email
0013  * to license@zend.com so we can send you a copy immediately.
0014  *
0015  * @category   Zend
0016  * @package    Zend_Form
0017  * @subpackage Decorator
0018  * @copyright  Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
0019  * @license    http://framework.zend.com/license/new-bsd     New BSD License
0020  */
0021 
0022 /** Zend_Form_Decorator_Abstract */
0023 // require_once 'Zend/Form/Decorator/Abstract.php';
0024 
0025 /**
0026  * Zend_Form_Decorator_Errors
0027  *
0028  * Any options passed will be used as HTML attributes of the ul tag for the errors.
0029  *
0030  * @category   Zend
0031  * @package    Zend_Form
0032  * @subpackage Decorator
0033  * @copyright  Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
0034  * @license    http://framework.zend.com/license/new-bsd     New BSD License
0035  * @version    $Id$
0036  */
0037 class Zend_Form_Decorator_Errors extends Zend_Form_Decorator_Abstract
0038 {
0039     /**
0040      * Render errors
0041      *
0042      * @param  string $content
0043      * @return string
0044      */
0045     public function render($content)
0046     {
0047         $element = $this->getElement();
0048         $view    = $element->getView();
0049         if (null === $view) {
0050             return $content;
0051         }
0052 
0053         // Get error messages
0054         if ($element instanceof Zend_Form
0055             && null !== $element->getElementsBelongTo()
0056         ) {
0057             $errors = $element->getMessages(null, true);
0058         } else {
0059             $errors = $element->getMessages();
0060         }
0061 
0062         if (empty($errors)) {
0063             return $content;
0064         }
0065 
0066         $separator = $this->getSeparator();
0067         $placement = $this->getPlacement();
0068         $errors    = $view->formErrors($errors, $this->getOptions());
0069 
0070         switch ($placement) {
0071             case self::APPEND:
0072                 return $content . $separator . $errors;
0073             case self::PREPEND:
0074                 return $errors . $separator . $content;
0075         }
0076     }
0077 }