Mercurial > hg > isophonics-drupal-site
comparison core/lib/Drupal/Core/Render/RenderContext.php @ 0:4c8ae668cc8c
Initial import (non-working)
author | Chris Cannam |
---|---|
date | Wed, 29 Nov 2017 16:09:58 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:4c8ae668cc8c |
---|---|
1 <?php | |
2 | |
3 namespace Drupal\Core\Render; | |
4 | |
5 /** | |
6 * The render context: a stack containing bubbleable rendering metadata. | |
7 * | |
8 * A stack of \Drupal\Core\Render\BubbleableMetadata objects. | |
9 * | |
10 * @see \Drupal\Core\Render\RendererInterface | |
11 * @see \Drupal\Core\Render\Renderer | |
12 * @see \Drupal\Core\Render\BubbleableMetadata | |
13 */ | |
14 class RenderContext extends \SplStack { | |
15 | |
16 /** | |
17 * Updates the current frame of the stack. | |
18 * | |
19 * @param array &$element | |
20 * The element of the render array that has just been rendered. The stack | |
21 * frame for this element will be updated with the bubbleable rendering | |
22 * metadata of this element. | |
23 */ | |
24 public function update(&$element) { | |
25 // The latest frame represents the bubbleable metadata for the subtree. | |
26 $frame = $this->pop(); | |
27 // Update the frame, but also update the current element, to ensure it | |
28 // contains up-to-date information in case it gets render cached. | |
29 $updated_frame = BubbleableMetadata::createFromRenderArray($element)->merge($frame); | |
30 $updated_frame->applyTo($element); | |
31 $this->push($updated_frame); | |
32 } | |
33 | |
34 /** | |
35 * Bubbles the stack. | |
36 * | |
37 * Whenever another level in the render array has been rendered, the stack | |
38 * must be bubbled, to merge its rendering metadata with that of the parent | |
39 * element. | |
40 */ | |
41 public function bubble() { | |
42 // If there's only one frame on the stack, then this is the root call, and | |
43 // we can't bubble up further. ::renderRoot() will reset the stack, but we | |
44 // must not reset it here to allow users of ::executeInRenderContext() to | |
45 // access the stack directly. | |
46 if ($this->count() === 1) { | |
47 return; | |
48 } | |
49 | |
50 // Merge the current and the parent stack frame. | |
51 $current = $this->pop(); | |
52 $parent = $this->pop(); | |
53 $this->push($current->merge($parent)); | |
54 } | |
55 | |
56 } |