diff --git a/core/lib/Drupal/Core/Template/Attribute.php b/core/lib/Drupal/Core/Template/Attribute.php index cd1c9f0..6a54e8e 100644 --- a/core/lib/Drupal/Core/Template/Attribute.php +++ b/core/lib/Drupal/Core/Template/Attribute.php @@ -76,6 +76,9 @@ public function offsetSet($name, $value) { * @param mixed $value * The attribute value. * + * @throws \Exception + * If invalid object was passed as a value. + * * @return \Drupal\Core\Template\AttributeValueBase * An AttributeValueBase representation of the attribute's value. */ @@ -100,7 +103,7 @@ protected function createAttributeValue($name, $value) { $value = new AttributeString($name, $value); } // Provide a better exception message when invalid object is passed as value. - elseif (is_object($value)) { + elseif (is_object($value) && !method_exists($value, '__toString')) { throw new \Exception('"' . $name . '" attribute value of type "' . get_class($value) . '" can not be converted to string'); }