class TwigNodeCheckDeprecations

Same name in other branches
  1. 10 core/lib/Drupal/Core/Template/TwigNodeCheckDeprecations.php \Drupal\Core\Template\TwigNodeCheckDeprecations

A node that checks deprecated variable usage.

Hierarchy

Expanded class hierarchy of TwigNodeCheckDeprecations

See also

\Drupal\Core\Template\TwigNodeVisitorCheckDeprecations

\Drupal\Core\Template\TwigExtension::checkDeprecations()

File

core/lib/Drupal/Core/Template/TwigNodeCheckDeprecations.php, line 16

Namespace

Drupal\Core\Template
View source
class TwigNodeCheckDeprecations extends Node {
    
    /**
     * The named variables used in the template.
     */
    protected array $usedNames = [];
    
    /**
     * {@inheritdoc}
     */
    public function __construct(array $usedNames) {
        $this->usedNames = $usedNames;
        parent::__construct();
    }
    
    /**
     * {@inheritdoc}
     */
    public function compile(Compiler $compiler) {
        $usedNamesNode = new ArrayExpression([], $this->getTemplateLine());
        foreach ($this->usedNames as $name) {
            $usedNamesNode->addElement(new ConstantExpression($name, $this->getTemplateLine()));
        }
        $compiler->write("\$this->env->getExtension('\\Drupal\\Core\\Template\\TwigExtension')\n");
        $compiler->indent();
        $compiler->write("->checkDeprecations(\$context, ");
        $compiler->subcompile($usedNamesNode);
        $compiler->raw(");");
        $compiler->outdent();
    }

}

Members

Title Sort descending Modifiers Object type Summary
TwigNodeCheckDeprecations::$usedNames protected property The named variables used in the template.
TwigNodeCheckDeprecations::compile public function
TwigNodeCheckDeprecations::__construct public function

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.