diff --git a/core/lib/Drupal/Core/Template/TwigExtension.php b/core/lib/Drupal/Core/Template/TwigExtension.php index f11fe67..4937b5a 100644 --- a/core/lib/Drupal/Core/Template/TwigExtension.php +++ b/core/lib/Drupal/Core/Template/TwigExtension.php @@ -142,7 +142,7 @@ public function getFilters() { // Implements safe joining. // @todo Make that the default for |join? Upstream issue: // https://github.com/fabpot/Twig/issues/1420 - new \Twig_SimpleFilter('safe_join', array($this, 'safeJoin'), array('needs_environment' => true, 'is_safe' => array('html'))), + new \Twig_SimpleFilter('safe_join', [$this, 'safeJoin'], ['needs_environment' => true, 'is_safe' => ['html']]), // Array filters. new \Twig_SimpleFilter('without', 'twig_without'), @@ -530,14 +530,10 @@ public function renderVar($arg) { * The imploded string. */ public function safeJoin(\Twig_Environment $env, $value, $glue = '') { - $separator = ''; - $output = ''; - foreach ($value as $item) { + return implode($glue, array_map(function($item) use ($env) { // If $item is not marked safe then it will be escaped. - $output .= $separator . $this->escapeFilter($env, $item, 'html', NULL, TRUE); - $separator = $glue; - } - return $output; + return $this->escapeFilter($env, $item, 'html', NULL, TRUE); + }, $value)); } }