diff -u b/core/lib/Drupal/Core/Template/Attribute.php b/core/lib/Drupal/Core/Template/Attribute.php --- b/core/lib/Drupal/Core/Template/Attribute.php +++ b/core/lib/Drupal/Core/Template/Attribute.php @@ -240,23 +240,17 @@ } /** - * Merges Attributes objects into another one. + * Merges the values of another Attributes object with this one. * - * @param Attributes[] - * An array of Attribute objects + * @param \Drupal\Core\Template\Attribute + * The other Attribute object. * - * @return $this; + * @return $this */ - public function merge() { - $args = func_get_args(); - if ($args) { - $merged_array = $this->toArray(); - foreach ($args as $arg) { - $merged_array = array_merge_recursive($merged_array, $arg->toArray()); - } - foreach ($merged_array as $attribute => $value) { - $this->setAttribute($attribute, $value); - } + public function merge(Attribute $attribute) { + $merged_array = array_merge_recursive($this->toArray(), $attribute->toArray()); + foreach ($merged_array as $attribute => $value) { + $this->setAttribute($attribute, $value); } return $this; diff -u b/core/tests/Drupal/Tests/Core/Template/AttributeTest.php b/core/tests/Drupal/Tests/Core/Template/AttributeTest.php --- b/core/tests/Drupal/Tests/Core/Template/AttributeTest.php +++ b/core/tests/Drupal/Tests/Core/Template/AttributeTest.php @@ -161,7 +161,6 @@ ]; $attribute2 = new Attribute($attributes2); - // Test merging another Attributes object $attribute = new Attribute(); $attribute->merge($attribute1); @@ -170,7 +169,8 @@ // Test merging two Attributes object $attribute = new Attribute(); - $attribute->merge($attribute1, $attribute2); + $attribute->merge($attribute1); + $attribute->merge($attribute2); $this->assertArrayEquals(['class1', 'class2', 'class3'], $attribute['class']->value()); $this->assertEquals('koala', $attribute['id']->value()); $this->assertEquals('pinguin', $attribute['name']->value()); only in patch2: unchanged: --- a/core/lib/Drupal/Core/Template/TwigSandboxPolicy.php +++ b/core/lib/Drupal/Core/Template/TwigSandboxPolicy.php @@ -57,6 +57,7 @@ public function __construct() { 'bundle', 'get', '__toString', + 'merge', ]); $this->whitelisted_methods = array_flip($whitelisted_methods);