Permalink
Browse files

Having $element->__toString() in buildCommonFields() made that method…

… not-quite-usable by renderer plugins

Additionally provide 'class' attribute for groups, as in Default renderer

git-svn-id: http://svn.php.net/repository/pear/packages/HTML_QuickForm2/trunk@325667 c90b9560-bf6c-de11-be94-00142212c4b1
  • Loading branch information...
sad-spirit committed May 13, 2012
1 parent 6758fdf commit e444c7e17e14696c29d1035192e7ffc8813d7a61
Showing with 21 additions and 10 deletions.
  1. +21 −10 HTML/QuickForm2/Renderer/Array.php
@@ -233,15 +233,24 @@ public function buildCommonFields(HTML_QuickForm2_Node $element)
if (isset($this->styles[$ary['id']])) {
$ary['style'] = $this->styles[$ary['id']];
}
- if (!$element instanceof HTML_QuickForm2_Container) {
- $ary['html'] = $element->__toString();
- } else {
- $ary['elements'] = array();
- $ary['attributes'] = $element->getAttributes(true);
- }
return $ary;
}
+ /**
+ * Creates an array with fields that are common to all Containers
+ *
+ * @param HTML_QuickForm2_Node $container Container being rendered
+ *
+ * @return array
+ */
+ public function buildCommonContainerFields(HTML_QuickForm2_Node $container)
+ {
+ return $this->buildCommonFields($container) + array(
+ 'elements' => array(),
+ 'attributes' => $container->getAttributes(true)
+ );
+ }
+
/**
* Stores an array representing "scalar" element in the form array
*
@@ -307,6 +316,7 @@ public function setStyleForId($idOrStyles, $style = null)
public function renderElement(HTML_QuickForm2_Node $element)
{
$ary = $this->buildCommonFields($element) + array(
+ 'html' => $element->__toString(),
'value' => $element->getValue(),
'type' => $element->getType(),
'required' => $element->isRequired(),
@@ -327,7 +337,7 @@ public function startForm(HTML_QuickForm2_Node $form)
{
$this->reset();
- $this->array = $this->buildCommonFields($form);
+ $this->array = $this->buildCommonContainerFields($form);
if ($this->options['group_errors']) {
$this->array['errors'] = array();
}
@@ -348,7 +358,7 @@ public function finishForm(HTML_QuickForm2_Node $form)
public function startContainer(HTML_QuickForm2_Node $container)
{
- $ary = $this->buildCommonFields($container) + array(
+ $ary = $this->buildCommonContainerFields($container) + array(
'required' => $container->isRequired(),
'type' => $container->getType()
);
@@ -362,9 +372,10 @@ public function finishContainer(HTML_QuickForm2_Node $container)
public function startGroup(HTML_QuickForm2_Node $group)
{
- $ary = $this->buildCommonFields($group) + array(
+ $ary = $this->buildCommonContainerFields($group) + array(
'required' => $group->isRequired(),
- 'type' => $group->getType()
+ 'type' => $group->getType(),
+ 'class' => $group->getAttribute('class')
);
if ($separator = $group->getSeparator()) {
$ary['separator'] = array();

0 comments on commit e444c7e

Please sign in to comment.