Skip to content

Commit

Permalink
[Form] Fixed passing of variables in the FormRenderer
Browse files Browse the repository at this point in the history
  • Loading branch information
webmozart committed Jul 16, 2012
1 parent 629093e commit d11f8b5
Showing 1 changed file with 29 additions and 3 deletions.
32 changes: 29 additions & 3 deletions src/Symfony/Component/Form/FormRenderer.php
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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.
Expand Down

0 comments on commit d11f8b5

Please sign in to comment.