This is an interesting idea, but I have no plans to implement it in the 1.x branch. In 2.0, you will have the option of defining your own decorator chains as classes -- which means that you should be able to specify the name of a decorator chain class when defining an element, and it will use that. This allows you to define the chain once, and use it simply many times.
-- darkangel <[email protected]> wrote (on Monday, 15 February 2010, 11:01 AM -0800): > > For the second option above, the Zend_Form::_defaultElementDecorators > variable should be an associative array of element names to decorators, for > example: > > array( > 'Element' => array(// decorators), // Special case, applies to elements > without default decorators. > 'Text' => array(// decorators), > 'Date' => array(// decorators) > ) > > setDefaultElementDecorators(array $decorators, $elementType = null) > > This is what I'm using: > > <?php > > class App_Form_BaseForm extends Zend_Form > { > protected $_defaultElementDecorators = array( > 'Element' => array( > 'ViewHelper', > 'Label', > array('Errors', array('placement' => 'prepend')), > array(array('row' => 'HtmlTag'), array('tag' => 'div')) > ), > 'Hash' => array('ViewHelper'), > 'Submit' => array( > 'ViewHelper', array('HtmlTag', array('tag' => 'div', 'class' => > 'form-buttons')) > ) > ); > > public function loadDefaultDecorators() > { > if ($this->loadDefaultDecoratorsIsDisabled()) { > return; > } > > $decorators = $this->getDecorators(); > if (empty($decorators)) { > $this->addDecorators(array( > 'FormElements', > array('Description', array('placement' => 'prepend')), > 'Form' > )); > } > } > > public function createElement($type, $name, $options = null) > { > if (!isset($options['decorators'])) { > if (isset($this->_defaultElementDecorators[$type])) { > $options['decorators'] = > $this->_defaultElementDecorators[$type]; > } else { > $options['decorators'] = > $this->_defaultElementDecorators['Element']; > } > } > > $element = parent::createElement($type, $name, $options); > > return $element; > } > } > -- > View this message in context: > http://n4.nabble.com/How-to-set-the-default-decorators-for-form-elements-tp1290314p1556488.html > Sent from the Zend Framework mailing list archive at Nabble.com. > -- Matthew Weier O'Phinney Project Lead | [email protected] Zend Framework | http://framework.zend.com/ PGP key: http://framework.zend.com/zf-matthew-pgp-key.asc
