Hello,
Sorry if this will become double-post, but I have some problems with
mailing list but seems like now I fixed-up everything :))
I've met strange (at least for me) behavior when using ViewHelper
decorator. When ViewHelper grabs result of helper execution, it
passes $element->options as fourth argument on 246'th line of
Zend/Form/Decorator/ViewHeper.php:
$elementContent = $view->$helper($name, $value, $attribs, $element->options);
Of course I thought you may set this options value upon addElement()
call, like this:
$form->addElemen('myElement', 'my_name', array(
'label' => 'My Label',
'options' => array(
'argument' => 'for my view helper'
)
));
And was surprised when found why it had no effect and that this 'options'
never appear anywhere. The answer was on 341'st line of Zend/Form/Element.php
(inside of setOptions() method):
unset($options['options']);
So that was why even 'attribs' had no such key. So var_dump'ing of _getInfo()
produced something like this:
array
'name' => string 'my_name' (length=7)
'id' => string 'My Label' (length=8)
'value' => null
'attribs' =>
array
empty
'options' => null
'listsep' => null
'disable' => boolean false
'escape' => boolean true
Solution was to set 'options' property directly on element:
$form->getElement('my_name')->options = array(
'argument' => 'for my view helper'
);
So after this var_dump of _getInfo() will produce something similar to:
array
'name' => string 'my_name' (length=7)
'id' => string 'My Label' (length=8)
'value' => null
'attribs' =>
array
empty
'options' =>
array
'argument' => string 'for my view helper' (length=18)
'listsep' => null
'disable' => boolean false
'escape' => boolean true
And now I'm wondering is it was specially done so? Or it's some
kind of defect? I guess Zend/Form/Element.php's 342'nd line should be
replaced with:
if (array_key_exists('options', $options)) {
$this->options = $options['options'];
unset($options);
}
--
Sincerely yours,
Aleksey V. Zapparov A.K.A. ixti
FSF Member #7118
Mobile Phone: +34 617 179 344
Homepage: http://www.ixti.ru
*Origin: Happy Hacking!