Issue Type: Improvement Created: 2008-06-25T14:23:42.000+0000 Last Updated: 2008-09-02T10:39:16.000+0000 Status: Resolved Fix version(s): - 1.6.0 (02/Sep/08)
Reporter: David Rogers (al_the_x) Assignee: Matthew Weier O'Phinney (matthew) Tags: - Zend_Form
Related issues: - ZF-3572
Attachments: - Form.php
The "remove" method family (Zend_Form::removeElement(), Zend_Form_DisplayGroup::removeDecorator(), Zend_Form_Element::removeValidator(), etc) should not return a Boolean but an Object. Either these methods should return the Object they remove or the Object on which the method is called, which is fairly standard behavior for pushing and popping Stack Objects. In languages where garbage collection is an issue, the Stack returns the object popped, so that it can be explicitly destroyed. In a language such as PHP where garbage collection isn't as much of an issue, the Stack should return itself, to allow additional method chaining on itself.
In the case of Zend_Form, this latter approach would be invaluable, as a developer could then perform an action such as:
<pre class="highlight"> $Form = new Zend_Form; $Form->removeDecorator('FormElements')->addDecorator('Fieldset')->addDecorator('FormElements'); echo $Form;
Posted by Stephen Crosby (stevecrozz) on 2008-06-26T14:21:57.000+0000
Try Zend_Form::removeElement() after applying this patch. It returns the Zend_Form object, but throws an exception if you tried to remove an element that doesn't exist.
Posted by Stephen Crosby (stevecrozz) on 2008-06-26T14:24:41.000+0000
I meant to attach this diff rather than the whole class file.
Posted by David Rogers (al_the_x) on 2008-06-28T07:56:59.000+0000
That appears to do the job, although you may want to handle the Exception message differently, ie:
[code] throw new Zend_Form_Exception('Only form elements and groups may be overloaded; variable of type "' . $type . '" provided'); [code]
[code] throw new Zend_Form_Exception(sprintf('%s cannot remove nonexistent element: %s', getclass($this), $name)); [code]
This produces more portable code, IMO. Good job, though! Are we regular users permitted to submit patches? I know there's an official process for submitting new components and an agreement to sign, etc. Does the same process apply for patches?
Posted by Matthew Weier O'Phinney (matthew) on 2008-07-03T13:01:14.000+0000
Scheduling for next minor release
Posted by Matthew Weier O'Phinney (matthew) on 2008-07-03T13:04:33.000+0000
depends on refactoring for lazy loading (not entirely, but that's a good time to do it)
Posted by Matthew Weier O'Phinney (matthew) on 2008-07-03T13:11:23.000+0000
Fixed in r9919
Posted by Wil Sinclair (wil) on 2008-09-02T10:39:16.000+0000
Updating for the 1.6.0 release.
Have you found an issue?
See the Overview section for more details.