File indexing completed on 2024-12-22 05:36:42

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_FormElements */
0023 // require_once 'Zend/Form/Decorator/FormElements.php';
0024 
0025 /**
0026  * Zend_Form_Decorator_PrepareElements
0027  *
0028  * Render all form elements registered with current form
0029  *
0030  * Accepts following options:
0031  * - separator: Separator to use between elements
0032  *
0033  * Any other options passed will be used as HTML attributes of the form tag.
0034  *
0035  * @category   Zend
0036  * @package    Zend_Form
0037  * @subpackage Decorator
0038  * @copyright  Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
0039  * @license    http://framework.zend.com/license/new-bsd     New BSD License
0040  * @version    $Id$
0041  */
0042 class Zend_Form_Decorator_PrepareElements extends Zend_Form_Decorator_FormElements
0043 {
0044     /**
0045      * Render form elements
0046      *
0047      * @param  string $content
0048      * @return string
0049      */
0050     public function render($content)
0051     {
0052         $form = $this->getElement();
0053         if ((!$form instanceof Zend_Form) && (!$form instanceof Zend_Form_DisplayGroup)) {
0054             return $content;
0055         }
0056 
0057         $this->_recursivelyPrepareForm($form);
0058 
0059         return $content;
0060     }
0061 
0062     protected function _recursivelyPrepareForm(Zend_Form $form)
0063     {
0064         $belongsTo      = ($form instanceof Zend_Form) ? $form->getElementsBelongTo() : null;
0065         $elementContent = '';
0066         $separator      = $this->getSeparator();
0067         $translator     = $form->getTranslator();
0068         $view           = $form->getView();
0069 
0070         foreach ($form as $item) {
0071             $item->setView($view)
0072                  ->setTranslator($translator);
0073             if ($item instanceof Zend_Form_Element) {
0074                 $item->setBelongsTo($belongsTo);
0075             } elseif (!empty($belongsTo) && ($item instanceof Zend_Form)) {
0076                 if ($item->isArray()) {
0077                     $name = $this->mergeBelongsTo($belongsTo, $item->getElementsBelongTo());
0078                     $item->setElementsBelongTo($name, true);
0079                 } else {
0080                     $item->setElementsBelongTo($belongsTo, true);
0081                 }
0082                 $this->_recursivelyPrepareForm($item);
0083             } elseif (!empty($belongsTo) && ($item instanceof Zend_Form_DisplayGroup)) {
0084                 foreach ($item as $element) {
0085                     $element->setBelongsTo($belongsTo);
0086                 }
0087             }
0088         }
0089     }
0090 }