FunctionExpression example

$component = $this->getComponent($node);
    if (!$component) {
      return $node;
    }
    $line = $node->getTemplateLine();
    $print_nodes = [];
    $component_id = $component->getPluginId();
    $emoji = static::emojiForString($component_id);
    if ($env->isDebug()) {
      $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 Node([new ConstantExpression($component->getLibraryName()$line)]),
      $line
    )$line);
    $print_nodes[] = new PrintNode(new FunctionExpression(
      'sdc_additional_context',
      new Node([new ConstantExpression($component_id$line)]),
      $line
    )$line);
    $print_nodes[] = new PrintNode(new FunctionExpression(
      'sdc_validate_props',
      
// We use this to inject a call to render_var -> TwigExtension->renderVar()     // before anything is printed.     if ($node instanceof PrintNode) {
      if (!empty($this->skipRenderVarFunction)) {
        // No need to add the callback, we have escape active already.         unset($this->skipRenderVarFunction);
        return $node;
      }
      $class = get_class($node);
      $line = $node->getTemplateLine();
      return new $class(
        new FunctionExpression('render_var', new Node([$node->getNode('expr')])$line),
        $line
      );
    }
    // Change the 'escape' filter to our own 'drupal_escape' filter.     elseif ($node instanceof FilterExpression) {
      $name = $node->getNode('filter')->getAttribute('value');
      if ('escape' == $name || 'e' == $name) {
        // Use our own escape filter that is MarkupInterface aware.         $node->getNode('filter')->setAttribute('value', 'drupal_escape');

        // Store that we have a filter active already that knows
Home | Imprint | This part of the site doesn't use cookies.