Issue Type: Improvement Created: 2009-05-27T22:51:01.000+0000 Last Updated: 2009-05-28T03:59:23.000+0000 Status: Resolved Fix version(s): Reporter: Joshua Hogendorn (devians) Assignee: Matthew Weier O'Phinney (matthew) Tags: - Zend_Form
Related issues: Attachments:
Sometimes its particularly useful to be able to change options of individual decorators out of an elements decorator stack without having to re-set the entire thing manually (ie when using a preset list of elements and customising minor aspects for the current output). At the moment the closest thing to this would be to use removeDecorator and then addDecorator with the new options list. (which only works for the item on the end of the stack, not the most useful since the order of the stack is important in this case)
something like $element -> setDecoratorOption($decoratoridentifier, $option) and $element -> removeDecoratorOption($decoratoridentifier, $option)
of course the tricky bit i can see here is that decorators dont really get names, at best they're identifiable by their type and the order of that type in the stack. (ie if the stack was viewhelper,htmltag,label,htmltag to ident the htmltags would be htmltag:0, htmltag:1 etc. not ideal since you cant always guarantee the order of the stack if something else is setting it.)
Posted by Tomoaki Kosugi (noopable) on 2009-05-27T23:59:04.000+0000
Try addDecorator without removeDecorator. Options could be changed by addDecorator without breaking the order. If you like,you can change options of decorator it has explicitly-defined name.
Posted by Joshua Hogendorn (devians) on 2009-05-28T00:45:03.000+0000
hrm, add decorator seems to work pretty admirably at this task (many thanks). its a little clunky though since you have to redo all the options that were a part of that decorator previously, rather than change just the one you want to change. so i think the improvement request still stands?
decorators also seem to have issues when you want to attach a single decorator to the element multiple times since it uses the assoc array to build the stack. is there a design reason for this?
Posted by Matthew Weier O'Phinney (matthew) on 2009-05-28T03:59:05.000+0000
There's a much easier way to do this; simply retrieve the decorator from the element and call the appropriate methods:
<pre class="highlight"> $decorator = $element->getDecorator('foo'); $decorator->setOption('bar', 'baz'); $decorator->removeOption('baz');
As for using the same decorator multiple times, you can't. You can have multiple instances of the same decorator, and the way to do this is via aliases; the methodology is described in the manual. The reason behind this is that the decorators are stateful, and can use different options.
Have you found an issue?
See the Overview section for more details.