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_Abstract */ 0023 // require_once 'Zend/Form/Decorator/Abstract.php'; 0024 0025 /** 0026 * Zend_Form_Decorator_Fieldset 0027 * 0028 * Any options passed will be used as HTML attributes of the fieldset tag. 0029 * 0030 * 0031 * @category Zend 0032 * @package Zend_Form 0033 * @subpackage Decorator 0034 * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com) 0035 * @license http://framework.zend.com/license/new-bsd New BSD License 0036 * @version $Id$ 0037 */ 0038 class Zend_Form_Decorator_Fieldset extends Zend_Form_Decorator_Abstract 0039 { 0040 /** 0041 * Attribs that should be removed prior to rendering 0042 * @var array 0043 */ 0044 public $stripAttribs = array( 0045 'action', 0046 'enctype', 0047 'helper', 0048 'method', 0049 'name', 0050 'accept-charset', 0051 ); 0052 0053 /** 0054 * Fieldset legend 0055 * @var string 0056 */ 0057 protected $_legend; 0058 0059 /** 0060 * Default placement: surround content 0061 * @var string 0062 */ 0063 protected $_placement = null; 0064 0065 /** 0066 * Get options 0067 * 0068 * Merges in element attributes as well. 0069 * 0070 * @return array 0071 */ 0072 public function getOptions() 0073 { 0074 $options = parent::getOptions(); 0075 if (null !== ($element = $this->getElement())) { 0076 $attribs = $element->getAttribs(); 0077 $options = array_merge($attribs, $options); 0078 $this->setOptions($options); 0079 } 0080 return $options; 0081 } 0082 0083 /** 0084 * Set legend 0085 * 0086 * @param string $value 0087 * @return Zend_Form_Decorator_Fieldset 0088 */ 0089 public function setLegend($value) 0090 { 0091 $this->_legend = (string) $value; 0092 return $this; 0093 } 0094 0095 /** 0096 * Get legend 0097 * 0098 * @return string 0099 */ 0100 public function getLegend() 0101 { 0102 $legend = $this->_legend; 0103 if ((null === $legend) && (null !== ($element = $this->getElement()))) { 0104 if (method_exists($element, 'getLegend')) { 0105 $legend = $element->getLegend(); 0106 $this->setLegend($legend); 0107 } 0108 } 0109 if ((null === $legend) && (null !== ($legend = $this->getOption('legend')))) { 0110 $this->setLegend($legend); 0111 $this->removeOption('legend'); 0112 } 0113 0114 return $legend; 0115 } 0116 0117 /** 0118 * Render a fieldset 0119 * 0120 * @param string $content 0121 * @return string 0122 */ 0123 public function render($content) 0124 { 0125 $element = $this->getElement(); 0126 $view = $element->getView(); 0127 if (null === $view) { 0128 return $content; 0129 } 0130 0131 $legend = $this->getLegend(); 0132 $attribs = $this->getOptions(); 0133 $name = $element->getFullyQualifiedName(); 0134 $id = (string)$element->getId(); 0135 0136 if ((!array_key_exists('id', $attribs) || $attribs['id'] == $id) && '' !== $id) { 0137 $attribs['id'] = 'fieldset-' . $id; 0138 } 0139 0140 if (null !== $legend) { 0141 if (null !== ($translator = $element->getTranslator())) { 0142 $legend = $translator->translate($legend); 0143 } 0144 0145 $attribs['legend'] = $legend; 0146 } 0147 0148 foreach (array_keys($attribs) as $attrib) { 0149 $testAttrib = strtolower($attrib); 0150 if (in_array($testAttrib, $this->stripAttribs)) { 0151 unset($attribs[$attrib]); 0152 } 0153 } 0154 0155 return $view->fieldset($name, $content, $attribs); 0156 } 0157 }