Verified Commit f38c94f9 authored by Dave Long's avatar Dave Long
Browse files

Issue #3477373 by finnsky, bbrala, longwave: Fix "Not passing an instance of...

Issue #3477373 by finnsky, bbrala, longwave: Fix "Not passing an instance of "TwigFunction" when creating a function of type "FunctionExpression" is deprecated."

(cherry picked from commit 4b762453)
parent 8b7350e2
Loading
Loading
Loading
Loading
Loading
+0 −4
Original line number Diff line number Diff line
@@ -64,8 +64,4 @@
%The "Drupal\\Tests\\Core\\Utility\\MockContainerAware" class implements "Symfony\\Component\\DependencyInjection\\ContainerAwareInterface" that is deprecated since Symfony 6.4, use dependency injection instead.%

# Twig 3.
%Since twig/twig 3.12: Not passing an instance of "TwigFunction" when creating a "attach_library" function of type "Twig\\Node\\Expression\\FunctionExpression" is deprecated.%
%Since twig/twig 3.12: Not passing an instance of "TwigFunction" when creating a "add_component_context" function of type "Twig\\Node\\Expression\\FunctionExpression" is deprecated.%
%Since twig/twig 3.12: Not passing an instance of "TwigFunction" when creating a "render_var" function of type "Twig\\Node\\Expression\\FunctionExpression" is deprecated.%
%Since twig/twig 3.12: Not passing an instance of "TwigFunction" when creating a "validate_component_props" function of type "Twig\\Node\\Expression\\FunctionExpression" is deprecated.%
%Since twig/twig 3.12: Twig Filter "spaceless" is deprecated%
+4 −3
Original line number Diff line number Diff line
@@ -9,6 +9,7 @@
use Drupal\Core\Render\Component\Exception\InvalidComponentException;
use Drupal\Core\Theme\ComponentPluginManager;
use Twig\Environment;
use Twig\TwigFunction;
use Twig\Node\Expression\ConstantExpression;
use Twig\Node\Expression\FunctionExpression;
use Twig\Node\ModuleNode;
@@ -55,17 +56,17 @@ public function leaveNode(Node $node, Environment $env): ?Node {
      $print_nodes[] = new PrintNode(new ConstantExpression(sprintf('<!-- %s Component start: %s -->', $emoji, $component_id), $line), $line);
    }
    $print_nodes[] = new PrintNode(new FunctionExpression(
      'attach_library',
      new TwigFunction('attach_library', [$env->getExtension(TwigExtension::class), 'attachLibrary']),
      new Node([new ConstantExpression($component->getLibraryName(), $line)]),
      $line
    ), $line);
    $print_nodes[] = new PrintNode(new FunctionExpression(
      'add_component_context',
      new TwigFunction('add_component_context', [$env->getExtension(ComponentsTwigExtension::class), 'addAdditionalContext'], ['needs_context' => TRUE]),
      new Node([new ConstantExpression($component_id, $line)]),
      $line
    ), $line);
    $print_nodes[] = new PrintNode(new FunctionExpression(
      'validate_component_props',
      new TwigFunction('validate_component_props', [$env->getExtension(ComponentsTwigExtension::class), 'validateProps'], ['needs_context' => TRUE]),
      new Node([new ConstantExpression($component_id, $line)]),
      $line
    ), $line);
+6 −1
Original line number Diff line number Diff line
@@ -3,6 +3,7 @@
namespace Drupal\Core\Template;

use Twig\Environment;
use Twig\TwigFunction;
use Twig\Node\Expression\FilterExpression;
use Twig\Node\Expression\FunctionExpression;
use Twig\Node\Node;
@@ -47,7 +48,11 @@ public function leaveNode(Node $node, Environment $env): ?Node {
      $class = get_class($node);
      $line = $node->getTemplateLine();
      return new $class(
        new FunctionExpression('render_var', new Node([$node->getNode('expr')]), $line),
        new FunctionExpression(
          new TwigFunction('render_var', [$env->getExtension(TwigExtension::class), 'renderVar']),
          new Node([$node->getNode('expr')]),
          $line
        ),
        $line
      );
    }