Skip to content

Commit d11f8b5

Browse files
committed
[Form] Fixed passing of variables in the FormRenderer
1 parent 629093e commit d11f8b5

File tree

1 file changed

+29
-3
lines changed

1 file changed

+29
-3
lines changed

src/Symfony/Component/Form/FormRenderer.php

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,19 @@ public function renderBlock($block, array $variables = array())
155155
throw new FormException(sprintf('No block "%s" found while rendering the form.', $block));
156156
}
157157

158-
$variables = array_replace_recursive($scopeVariables, $variables);
158+
// Merge the passed with the existing attributes
159+
if (isset($variables['attr']) && isset($scopeVariables['attr'])) {
160+
$variables['attr'] = array_replace($scopeVariables['attr'], $variables['attr']);
161+
}
162+
163+
// Merge the passed with the exist *label* attributes
164+
if (isset($variables['label_attr']) && isset($scopeVariables['label_attr'])) {
165+
$variables['label_attr'] = array_replace($scopeVariables['label_attr'], $variables['label_attr']);
166+
}
167+
168+
// Do not use array_replace_recursive(), otherwise array variables
169+
// cannot be overwritten
170+
$variables = array_replace($scopeVariables, $variables);
159171

160172
return $this->engine->renderBlock($view, $resource, $block, $variables);
161173
}
@@ -253,7 +265,7 @@ protected function renderSection(FormViewInterface $view, $section, array $varia
253265

254266
// The default variable scope contains all view variables, merged with
255267
// the variables passed explicitely to the helper
256-
$variables = array_replace_recursive($view->getVars(), $variables);
268+
$scopeVariables = $view->getVars();
257269
} else {
258270
// RECURSIVE CALL
259271
// If a block recursively calls renderSection() again, resume rendering
@@ -262,7 +274,7 @@ protected function renderSection(FormViewInterface $view, $section, array $varia
262274
$hierarchyLevel = $this->hierarchyLevelMap[$mapKey] - 1;
263275

264276
// Reuse the current scope and merge it with the explicitely passed variables
265-
$variables = array_replace_recursive($this->variableMap[$mapKey], $variables);
277+
$scopeVariables = $this->variableMap[$mapKey];
266278
}
267279

268280
// Load the resource where this block can be found
@@ -285,6 +297,20 @@ protected function renderSection(FormViewInterface $view, $section, array $varia
285297
));
286298
}
287299

300+
// Merge the passed with the existing attributes
301+
if (isset($variables['attr']) && isset($scopeVariables['attr'])) {
302+
$variables['attr'] = array_replace($scopeVariables['attr'], $variables['attr']);
303+
}
304+
305+
// Merge the passed with the exist *label* attributes
306+
if (isset($variables['label_attr']) && isset($scopeVariables['label_attr'])) {
307+
$variables['label_attr'] = array_replace($scopeVariables['label_attr'], $variables['label_attr']);
308+
}
309+
310+
// Do not use array_replace_recursive(), otherwise array variables
311+
// cannot be overwritten
312+
$variables = array_replace($scopeVariables, $variables);
313+
288314
// In order to make recursive calls possible, we need to store the block hierarchy,
289315
// the current level of the hierarchy and the variables so that this method can
290316
// resume rendering one level higher of the hierarchy when it is called recursively.

0 commit comments

Comments
 (0)