@@ -155,7 +155,19 @@ public function renderBlock($block, array $variables = array())
155
155
throw new FormException (sprintf ('No block "%s" found while rendering the form. ' , $ block ));
156
156
}
157
157
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 );
159
171
160
172
return $ this ->engine ->renderBlock ($ view , $ resource , $ block , $ variables );
161
173
}
@@ -253,7 +265,7 @@ protected function renderSection(FormViewInterface $view, $section, array $varia
253
265
254
266
// The default variable scope contains all view variables, merged with
255
267
// the variables passed explicitely to the helper
256
- $ variables = array_replace_recursive ( $ view ->getVars (), $ variables );
268
+ $ scopeVariables = $ view ->getVars ();
257
269
} else {
258
270
// RECURSIVE CALL
259
271
// If a block recursively calls renderSection() again, resume rendering
@@ -262,7 +274,7 @@ protected function renderSection(FormViewInterface $view, $section, array $varia
262
274
$ hierarchyLevel = $ this ->hierarchyLevelMap [$ mapKey ] - 1 ;
263
275
264
276
// 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 ];
266
278
}
267
279
268
280
// Load the resource where this block can be found
@@ -285,6 +297,20 @@ protected function renderSection(FormViewInterface $view, $section, array $varia
285
297
));
286
298
}
287
299
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
+
288
314
// In order to make recursive calls possible, we need to store the block hierarchy,
289
315
// the current level of the hierarchy and the variables so that this method can
290
316
// resume rendering one level higher of the hierarchy when it is called recursively.
0 commit comments