Skip to content
Snippets Groups Projects
Commit eadc5375 authored by catch's avatar catch
Browse files

Issue #3011393 by Spokje, scott_euser, TylerMarshall, markcarver, lauriii:...

Issue #3011393 by Spokje, scott_euser, TylerMarshall, markcarver, lauriii: Remove twig_without() and manual inclusion of twig.engine TwigEnvironment
parent 6251b3ed
No related branches found
No related tags found
No related merge requests found
......@@ -64,11 +64,6 @@ class TwigEnvironment extends Environment {
public function __construct($root, CacheBackendInterface $cache, $twig_extension_hash, StateInterface $state, LoaderInterface $loader = NULL, array $options = []) {
$this->state = $state;
// Ensure that twig.engine is loaded, given that it is needed to render a
// template because functions like TwigExtension::escapeFilter() are called.
// @todo remove in Drupal 9.0.0 https://www.drupal.org/node/3011393.
require_once $root . '/core/themes/engines/twig/twig.engine';
$this->templateClasses = [];
$options += [
......
......@@ -2,7 +2,6 @@
namespace Drupal\Tests\system\Kernel\Theme;
use Drupal\Core\Extension\Extension;
use Drupal\KernelTests\KernelTestBase;
/**
......@@ -121,39 +120,4 @@ public function testTwigWithoutFilter() {
}
}
/**
* Test "twig_without" filter function.
*
* @expectedDeprecation twig_without() is deprecated in Drupal 8.7.x and will be removed before Drupal 9.0.0. Use \Drupal\Core\Template\TwigExtension::withoutFilter(). See https://www.drupal.org/node/3011154.
* @group legacy
*/
public function testLegacyTwigWithoutFunction() {
// Load the twig engine to ensure twig_without() exists.
$twig_engine = new Extension($this->root, 'theme_engine', 'core/themes/engines/twig/twig.info.yml', 'twig.engine');
$twig_engine->load();
$filter_test = [
'red' => '#F00',
'green' => '#0F0',
'blue' => '#00F',
];
// Filter out red key.
$result_without_red = twig_without($filter_test, 'red');
$expected_without_red = $filter_test;
unset($expected_without_red['red']);
$this->assertSame($expected_without_red, $result_without_red);
// Filter nothing and check the array is unaltered.
$result_unaltered = twig_without($filter_test);
$this->assertSame($filter_test, $result_unaltered);
// Filter out blue and green.
$result_without_blue_green = twig_without($filter_test, 'blue', 'green');
$expected_without_blue_green = $filter_test;
unset($expected_without_blue_green['blue']);
unset($expected_without_blue_green['green']);
$this->assertSame($expected_without_blue_green, $result_without_blue_green);
}
}
......@@ -114,6 +114,8 @@ protected function setUp() {
* Tests white-listing of methods doesn't interfere with chaining.
*/
public function testWhiteListChaining() {
/** @var \Drupal\Core\Template\TwigEnvironment $environment */
$environment = \Drupal::service('twig');
$node = Node::create([
'type' => 'page',
'title' => 'Some node mmk',
......@@ -121,7 +123,9 @@ public function testWhiteListChaining() {
'field_term' => $this->term->id(),
]);
$node->save();
$this->setRawContent(twig_render_template(drupal_get_path('theme', 'test_theme') . '/templates/node.html.twig', ['node' => $node]));
$template = $environment->loadTemplate(drupal_get_path('theme', 'test_theme') . '/templates/node.html.twig');
$markup = $template->render(['node' => $node]);
$this->setRawContent($markup);
$this->assertText('Sometimes people are just jerks');
}
......
......@@ -118,30 +118,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[] ...
* The string keys of $element to prevent printing.
*
* @return array
* The filtered renderable array.
*
* @deprecated in Drupal 8.7.x and will be removed before 9.0.0. Use
* \Drupal\Core\Template\TwigExtension::withoutFilter() instead.
*/
function twig_without($element) {
@trigger_error('twig_without() is deprecated in Drupal 8.7.x and will be removed before Drupal 9.0.0. Use \Drupal\Core\Template\TwigExtension::withoutFilter(). See https://www.drupal.org/node/3011154.', E_USER_DEPRECATED);
/** @var \Drupal\Core\Template\TwigExtension $extension */
$extension = \Drupal::service('twig.extension');
return call_user_func_array([$extension, 'withoutFilter'], func_get_args());
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment