diff --git a/core/lib/Drupal/Core/Template/TwigExtension.php b/core/lib/Drupal/Core/Template/TwigExtension.php index ed9ed3d..e9eca7a 100644 --- a/core/lib/Drupal/Core/Template/TwigExtension.php +++ b/core/lib/Drupal/Core/Template/TwigExtension.php @@ -54,11 +54,11 @@ class TwigExtension extends \Twig_Extension { protected $dateFormatter; /** - * An empty attributes object that can be cloned. + * An empty Attribute object that can be cloned. * * @var \Drupal\Core\Template\Attribute */ - protected $attributes; + protected $attribute; /** * Constructs \Drupal\Core\Template\TwigExtension. @@ -618,15 +618,16 @@ public function safeJoin(\Twig_Environment $env, $value, $glue = '') { * An attributes object that has the given attributes. */ public function createAttribute(array $attributes = []) { - if (empty($attributes)) { - if (!$this->attributes) { - $this->attributes = new Attribute(); - } + if (!isset($this->attribute)) { + $this->attribute = new Attribute(); + } + $cloned_attributes = clone $this->attribute; - return clone $this->attributes; + foreach ($attributes as $name => $value) { + $cloned_attributes->offsetSet($name, $value); } - return new Attribute($attributes); + return $cloned_attributes; } }