class RenderContext in Zircon Profile 8
Same name and namespace in other branches
- 8.0 core/lib/Drupal/Core/Render/RenderContext.php \Drupal\Core\Render\RenderContext
The render context: a stack containing bubbleable rendering metadata.
A stack of \Drupal\Core\Render\BubbleableMetadata objects.
@internal
Hierarchy
- class \Drupal\Core\Render\RenderContext extends \Drupal\Core\Render\SplStack
Expanded class hierarchy of RenderContext
See also
\Drupal\Core\Render\RendererInterface
\Drupal\Core\Render\BubbleableMetadata
25 files declare their use of RenderContext
- AssertContentTrait.php in core/
modules/ simpletest/ src/ AssertContentTrait.php - Contains \Drupal\simpletest\AssertContentTrait.
- CacheTest.php in core/
modules/ views/ src/ Tests/ Plugin/ CacheTest.php - Contains \Drupal\views\Tests\Plugin\CacheTest.
- CommentFieldNameTest.php in core/
modules/ comment/ src/ Tests/ Views/ CommentFieldNameTest.php - Contains \Drupal\comment\Tests\Views\CommentFieldNameTest.
- EarlyRenderingControllerWrapperSubscriber.php in core/
lib/ Drupal/ Core/ EventSubscriber/ EarlyRenderingControllerWrapperSubscriber.php - Contains \Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber.
- ExtensionViewsFieldTest.php in core/
modules/ file/ src/ Tests/ Views/ ExtensionViewsFieldTest.php - Contains \Drupal\file\Tests\Views\ExtensionViewsFieldTest.
File
- core/
lib/ Drupal/ Core/ Render/ RenderContext.php, line 20 - Contains \Drupal\Core\Render\RenderContext.
Namespace
Drupal\Core\RenderView source
class RenderContext extends \SplStack {
/**
* Updates the current frame of the stack.
*
* @param array &$element
* The element of the render array that has just been rendered. The stack
* frame for this element will be updated with the bubbleable rendering
* metadata of this element.
*/
public function update(&$element) {
// The latest frame represents the bubbleable metadata for the subtree.
$frame = $this
->pop();
// Update the frame, but also update the current element, to ensure it
// contains up-to-date information in case it gets render cached.
$updated_frame = BubbleableMetadata::createFromRenderArray($element)
->merge($frame);
$updated_frame
->applyTo($element);
$this
->push($updated_frame);
}
/**
* Bubbles the stack.
*
* Whenever another level in the render array has been rendered, the stack
* must be bubbled, to merge its rendering metadata with that of the parent
* element.
*/
public function bubble() {
// If there's only one frame on the stack, then this is the root call, and
// we can't bubble up further. ::renderRoot() will reset the stack, but we
// must not reset it here to allow users of ::executeInRenderContext() to
// access the stack directly.
if ($this
->count() === 1) {
return;
}
// Merge the current and the parent stack frame.
$current = $this
->pop();
$parent = $this
->pop();
$this
->push($current
->merge($parent));
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
RenderContext:: |
public | function | Bubbles the stack. | |
RenderContext:: |
public | function | Updates the current frame of the stack. |