Hi,
I just spent hours with searching why my decorator doesn't get called. I
use the Zend_Form stuff separately for testing purposes and wrote an own
decorator for some elements.
In my form class I use the following lines of code to register and use
my decorator:
$this->addElementPrefixPath(
'',
$this->_decoratorPath,
'decorator'
);
$this->setElementDecorators(array(
'ViewHelper',
array('Description', array('tag' => 'div')),
'TableRowDecorator',
));
The debugger reveals the following:
When the elements get rendered Zend_Form_Element runs the
_loadDecorator() method to lazy load those decorators.
Because I decided not to use a prefix in my decorator class the
following lines in _loadDecorator() just unset it:
// If the class has no prefix here starts the pain...
$newName = get_class($instance);
$decoratorNames = array_keys($this->_decorators);
$order = array_flip($decoratorNames);
$order[$newName] = $order[$name];
$decoratorsExchange = array();
// ...this one is bad!
unset($order[$name]);
asort($order);
After those lines 'ViewHelper' becomes to
'Zend_Form_Decorator_ViewHelper'. 'Description' becomes to
'Zend_Form_Decorator_Description'. And 'TableRowDecorator' gets unset.
By renaming TableRowDecorator to XXX_TableRowDecorator and specifying
$this->addElementPrefixPath(
'XXX_',
$this->_decoratorPath,
'decorator'
);
...all is fine.
Now my question: Is this an outstandig case of misuse and
misunderstanding or just a bug?
A compromise maybe could be that addElementPrefixPath() just throws an
exception or something if an empty prefix is given.
Regards,
Hauke Stange
--
List: [email protected]
Info: http://framework.zend.com/archives
Unsubscribe: [email protected]