diff --git a/core/lib/Drupal/Core/Template/TwigEnvironment.php b/core/lib/Drupal/Core/Template/TwigEnvironment.php index eb4f8e5..fc0c994 100644 --- a/core/lib/Drupal/Core/Template/TwigEnvironment.php +++ b/core/lib/Drupal/Core/Template/TwigEnvironment.php @@ -27,6 +27,8 @@ class TwigEnvironment extends \Twig_Environment { */ protected $templateClasses; + protected $templateClassPrefix = '__TwigTemplate_'; + /** * Constructs a TwigEnvironment object and stores cache and storage * internally. @@ -43,10 +45,6 @@ class TwigEnvironment extends \Twig_Environment { * The options for the Twig environment. */ public function __construct($root, CacheBackendInterface $cache, $twig_extension_hash, \Twig_LoaderInterface $loader = NULL, $options = array()) { - // Ensure that twig.engine is loaded, given that it is needed to render a - // template because functions like TwigExtension::escapeFilter() are called. - require_once $root . '/core/themes/engines/twig/twig.engine'; - $this->templateClasses = array(); $options += array( diff --git a/core/lib/Drupal/Core/Template/TwigExtension.php b/core/lib/Drupal/Core/Template/TwigExtension.php index 9d6dd1a..2d00ee5 100644 --- a/core/lib/Drupal/Core/Template/TwigExtension.php +++ b/core/lib/Drupal/Core/Template/TwigExtension.php @@ -166,7 +166,7 @@ public function getFilters() { new \Twig_SimpleFilter('safe_join', [$this, 'safeJoin'], ['needs_environment' => true, 'is_safe' => ['html']]), // Array filters. - new \Twig_SimpleFilter('without', 'twig_without'), + new \Twig_SimpleFilter('without', [$this, 'withoutFilter']), // CSS class and ID filters. new \Twig_SimpleFilter('clean_class', '\Drupal\Component\Utility\Html::getClass'), @@ -551,4 +551,37 @@ public function safeJoin(\Twig_Environment $env, $value, $glue = '') { }, $value)); } + /** + * Removes child elements from a copy of the original array. + * + * Creates a copy of the renderable array and removes child elements by key + * specified through filter's arguments. The copy can be printed without these + * elements. The original renderable array is still available and can be used + * to print child elements in their entirety in the twig template. + * + * @param array|object $element + * The parent renderable array to exclude the child items. + * @param string[] $args, ... + * The string keys of $element to prevent printing. + * + * @return array + * The filtered renderable array. + */ + public function withoutFilter($element) { + if ($element instanceof \ArrayAccess) { + $filtered_element = clone $element; + } + else { + $filtered_element = $element; + } + $args = func_get_args(); + unset($args[0]); + foreach ($args as $arg) { + if (isset($filtered_element[$arg])) { + unset($filtered_element[$arg]); + } + } + return $filtered_element; + } + } diff --git a/core/themes/engines/twig/twig.engine b/core/themes/engines/twig/twig.engine index 30ec511..e937f95 100644 --- a/core/themes/engines/twig/twig.engine +++ b/core/themes/engines/twig/twig.engine @@ -117,36 +117,3 @@ function twig_render_template($template_file, array $variables) { // This output has already been rendered and is therefore considered safe. return Markup::create(implode('', $output)); } - -/** - * Removes child elements from a copy of the original array. - * - * Creates a copy of the renderable array and removes child elements by key - * specified through filter's arguments. The copy can be printed without these - * elements. The original renderable array is still available and can be used - * to print child elements in their entirety in the twig template. - * - * @param array|object $element - * The parent renderable array to exclude the child items. - * @param string[] $args, ... - * The string keys of $element to prevent printing. - * - * @return array - * The filtered renderable array. - */ -function twig_without($element) { - if ($element instanceof ArrayAccess) { - $filtered_element = clone $element; - } - else { - $filtered_element = $element; - } - $args = func_get_args(); - unset($args[0]); - foreach ($args as $arg) { - if (isset($filtered_element[$arg])) { - unset($filtered_element[$arg]); - } - } - return $filtered_element; -}