(Long post ahead!) IMHO, it should work like this:
-- If it's OK for the element to have knowledge of the form that contains it: -- When the element is rendered (or added to the form, or whatever), if it has no decorators, it will load the default decorators set on its form ($this->getForm()->getDefaultElementDecorators(). (you'd use setDefaultElementDecorators() in your Zend_Form subclass or elsewhere). This doesn't help in cases where you just want to make a small change to the defaults, such as disabling label escaping for a particular element, as the default decorators will not be loaded at this time. Question: Does the form render the elements within it? -- If it's not OK -- You should be able to call setDefaultElementDecorators() as above, and then create elements using $form->createElement() -- at the moment this does not load the default decorators (see http://framework.zend.com/issues/browse/ZF-8942). Also, Zend_Form::_elementDecorators should not be used, since it just represents what was last set using setElementDecorators(), i.e. a Zend_Form::_defaultElementDecorators variable should be added and used (Zend_Form::_elementDecorators could probably be removed). This is the better option of the two (IMHO). The order of element decorator use should be (using Zend_Form::createElement()): (1) Explicitly set decorators on the element, (2) Default decorators set on the form (setDefaultElementDecorators()) (3) Default decorators set in Element::loadDefaultDecorators() (if the above is not set). Using direct construction (new Zend_Form_Element_Text()): (1) Explicitly set decorators on the element, (2) Default decorators set in Element::loadDefaultDecorators(). -- Other thoughts -- Another option may be to use static methods: Zend_Form_Element::setDefaultDecorators(a); Zend_Form_Element_Date::setDefaultDecorators(b); Untested, but Zend_Form_Element_Date::loadDefaultDecorators() could be something like: public function loadDefaultDecorators() { if ($this->loadDefaultDecoratorsIsDisabled()) { return; } $decorators = $this->getDecorators(); if (empty($decorators)) { // If Zend_Form_Element_Date::setDefaultDecorators() has been called, use those decorators. if (!empty(self::_defaultDecorators)) { // Load self::_defaultDecorators return; } // If Zend_Form_Element::setDefaultDecorators() has been called, use those decorators. if (!empty(static::_defaultDecorators)) { // I think this is late static binding and would require PHP 5.3. // Load static::_defaultDecorators return; } // Load the date element's default decorators. } } -- View this message in context: http://n4.nabble.com/How-to-set-the-default-decorators-for-form-elements-tp1290314p1311681.html Sent from the Zend Framework mailing list archive at Nabble.com.
