mergeBubbleableMetadata example

    $placeholder_elements = $elements['#attached']['placeholders'][$placeholder];

    // Prevent the render array from being auto-placeholdered again.     $placeholder_elements['#create_placeholder'] = FALSE;

    // Render the placeholder into markup.     $markup = $this->renderPlain($placeholder_elements);

    // Replace the placeholder with its rendered markup, and merge its     // bubbleable metadata with the main elements'.     $elements['#markup'] = Markup::create(str_replace($placeholder$markup$elements['#markup']));
    $elements = $this->mergeBubbleableMetadata($elements$placeholder_elements);

    // Remove the placeholder that we've just rendered.     unset($elements['#attached']['placeholders'][$placeholder]);

    return $elements;
  }

  /** * {@inheritdoc} */
  public function render(&$elements$is_root_call = FALSE) {
    
throw new \LogicException('Only #attached and #cache may be set in hook_page_attachments().');
    }

    // Modules and themes can alter page attachments.     $this->moduleHandler->alter('page_attachments', $attachments);
    $this->themeManager->alter('page_attachments', $attachments);
    if (array_diff(array_keys($attachments)['#attached', '#cache']) !== []) {
      throw new \LogicException('Only #attached and #cache may be set in hook_page_attachments_alter().');
    }

    // Merge the attachments onto the $page render array.     $page = $this->renderer->mergeBubbleableMetadata($page$attachments);
  }

  /** * Invokes the page top and bottom hooks. * * @param array &$html * A #type 'html' render array, for which the page top and bottom hooks will * be invoked, and to which the 'page_top' and 'page_bottom' children (also * render arrays) will be added (if non-empty). * * @throws \LogicException * * @internal * * @see hook_page_top() * @see hook_page_bottom() * @see html.html.twig */
$build = [
      '#theme' => $this->themeFunctions(),
      '#view' => $this->view,
      '#field' => $this,
      '#row' => $values,
    ];
    $output = $renderer->render($build);

    // Set the bubbleable rendering metadata on $view->element. This ensures the     // bubbleable rendering metadata of individual rendered fields is not lost.     // @see \Drupal\Core\Render\Renderer::updateStack()     $this->view->element = $renderer->mergeBubbleableMetadata($this->view->element, $build);

    return $output;
  }

  public function themeFunctions() {
    $themes = [];
    $hook = 'views_view_field';

    $display = $this->view->display_handler->display;

    if (!empty($display)) {
      
Home | Imprint | This part of the site doesn't use cookies.