Skip to content

Commit

Permalink
[Form][TwigBundle] Making sure all field types are rendered with the …
Browse files Browse the repository at this point in the history
…proper template
  • Loading branch information
Seldaek authored and fabpot committed Nov 15, 2010
1 parent f21c58c commit d45954a
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 6 deletions.
15 changes: 9 additions & 6 deletions src/Symfony/Bundle/TwigBundle/Extension/FormExtension.php
Expand Up @@ -6,6 +6,7 @@
use Symfony\Component\Form\FieldGroupInterface;
use Symfony\Component\Form\FieldInterface;
use Symfony\Component\Form\CollectionField;
use Symfony\Component\Form\HybridField;
use Symfony\Bundle\TwigBundle\TokenParser\FormThemeTokenParser;
use Symfony\Bundle\FrameworkBundle\Templating\HtmlGeneratorInterface;

Expand Down Expand Up @@ -96,16 +97,18 @@ public function render(FieldInterface $field, array $attributes = array())
$this->templates = $this->resolveResources($this->resources);
}

if ($field instanceof FieldGroupInterface) {
return $this->templates['group']->getBlock('group', array(
'group' => $field,
if ($field instanceof CollectionField) {
return $this->templates['group']->getBlock('collection', array(
'collection' => $field,
'attributes' => $attributes,
));
}

if ($field instanceof CollectionField) {
return $this->templates['group']->getBlock('collection', array(
'collection' => $field,
// FieldGroupInterface instances that need to be rendered as
// a field instead of group should return false in isGroup()
if ($field instanceof FieldGroupInterface && true === $field->isGroup()) {
return $this->templates['group']->getBlock('group', array(
'group' => $field,
'attributes' => $attributes,
));
}
Expand Down
5 changes: 5 additions & 0 deletions src/Symfony/Component/Form/FieldGroup.php
Expand Up @@ -447,6 +447,11 @@ public function isMultipart()
return false;
}

public function isGroup()
{
return true;
}

/**
* Returns true if the bound field exists (implements the \ArrayAccess interface).
*
Expand Down
5 changes: 5 additions & 0 deletions src/Symfony/Component/Form/FieldGroupInterface.php
Expand Up @@ -18,4 +18,9 @@
*/
interface FieldGroupInterface extends FieldInterface, \ArrayAccess, \Traversable, \Countable
{
/**
* Returns whether the Field instance really is a group
* @return bool
*/
public function isGroup();
}

0 comments on commit d45954a

Please sign in to comment.