Loading core/lib/Drupal/Core/Template/Loader/StringLoader.php +13 −1 Original line number Diff line number Diff line Loading @@ -2,6 +2,10 @@ namespace Drupal\Core\Template\Loader; use Twig\Loader\ExistsLoaderInterface; use Twig\Loader\SourceContextLoaderInterface; use Twig\Source; /** * Loads string templates, also known as inline templates. * Loading @@ -20,7 +24,7 @@ * @see \Drupal\Core\Render\Element\InlineTemplate * @see twig_render_template() */ class StringLoader implements \Twig_LoaderInterface, \Twig_ExistsLoaderInterface { class StringLoader implements \Twig_LoaderInterface, ExistsLoaderInterface, SourceContextLoaderInterface { /** * {@inheritdoc} Loading Loading @@ -55,4 +59,12 @@ public function isFresh($name, $time) { return TRUE; } /** * {@inheritdoc} */ public function getSourceContext($name) { $name = (string) $name; return new Source($name, $name); } } core/lib/Drupal/Core/Template/TwigNodeTrans.php +14 −11 Original line number Diff line number Diff line Loading @@ -18,12 +18,17 @@ class TwigNodeTrans extends \Twig_Node { * {@inheritdoc} */ public function __construct(\Twig_Node $body, \Twig_Node $plural = NULL, \Twig_Node_Expression $count = NULL, \Twig_Node_Expression $options = NULL, $lineno, $tag = NULL) { parent::__construct([ 'count' => $count, 'body' => $body, 'plural' => $plural, 'options' => $options, ], [], $lineno, $tag); $nodes['body'] = $body; if ($count !== NULL) { $nodes['count'] = $count; } if ($plural !== NULL) { $nodes['plural'] = $plural; } if ($options !== NULL) { $nodes['options'] = $options; } parent::__construct($nodes, [], $lineno, $tag); } /** Loading @@ -32,12 +37,10 @@ public function __construct(\Twig_Node $body, \Twig_Node $plural = NULL, \Twig_N public function compile(\Twig_Compiler $compiler) { $compiler->addDebugInfo($this); $options = $this->getNode('options'); list($singular, $tokens) = $this->compileString($this->getNode('body')); $plural = NULL; if (NULL !== $this->getNode('plural')) { if ($this->hasNode('plural')) { list($plural, $pluralTokens) = $this->compileString($this->getNode('plural')); $tokens = array_merge($tokens, $pluralTokens); } Loading Loading @@ -67,8 +70,8 @@ public function compile(\Twig_Compiler $compiler) { $compiler->raw(')'); // Write any options passed. if (!empty($options)) { $compiler->raw(', ')->subcompile($options); if ($this->hasNode('options')) { $compiler->raw(', ')->subcompile($this->getNode('options')); } // Write function closure. Loading core/modules/system/tests/modules/twig_extension_test/src/TwigExtension/TestExtension.php +2 −2 Original line number Diff line number Diff line Loading @@ -21,7 +21,7 @@ class TestExtension extends \Twig_Extension { */ public function getFunctions() { return [ 'testfunc' => new \Twig_Function_Function(['Drupal\twig_extension_test\TwigExtension\TestExtension', 'testFunction']), new \Twig_SimpleFunction('testfunc', [$this, 'testFunction']), ]; } Loading @@ -39,7 +39,7 @@ public function getFunctions() { */ public function getFilters() { return [ 'testfilter' => new \Twig_Filter_Function(['Drupal\twig_extension_test\TwigExtension\TestExtension', 'testFilter']), new \Twig_SimpleFilter('testfilter', [$this, 'testFilter']), ]; } Loading core/modules/system/tests/modules/twig_extension_test/twig_extension_test.services.yml +0 −1 Original line number Diff line number Diff line services: twig_extension_test.twig.test_extension: arguments: ['@renderer'] class: Drupal\twig_extension_test\TwigExtension\TestExtension tags: - { name: twig.extension } core/modules/system/tests/src/Functional/Theme/TwigExtensionTest.php +3 −2 Original line number Diff line number Diff line Loading @@ -3,6 +3,7 @@ namespace Drupal\Tests\system\Functional\Theme; use Drupal\Tests\BrowserTestBase; use Drupal\twig_extension_test\TwigExtension\TestExtension; /** * Tests Twig extensions. Loading @@ -28,8 +29,8 @@ protected function setUp() { */ public function testTwigExtensionLoaded() { $twigService = \Drupal::service('twig'); $ext = $twigService->getExtension('twig_extension_test.test_extension'); $this->assertEqual(get_class($ext), 'Drupal\twig_extension_test\TwigExtension\TestExtension', 'TestExtension loaded successfully.'); $ext = $twigService->getExtension(TestExtension::class); $this->assertInstanceOf(TestExtension::class, $ext); } /** Loading Loading
core/lib/Drupal/Core/Template/Loader/StringLoader.php +13 −1 Original line number Diff line number Diff line Loading @@ -2,6 +2,10 @@ namespace Drupal\Core\Template\Loader; use Twig\Loader\ExistsLoaderInterface; use Twig\Loader\SourceContextLoaderInterface; use Twig\Source; /** * Loads string templates, also known as inline templates. * Loading @@ -20,7 +24,7 @@ * @see \Drupal\Core\Render\Element\InlineTemplate * @see twig_render_template() */ class StringLoader implements \Twig_LoaderInterface, \Twig_ExistsLoaderInterface { class StringLoader implements \Twig_LoaderInterface, ExistsLoaderInterface, SourceContextLoaderInterface { /** * {@inheritdoc} Loading Loading @@ -55,4 +59,12 @@ public function isFresh($name, $time) { return TRUE; } /** * {@inheritdoc} */ public function getSourceContext($name) { $name = (string) $name; return new Source($name, $name); } }
core/lib/Drupal/Core/Template/TwigNodeTrans.php +14 −11 Original line number Diff line number Diff line Loading @@ -18,12 +18,17 @@ class TwigNodeTrans extends \Twig_Node { * {@inheritdoc} */ public function __construct(\Twig_Node $body, \Twig_Node $plural = NULL, \Twig_Node_Expression $count = NULL, \Twig_Node_Expression $options = NULL, $lineno, $tag = NULL) { parent::__construct([ 'count' => $count, 'body' => $body, 'plural' => $plural, 'options' => $options, ], [], $lineno, $tag); $nodes['body'] = $body; if ($count !== NULL) { $nodes['count'] = $count; } if ($plural !== NULL) { $nodes['plural'] = $plural; } if ($options !== NULL) { $nodes['options'] = $options; } parent::__construct($nodes, [], $lineno, $tag); } /** Loading @@ -32,12 +37,10 @@ public function __construct(\Twig_Node $body, \Twig_Node $plural = NULL, \Twig_N public function compile(\Twig_Compiler $compiler) { $compiler->addDebugInfo($this); $options = $this->getNode('options'); list($singular, $tokens) = $this->compileString($this->getNode('body')); $plural = NULL; if (NULL !== $this->getNode('plural')) { if ($this->hasNode('plural')) { list($plural, $pluralTokens) = $this->compileString($this->getNode('plural')); $tokens = array_merge($tokens, $pluralTokens); } Loading Loading @@ -67,8 +70,8 @@ public function compile(\Twig_Compiler $compiler) { $compiler->raw(')'); // Write any options passed. if (!empty($options)) { $compiler->raw(', ')->subcompile($options); if ($this->hasNode('options')) { $compiler->raw(', ')->subcompile($this->getNode('options')); } // Write function closure. Loading
core/modules/system/tests/modules/twig_extension_test/src/TwigExtension/TestExtension.php +2 −2 Original line number Diff line number Diff line Loading @@ -21,7 +21,7 @@ class TestExtension extends \Twig_Extension { */ public function getFunctions() { return [ 'testfunc' => new \Twig_Function_Function(['Drupal\twig_extension_test\TwigExtension\TestExtension', 'testFunction']), new \Twig_SimpleFunction('testfunc', [$this, 'testFunction']), ]; } Loading @@ -39,7 +39,7 @@ public function getFunctions() { */ public function getFilters() { return [ 'testfilter' => new \Twig_Filter_Function(['Drupal\twig_extension_test\TwigExtension\TestExtension', 'testFilter']), new \Twig_SimpleFilter('testfilter', [$this, 'testFilter']), ]; } Loading
core/modules/system/tests/modules/twig_extension_test/twig_extension_test.services.yml +0 −1 Original line number Diff line number Diff line services: twig_extension_test.twig.test_extension: arguments: ['@renderer'] class: Drupal\twig_extension_test\TwigExtension\TestExtension tags: - { name: twig.extension }
core/modules/system/tests/src/Functional/Theme/TwigExtensionTest.php +3 −2 Original line number Diff line number Diff line Loading @@ -3,6 +3,7 @@ namespace Drupal\Tests\system\Functional\Theme; use Drupal\Tests\BrowserTestBase; use Drupal\twig_extension_test\TwigExtension\TestExtension; /** * Tests Twig extensions. Loading @@ -28,8 +29,8 @@ protected function setUp() { */ public function testTwigExtensionLoaded() { $twigService = \Drupal::service('twig'); $ext = $twigService->getExtension('twig_extension_test.test_extension'); $this->assertEqual(get_class($ext), 'Drupal\twig_extension_test\TwigExtension\TestExtension', 'TestExtension loaded successfully.'); $ext = $twigService->getExtension(TestExtension::class); $this->assertInstanceOf(TestExtension::class, $ext); } /** Loading