QuickForm 3.0 news: renderers
| From: | Alexey Borzov | Date: | Thu, 13 Mar 2003 14:27:38 +0000 |
| Subject: | QuickForm 3.0 news: renderers | ||
| Groups: | php.pear.dev | ||
| Request: | Send a blank email to pear-dev+get-14244@lists.php.net to get a copy of this message | ||
Greetings!
As those of you who used QuickForm probably know, form outputting logic was
previously implemented as methods of HTML_QuickForm class. This led to two
problems:
1) Bloat of the said class (80+ methods!)
2) Difficulties in adding new output logic (i.e. through templates)
For the upcoming 3.0 release a new "Renderer" system was implemented. The form
output code is contained in classes from HTML_QuickForm_Renderer hierarchy,
whose behaviour is based on Visitor design pattern from the classic "Design
Patterns" book. Their usage looks like this:
$renderer = new HTML_QuickForm_Renderer_Concrete();
$renderer->doSomeCustomizingIfNecessary($foo, $bar);
$form->accept($renderer);
$renderer->getSomeResult();
There are 3 renderers currently available:
1) HTML_QuickForm_Renderer_Default --- based on old toHtml() code;
2) HTML_QuickForm_Renderer_Array --- based on old toArray() code;
3) HTML_QuickForm_Renderer_ITX --- uses HTML_Template_ITX template system.
The first two renderers are implicitly called from current toHtml() and
toArray() methods. The third renderer is new, example of its usage with a
sample template file is available in CVS.
How does this affect users? Well, all this was kept backwards compatible.
Template customising methods of HTML_QuickForm call default renderer's
methods, usage of HTML_QuickForm's methods is deprecated.
toArray() works through a new renderer as well, although its behaviour changed
a bit: it does not return html for group elements, but rather an array of
group elements' array representations. BTW, I need feedback from toArray()
users: is this BC break OK with them or should I add a BC switch?
How does this affect developers? If you add a new element to QuickForm, that
is a container (like 'group') or has some special rendering needs (like
'hidden') then you have to add an abstract renderMyElement() to
HTML_QuickForm_Renderer, and implement the logic in all of its subclasses. If
you want to add a new renderer, you just have to implement all the methods of
HTML_QuickForm_Renderer in it.
Well, I'm writing this in hope that it (and the questions that you ask) will
serve as a basis of future renderer documentation. :]