'image', * '#attributes' => array('class' => array('foo')), * '#theme_wrappers' => array('container'), * ); * @endcode * and we need to pass the class 'bar' as an attribute for 'container', we * can rewrite our element thus: * @code * array( * '#theme' => 'image', * '#attributes' => array('class' => array('foo')), * '#theme_wrappers' => array( * 'container' => array( * '#attributes' => array('class' => array('bar')), * ), * ), * ); * @endcode * - If this element has an array of #post_render functions defined, they * are called sequentially to modify the rendered #children. Unlike * #pre_render functions, #post_render functions are passed both the * rendered #children attribute as a string and the element itself. * - If this element has #prefix and/or #suffix defined, they are * concatenated to #children. * - The rendering of this element is now complete. The next step will be * render caching. So this is the perfect time to update the stack. At * this point, children of this element (if any), have been rendered also, * and if there were any, their bubbleable rendering metadata will have * been bubbled up into the stack frame for the element that is currently * being rendered. The render cache item for this element must contain the * bubbleable rendering metadata for this element and all of its children. * However, right now, the topmost stack frame (the one for this element) * currently only contains the metadata for the children. Therefore, the * topmost stack frame is updated with this element's metadata, and then * the element's metadata is replaced with the metadata in the topmost * stack frame. This element now contains all bubbleable rendering * metadata for this element and all its children, so it's now ready for * render caching. * - If this element has #cache defined, the rendered output of this element * is saved to Renderer::render()'s internal cache. This includes the * changes made by #post_render. * At the same time, if $pre_bubbling_cid is set, it is compared to the * calculated cache ID. If they are different, then a redirecting cache * item is created, containing the #cache metadata of the current element, * and written to cache using the value of $pre_bubbling_cid as the cache * ID. This ensures the pre-bubbling ("wrong") cache ID redirects to the * post-bubbling ("right") cache ID. * - If this element also has #cache_properties defined, all the array items * matching the specified property names will be cached along with the * element markup. If properties include children names, the system * assumes only children's individual markup is relevant and ignores the * parent markup. This approach is normally not needed and should be * adopted only when dealing with very advanced use cases. * - If this element has attached placeholders ([#attached][placeholders]), * or any of its children has (which we would know thanks to the stack * having been updated just before the render caching step), its * placeholder element containing a #lazy_builder function is rendered in * isolation. The resulting markup is used to replace the placeholder, and * any bubbleable metadata is merged. * Placeholders must be unique, to guarantee that for instance, samples of * placeholders are not replaced as well. * - Just before finishing the rendering of this element, this element's * stack frame (the topmost one) is bubbled: the two topmost frames are * popped from the stack, they are merged and the result is pushed back * onto the stack. * So if for instance this element was a child element, then a new frame * was pushed onto the stack element at the beginning of rendering this * element, it was updated when the rendering was completed, and now we * merge it with the frame for the parent, so that the parent now has the * bubbleable rendering metadata for its child. * - #printed is set to TRUE for this element to ensure that it is only * rendered once. * - The final value of #children for this element is returned as the * rendered output. * * @param array $elements * The structured array describing the data to be rendered. * @param bool $is_root_call * (Internal use only.) Whether this is a recursive call or not. See * ::renderRoot(). * * @return \Drupal\Component\Render\MarkupInterface * The rendered HTML. * * @throws \LogicException * When called outside of a render context (i.e. outside of a renderRoot(), * renderInIsolation() or executeInRenderContext() call). * @throws \Exception * If a #pre_render callback throws an exception, it is caught to mark the * renderer as no longer being in a root render call, if any. Then the * exception is rethrown. * * @see \Drupal\Core\Render\ElementInfoManagerInterface::getInfo() * @see \Drupal\Core\Theme\ThemeManagerInterface::render() * @see \Drupal\Core\Form\FormHelper::processStates() * @see \Drupal\Core\Render\AttachmentsResponseProcessorInterface::processAttachments() * @see \Drupal\Core\Render\RendererInterface::renderRoot() */ public function render(&$elements, $is_root_call = FALSE); /** * Checks whether a render context is active. * * This is useful only in very specific situations to determine whether the * system is already capable of collecting bubbleable metadata. Normally it * should not be necessary to be concerned about this. * * @return bool * TRUE if the renderer has a render context active, FALSE otherwise. */ public function hasRenderContext(); /** * Executes a callable within a render context. * * Only for very advanced use cases. Prefer using ::renderRoot() and * ::renderInIsolation() instead. * * All rendering must happen within a render context. Within a render context, * all bubbleable metadata is bubbled and hence tracked. Outside of a render * context, it would be lost. This could lead to missing assets, incorrect * cache variations (and thus security issues), insufficient cache * invalidations, and so on. * * Any and all rendering must therefore happen within a render context, and it * is this method that provides that. * * @param \Drupal\Core\Render\RenderContext $context * The render context to execute the callable within. * @param callable $callable * The callable to execute. * * @return mixed * The callable's return value. * * @throws \LogicException * In case bubbling has failed, can only happen in case of broken code. * * @see \Drupal\Core\Render\RenderContext * @see \Drupal\Core\Render\BubbleableMetadata */ public function executeInRenderContext(RenderContext $context, callable $callable); /** * Merges the bubbleable rendering metadata o/t 2nd render array with the 1st. * * @param array $a * A render array. * @param array $b * A render array. * * @return array * The first render array, modified to also contain the bubbleable rendering * metadata of the second render array. * * @see \Drupal\Core\Render\BubbleableMetadata */ public function mergeBubbleableMetadata(array $a, array $b); /** * Adds a dependency on an object: merges its cacheability metadata. * * For instance, when a render array depends on some configuration, an entity, * or an access result, we must make sure their cacheability metadata is * present on the render array. This method makes doing that simple. * * @param array &$elements * The render array to update. * @param \Drupal\Core\Cache\CacheableDependencyInterface|mixed $dependency * The dependency. If the object implements CacheableDependencyInterface, * then its cacheability metadata will be used. Otherwise, the passed in * object must be assumed to be uncacheable, so max-age 0 is set. * * @see \Drupal\Core\Cache\CacheableMetadata::createFromObject() */ public function addCacheableDependency(array &$elements, $dependency); }