Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. CallExpression.php

function CallExpression::compileArguments

1 call to CallExpression::compileArguments()
CallExpression::compileCallable in vendor/twig/twig/src/Node/Expression/CallExpression.php

File

vendor/twig/twig/src/Node/Expression/CallExpression.php, line 67

Class

CallExpression

Namespace

Twig\Node\Expression

Code

protected function compileArguments(Compiler $compiler, $isArray = false) : void {
    if (\func_num_args() >= 2) {
        trigger_deprecation('twig/twig', '3.11', 'Passing a second argument to "%s()" is deprecated.', __METHOD__);
    }
    $compiler->raw($isArray ? '[' : '(');
    $first = true;
    $twigCallable = $this->getAttribute('twig_callable');
    if ($twigCallable->needsCharset()) {
        $compiler->raw('$this->env->getCharset()');
        $first = false;
    }
    if ($twigCallable->needsEnvironment()) {
        if (!$first) {
            $compiler->raw(', ');
        }
        $compiler->raw('$this->env');
        $first = false;
    }
    if ($twigCallable->needsContext()) {
        if (!$first) {
            $compiler->raw(', ');
        }
        $compiler->raw('$context');
        $first = false;
    }
    foreach ($twigCallable->getArguments() as $argument) {
        if (!$first) {
            $compiler->raw(', ');
        }
        $compiler->string($argument);
        $first = false;
    }
    if ($this->hasNode('node')) {
        if (!$first) {
            $compiler->raw(', ');
        }
        $compiler->subcompile($this->getNode('node'));
        $first = false;
    }
    if ($this->hasNode('arguments')) {
        $arguments = (new CallableArgumentsExtractor($this, $this->getTwigCallable()))
            ->extractArguments($this->getNode('arguments'));
        foreach ($arguments as $node) {
            if (!$first) {
                $compiler->raw(', ');
            }
            $compiler->subcompile($node);
            $first = false;
        }
    }
    $compiler->raw($isArray ? ']' : ')');
}
RSS feed
Powered by Drupal