function TwigExtension::bubbleArgMetadata

Same name in other branches
  1. 9 core/lib/Drupal/Core/Template/TwigExtension.php \Drupal\Core\Template\TwigExtension::bubbleArgMetadata()
  2. 8.9.x core/lib/Drupal/Core/Template/TwigExtension.php \Drupal\Core\Template\TwigExtension::bubbleArgMetadata()
  3. 10 core/lib/Drupal/Core/Template/TwigExtension.php \Drupal\Core\Template\TwigExtension::bubbleArgMetadata()

Bubbles Twig template argument's cacheability & attachment metadata.

For example: a generated link or generated URL object is passed as a Twig template argument, and its bubbleable metadata must be bubbled.

Parameters

mixed $arg: A Twig template argument that is about to be printed.

See also

\Drupal\Core\GeneratedLink

\Drupal\Core\GeneratedUrl

\Drupal\Core\Theme\ThemeManager::render()

\Drupal\Core\Render\RendererInterface::render()

2 calls to TwigExtension::bubbleArgMetadata()
TwigExtension::escapeFilter in core/lib/Drupal/Core/Template/TwigExtension.php
Overrides twig_escape_filter().
TwigExtension::renderVar in core/lib/Drupal/Core/Template/TwigExtension.php
Wrapper around render() for twig printed output.

File

core/lib/Drupal/Core/Template/TwigExtension.php, line 494

Class

TwigExtension
A class providing Drupal Twig extensions.

Namespace

Drupal\Core\Template

Code

protected function bubbleArgMetadata($arg) {
    // If it's a renderable, then it'll be up to the generated render array it
    // returns to contain the necessary cacheability & attachment metadata. If
    // it doesn't implement CacheableDependencyInterface or AttachmentsInterface
    // then there is nothing to do here.
    if ($arg instanceof RenderableInterface || !($arg instanceof CacheableDependencyInterface || $arg instanceof AttachmentsInterface)) {
        return;
    }
    $arg_bubbleable = [];
    BubbleableMetadata::createFromObject($arg)->applyTo($arg_bubbleable);
    $this->renderer
        ->render($arg_bubbleable);
}

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