diff --git a/core/lib/Drupal/Core/Template/Attribute.php b/core/lib/Drupal/Core/Template/Attribute.php index 3ce6900..1951d57 100644 --- a/core/lib/Drupal/Core/Template/Attribute.php +++ b/core/lib/Drupal/Core/Template/Attribute.php @@ -251,15 +251,18 @@ public function hasClass($class) { * Implements the magic __toString() method. */ public function __toString() { - $return = array(); + $return = ''; /** @var \Drupal\Core\Template\AttributeValueBase $value */ foreach ($this->storage as $name => $value) { - $return[] = $value->render(); + $rendered = $value->render(); + if ($rendered) { + $return .= ' ' . $rendered; + } } // The implementations of AttributeValueBase::render() call // htmlspecialchars() on the attribute name and value so we are confident // that the return value can be set as safe. - return SafeMarkup::set(implode(' ', $return)); + return SafeMarkup::set($return); } /**