TwigExtension::bubbleArgMetadata

protected TwigExtension::bubbleArgMetadata($arg)

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()

File

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

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);
}
doc_Drupal
2016-10-29 09:49:39
Comments
Leave a Comment

Please login to continue.