function Renderer::doReplacePlaceholder

Same name in other branches
  1. 10 core/lib/Drupal/Core/Render/Renderer.php \Drupal\Core\Render\Renderer::doReplacePlaceholder()

Replaces a placeholder with its markup.

Parameters

string $placeholder: The placeholder HTML.

\Drupal\Component\Render\MarkupInterface|string $markup: The markup to replace the placeholder with.

array $elements: The render array that the placeholder is from.

array $placeholder_element: The placeholder element render array.

Return value

\Drupal\Component\Render\MarkupInterface|string The rendered HTML.

2 calls to Renderer::doReplacePlaceholder()
Renderer::renderPlaceholder in core/lib/Drupal/Core/Render/Renderer.php
Renders final HTML for a placeholder.
Renderer::replacePlaceholders in core/lib/Drupal/Core/Render/Renderer.php
Replaces placeholders.

File

core/lib/Drupal/Core/Render/Renderer.php, line 165

Class

Renderer
Turns a render array into an HTML string.

Namespace

Drupal\Core\Render

Code

protected function doReplacePlaceholder(string $placeholder, string|MarkupInterface $markup, array $elements, array $placeholder_element) : array {
    // 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_element);
    // Remove the placeholder that we've just rendered.
    unset($elements['#attached']['placeholders'][$placeholder]);
    return $elements;
}

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