diff --git a/core/lib/Drupal/Core/Template/TwigExtension.php b/core/lib/Drupal/Core/Template/TwigExtension.php index 5f225d3..99c573a 100644 --- a/core/lib/Drupal/Core/Template/TwigExtension.php +++ b/core/lib/Drupal/Core/Template/TwigExtension.php @@ -402,6 +402,10 @@ public function escapePlaceholder($env, $string) { * @return string|null * The escaped, rendered output, or NULL if there is no valid output. * + * @throws \Exception + * When $arg is passed as an object which does not implement __toString(), + * RenderableInterface or toString(). + * * @todo Refactor this to keep it in sync with theme_render_and_autoescape() * in https://www.drupal.org/node/2575065 */ @@ -433,7 +437,7 @@ public function escapeFilter(\Twig_Environment $env, $arg, $strategy = 'html', $ elseif (method_exists($arg, '__toString')) { $return = (string) $arg; } - // You can't throw exceptions in the magic PHP __toString methods, see + // You can't throw exceptions in the magic PHP __toString() methods, see // http://php.net/manual/en/language.oop5.magic.php#object.tostring so // we also support a toString method. elseif (method_exists($arg, 'toString')) { @@ -471,10 +475,11 @@ public function escapeFilter(\Twig_Environment $env, $arg, $strategy = 'html', $ /** * Wrapper around render() for twig printed output. * - * If an object is passed that has no __toString method an exception is thrown; - * other objects are casted to string. However in the case that the object is an - * instance of a Twig_Markup object it is returned directly to support auto - * escaping. + * When $arg is passed as an object which does not implement __toString(), + * RenderableInterface or toString(). Other objects are casted to string. + * If it already implements __toString(), it will throw an exception. + * However in the case that the object is an instance of a Twig_Markup object + * it is returned directly to support auto escaping. * * If an array is passed it is rendered via render() and scalar values are * returned directly. @@ -485,6 +490,10 @@ public function escapeFilter(\Twig_Environment $env, $arg, $strategy = 'html', $ * @return mixed * The rendered output or an Twig_Markup object. * + * @throws \Exception + * When $arg is passed as an object which does not implement __toString(), + * RenderableInterface or toString(). + * * @see render * @see TwigNodeVisitor */ @@ -511,7 +520,7 @@ public function renderVar($arg) { elseif (method_exists($arg, '__toString')) { return (string) $arg; } - // You can't throw exceptions in the magic PHP __toString methods, see + // You can't throw exceptions in the magic PHP __toString() methods, see // http://php.net/manual/en/language.oop5.magic.php#object.tostring so // we also support a toString method. elseif (method_exists($arg, 'toString')) {