diff --git a/core/lib/Drupal/Core/Template/Attribute.php b/core/lib/Drupal/Core/Template/Attribute.php index 3ea18b1..ae671d0 100644 --- a/core/lib/Drupal/Core/Template/Attribute.php +++ b/core/lib/Drupal/Core/Template/Attribute.php @@ -251,14 +251,18 @@ public function hasClass($class) { * Implements the magic __toString() method. */ public function __toString() { - $return = ''; + $keys = ''; + $values = []; + $rendered = FALSE; foreach ($this->storage as $name => $value) { $rendered = $value->render(); if ($rendered) { - $return .= ' ' . $rendered; + $keys .= ' @' . $name; + $values['@' . $name] = $rendered; } } - return SafeMarkup::set($return); + + return $keys ? SafeMarkup::format($keys, $values) : ''; } /** diff --git a/core/lib/Drupal/Core/Template/AttributeArray.php b/core/lib/Drupal/Core/Template/AttributeArray.php index 4cdd932..d7465e8 100644 --- a/core/lib/Drupal/Core/Template/AttributeArray.php +++ b/core/lib/Drupal/Core/Template/AttributeArray.php @@ -7,8 +7,6 @@ namespace Drupal\Core\Template; -use Drupal\Component\Utility\SafeMarkup; - /** * A class that defines a type of Attribute that can be added to as an array. * @@ -76,7 +74,7 @@ public function offsetExists($offset) { public function __toString() { // Filter out any empty values before printing. $this->value = array_unique(array_filter($this->value)); - return SafeMarkup::checkPlain(implode(' ', $this->value)); + return implode(' ', $this->value); } /** diff --git a/core/lib/Drupal/Core/Template/AttributeBoolean.php b/core/lib/Drupal/Core/Template/AttributeBoolean.php index a2e5c02..2fc4bac 100644 --- a/core/lib/Drupal/Core/Template/AttributeBoolean.php +++ b/core/lib/Drupal/Core/Template/AttributeBoolean.php @@ -7,8 +7,6 @@ namespace Drupal\Core\Template; -use Drupal\Component\Utility\SafeMarkup; - /** * A class that defines a type of boolean HTML attribute. * @@ -42,7 +40,7 @@ public function render() { * Implements the magic __toString() method. */ public function __toString() { - return $this->value === FALSE ? '' : SafeMarkup::checkPlain($this->name); + return $this->value === FALSE ? '' : $this->name; } } diff --git a/core/lib/Drupal/Core/Template/AttributeString.php b/core/lib/Drupal/Core/Template/AttributeString.php index 51b1448..1cc5d6c 100644 --- a/core/lib/Drupal/Core/Template/AttributeString.php +++ b/core/lib/Drupal/Core/Template/AttributeString.php @@ -30,7 +30,7 @@ class AttributeString extends AttributeValueBase { * Implements the magic __toString() method. */ public function __toString() { - return SafeMarkup::checkPlain($this->value); + return (string) $this->value; } } diff --git a/core/lib/Drupal/Core/Template/AttributeValueBase.php b/core/lib/Drupal/Core/Template/AttributeValueBase.php index 4db6dd8..b1f0898 100644 --- a/core/lib/Drupal/Core/Template/AttributeValueBase.php +++ b/core/lib/Drupal/Core/Template/AttributeValueBase.php @@ -57,7 +57,7 @@ public function __construct($name, $value) { public function render() { $value = (string) $this; if (isset($this->value) && static::RENDER_EMPTY_ATTRIBUTE || !empty($value)) { - return SafeMarkup::checkPlain($this->name) . '="' . $value . '"'; + return SafeMarkup::format('@name="@value"', ['@name' => $this->name, '@value' => $value]); } }