From d11f8b5e9e49b10bf1c688426fbd9b32692877cc Mon Sep 17 00:00:00 2001 From: Bernhard Schussek Date: Mon, 16 Jul 2012 16:44:31 +0200 Subject: [PATCH] [Form] Fixed passing of variables in the FormRenderer --- src/Symfony/Component/Form/FormRenderer.php | 32 +++++++++++++++++++-- 1 file changed, 29 insertions(+), 3 deletions(-) diff --git a/src/Symfony/Component/Form/FormRenderer.php b/src/Symfony/Component/Form/FormRenderer.php index 05c77d3aff64..ca85ff477f70 100644 --- a/src/Symfony/Component/Form/FormRenderer.php +++ b/src/Symfony/Component/Form/FormRenderer.php @@ -155,7 +155,19 @@ public function renderBlock($block, array $variables = array()) throw new FormException(sprintf('No block "%s" found while rendering the form.', $block)); } - $variables = array_replace_recursive($scopeVariables, $variables); + // Merge the passed with the existing attributes + if (isset($variables['attr']) && isset($scopeVariables['attr'])) { + $variables['attr'] = array_replace($scopeVariables['attr'], $variables['attr']); + } + + // Merge the passed with the exist *label* attributes + if (isset($variables['label_attr']) && isset($scopeVariables['label_attr'])) { + $variables['label_attr'] = array_replace($scopeVariables['label_attr'], $variables['label_attr']); + } + + // Do not use array_replace_recursive(), otherwise array variables + // cannot be overwritten + $variables = array_replace($scopeVariables, $variables); return $this->engine->renderBlock($view, $resource, $block, $variables); } @@ -253,7 +265,7 @@ protected function renderSection(FormViewInterface $view, $section, array $varia // The default variable scope contains all view variables, merged with // the variables passed explicitely to the helper - $variables = array_replace_recursive($view->getVars(), $variables); + $scopeVariables = $view->getVars(); } else { // RECURSIVE CALL // If a block recursively calls renderSection() again, resume rendering @@ -262,7 +274,7 @@ protected function renderSection(FormViewInterface $view, $section, array $varia $hierarchyLevel = $this->hierarchyLevelMap[$mapKey] - 1; // Reuse the current scope and merge it with the explicitely passed variables - $variables = array_replace_recursive($this->variableMap[$mapKey], $variables); + $scopeVariables = $this->variableMap[$mapKey]; } // Load the resource where this block can be found @@ -285,6 +297,20 @@ protected function renderSection(FormViewInterface $view, $section, array $varia )); } + // Merge the passed with the existing attributes + if (isset($variables['attr']) && isset($scopeVariables['attr'])) { + $variables['attr'] = array_replace($scopeVariables['attr'], $variables['attr']); + } + + // Merge the passed with the exist *label* attributes + if (isset($variables['label_attr']) && isset($scopeVariables['label_attr'])) { + $variables['label_attr'] = array_replace($scopeVariables['label_attr'], $variables['label_attr']); + } + + // Do not use array_replace_recursive(), otherwise array variables + // cannot be overwritten + $variables = array_replace($scopeVariables, $variables); + // In order to make recursive calls possible, we need to store the block hierarchy, // the current level of the hierarchy and the variables so that this method can // resume rendering one level higher of the hierarchy when it is called recursively.