From 67223663f19529dc49142ab8011bea3817534337 Mon Sep 17 00:00:00 2001 From: Victor Berchet Date: Tue, 3 Jul 2012 19:59:54 +0200 Subject: [PATCH] [Form] Add theming support for collection --- src/Symfony/Bridge/Twig/Extension/FormExtension.php | 5 ++--- .../Bundle/FrameworkBundle/Templating/Helper/FormHelper.php | 5 ++--- .../Component/Form/Extension/Core/Type/CollectionType.php | 1 + src/Symfony/Component/Form/Extension/Core/Type/FormType.php | 6 ++++++ 4 files changed, 11 insertions(+), 6 deletions(-) diff --git a/src/Symfony/Bridge/Twig/Extension/FormExtension.php b/src/Symfony/Bridge/Twig/Extension/FormExtension.php index d21fe056ca75e..5dd27aade9738 100644 --- a/src/Symfony/Bridge/Twig/Extension/FormExtension.php +++ b/src/Symfony/Bridge/Twig/Extension/FormExtension.php @@ -235,8 +235,7 @@ protected function render(FormView $view, $section, array $variables = array()) } } - $custom = '_'.$view->getVar('id'); - $rendering = $custom.$section; + $rendering = $view->getVar('id').$section; $blocks = $this->getBlocks($view); if (isset($this->varStack[$rendering])) { @@ -245,7 +244,7 @@ protected function render(FormView $view, $section, array $variables = array()) $this->varStack[$rendering]['variables'] = array_replace_recursive($this->varStack[$rendering]['variables'], $variables); } else { $types = $view->getVar('types'); - $types[] = $custom; + $types[] = '_'.$view->getVar('theme_id'); $typeIndex = count($types) - 1; $this->varStack[$rendering] = array( 'variables' => array_replace_recursive($view->getVars(), $variables), diff --git a/src/Symfony/Bundle/FrameworkBundle/Templating/Helper/FormHelper.php b/src/Symfony/Bundle/FrameworkBundle/Templating/Helper/FormHelper.php index fd8c3deeab23f..3c974508b4c64 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Templating/Helper/FormHelper.php +++ b/src/Symfony/Bundle/FrameworkBundle/Templating/Helper/FormHelper.php @@ -237,8 +237,7 @@ protected function renderSection(FormView $view, $section, array $variables = ar $template = null; - $custom = '_'.$view->getVar('id'); - $rendering = $custom.$section; + $rendering = $view->getVar('id').$section; if (isset($this->varStack[$rendering])) { $typeIndex = $this->varStack[$rendering]['typeIndex'] - 1; @@ -246,7 +245,7 @@ protected function renderSection(FormView $view, $section, array $variables = ar $variables = array_replace_recursive($this->varStack[$rendering]['variables'], $variables); } else { $types = $view->getVar('types'); - $types[] = $custom; + $types[] = '_'.$view->getVar('theme_id'); $typeIndex = count($types) - 1; $variables = array_replace_recursive($view->getVars(), $variables); $this->varStack[$rendering]['types'] = $types; diff --git a/src/Symfony/Component/Form/Extension/Core/Type/CollectionType.php b/src/Symfony/Component/Form/Extension/Core/Type/CollectionType.php index 6b0d1ec1ee845..42db21adc6ead 100644 --- a/src/Symfony/Component/Form/Extension/Core/Type/CollectionType.php +++ b/src/Symfony/Component/Form/Extension/Core/Type/CollectionType.php @@ -51,6 +51,7 @@ public function buildView(FormViewInterface $view, FormInterface $form, array $o $view->addVars(array( 'allow_add' => $options['allow_add'], 'allow_delete' => $options['allow_delete'], + 'collection' => true, )); if ($form->getConfig()->hasAttribute('prototype')) { diff --git a/src/Symfony/Component/Form/Extension/Core/Type/FormType.php b/src/Symfony/Component/Form/Extension/Core/Type/FormType.php index 14d2203e982c6..0541c853590c4 100644 --- a/src/Symfony/Component/Form/Extension/Core/Type/FormType.php +++ b/src/Symfony/Component/Form/Extension/Core/Type/FormType.php @@ -137,6 +137,12 @@ public function finishView(FormViewInterface $view, FormInterface $form, array $ } $view->setVar('multipart', $multipart); + + $parent = $view->getParent(); + $themeId = null !== $parent && $parent->getVar('collection', false) + ? $parent->getVar('id').'_children' + : $view->getVar('id'); + $view->setVar('theme_id', $themeId); } /**