ZF-10149: "view" option assigned too late on instantiating Zend_Form
Description
Passing an alternative view object meeting Zend_View_Interface via the options array in Zend_Form constructor fails with:
ViewHelper decorator cannot render without a registered view object at /home/lib/ZendFramework-1.10.6/library/Zend/Form/Decorator/ViewHelper.php (226).
Seems that setView is happening too late in setOptions().
Solution I found was to insert this code at the top of setOptions():
public function setOptions(array $options)
{
if (isset($options['view'])) {
$this->setView($options['view']);
unset($options['view']);
}
-
-
-
}
Comments
Posted by Richard Tuin (richardtuin) on 2010-11-19T13:26:22.000+0000
Can you please provide some additional information on how to reproduce this issue?
Posted by Mark Maynereid (mim) on 2010-11-19T19:25:07.000+0000
Posted by Richard Tuin (richardtuin) on 2010-11-20T03:26:51.000+0000
The setOptions method in Zend_Form does not enable the user to pass a view object in the array. In fact, it explicitly ignores the view object.
Zend_Form::setView needs to be called explicitly to use the custom implementation of Zend_View_Interface.
Posted by Mark Maynereid (mim) on 2010-11-20T04:12:03.000+0000
I missed the $forbidden array. My mistake. Apols.
Posted by Richard Tuin (richardtuin) on 2010-11-20T04:13:13.000+0000
Although originally this issue references to expected behavior, allowing the user to add a view object using the options array is a good suggestion.
I have made a patch for it, and included the associated unit tests.
Posted by Mark Maynereid (mim) on 2010-11-20T04:17:44.000+0000
Appreciated, thanks.
Posted by Richard Tuin (richardtuin) on 2010-11-20T05:01:37.000+0000
Suggestion from FreeaqMob on irc was to improve the unit test to test on type safety.
Updated the unit test and uploaded the new patch.