diff --git a/core/lib/Drupal/Core/Template/TwigExtension.php b/core/lib/Drupal/Core/Template/TwigExtension.php index de7aad9..c19f867 100644 --- a/core/lib/Drupal/Core/Template/TwigExtension.php +++ b/core/lib/Drupal/Core/Template/TwigExtension.php @@ -134,7 +134,7 @@ public function getFunctions() { new \Twig_SimpleFunction('attach_library', [$this, 'attachLibrary']), new \Twig_SimpleFunction('active_theme_path', [$this, 'getActiveThemePath']), new \Twig_SimpleFunction('active_theme', [$this, 'getActiveTheme']), - new \Twig_SimpleFunction('addAttributes', [$this, 'addAttributes']), + new \Twig_SimpleFunction('add_attribute', [$this, 'addAttribute']), ]; } @@ -265,7 +265,7 @@ public function getLink($text, $url, $attributes = []) { if (!$url instanceof Url) { $url = Url::fromUri($url); } - if ($attributes) { + if ($attributesAttribute) { if ($attributes instanceof Attribute) { $attributes = $attributes->toArray(); } @@ -596,19 +596,15 @@ public function safeJoin(\Twig_Environment $env, $value, $glue = '') { } /** - * Create an Attribute object from an array. + * Creates a \Drupal\Core\Template\Attribute object. * - * @param array $attributes - * Array (key, value) for attributes. + * @param array $attributes + * An associative array of key-value pairs to be converted to attributes. * - * @return Attribute + * @return \Drupal\Core\Template\Attribute * An Attribute object. */ - public function addAttributes($attributes = array()) { - if (!empty($attributes)) { - foreach ($attributes as $attribute){ - new Attribute($attribute); - } - } + public function addAttribute(array $attributes = []) { + return new Attribute($attributes); } }