diff --git a/core/core.api.php b/core/core.api.php index fb612f23dbf..81b697cb938 100644 --- a/core/core.api.php +++ b/core/core.api.php @@ -2419,8 +2419,8 @@ function hook_validation_constraint_alter(array &$definitions) { * @code * array('#type' => 'status_messages') * @endcode - * to a render array, use drupal_render() to render it, and add a command to - * place the messages in an appropriate location. + * to a render array, use \Drupal::service('renderer')->render() to render it, + * and add a command to place the messages in an appropriate location. * * @section sec_other Other methods for triggering Ajax * Here are some additional methods you can use to trigger Ajax responses in diff --git a/core/includes/common.inc b/core/includes/common.inc index a9dbc8b44ad..5350acba31e 100644 --- a/core/includes/common.inc +++ b/core/includes/common.inc @@ -413,13 +413,13 @@ function render(&$element) { /** * Hides an element from later rendering. * - * The first time render() or drupal_render() is called on an element tree, - * as each element in the tree is rendered, it is marked with a #printed flag - * and the rendered children of the element are cached. Subsequent calls to - * render() or drupal_render() will not traverse the child tree of this element - * again: they will just use the cached children. So if you want to hide an - * element, be sure to call hide() on the element before its parent tree is - * rendered for the first time, as it will have no effect on subsequent + * The first time render() or RenderInterface::render() is called on an element + * tree, as each element in the tree is rendered, it is marked with a #printed + * flag and the rendered children of the element are cached. Subsequent calls to + * render() or RenderInterface::render() will not traverse the child tree of + * this element again: they will just use the cached children. So if you want to + * hide an element, be sure to call hide() on the element before its parent tree + * is rendered for the first time, as it will have no effect on subsequent * renderings of the parent tree. * * @param $element @@ -428,6 +428,7 @@ function render(&$element) { * @return * The element. * + * @see \Drupal\Core\Render\RendererInterface * @see render() * @see show() */ @@ -442,13 +443,13 @@ function hide(&$element) { * You can also use render($element), which shows the element while rendering * it. * - * The first time render() or drupal_render() is called on an element tree, - * as each element in the tree is rendered, it is marked with a #printed flag - * and the rendered children of the element are cached. Subsequent calls to - * render() or drupal_render() will not traverse the child tree of this element - * again: they will just use the cached children. So if you want to show an - * element, be sure to call show() on the element before its parent tree is - * rendered for the first time, as it will have no effect on subsequent + * The first time render() or RenderInterface::render() is called on an element + * tree, as each element in the tree is rendered, it is marked with a #printed + * flag and the rendered children of the element are cached. Subsequent calls to + * render() or RenderInterface::render() will not traverse the child tree of + * this element again: they will just use the cached children. So if you want to + * show an element, be sure to call show() on the element before its parent tree + * is rendered for the first time, as it will have no effect on subsequent * renderings of the parent tree. * * @param $element @@ -457,6 +458,7 @@ function hide(&$element) { * @return * The element. * + * @see \Drupal\Core\Render\RendererInterface * @see render() * @see hide() */ diff --git a/core/lib/Drupal/Core/Entity/EntityViewBuilder.php b/core/lib/Drupal/Core/Entity/EntityViewBuilder.php index 9ac0a6f5579..90e56472cf8 100644 --- a/core/lib/Drupal/Core/Entity/EntityViewBuilder.php +++ b/core/lib/Drupal/Core/Entity/EntityViewBuilder.php @@ -246,8 +246,8 @@ class EntityViewBuilder extends EntityHandlerBase implements EntityHandlerInterf * This function is assigned as a #pre_render callback in ::viewMultiple(). * * By delaying the building of an entity until the #pre_render processing in - * drupal_render(), the processing cost of assembling an entity's renderable - * array is saved on cache-hit requests. + * \Drupal::service('renderer')->render(), the processing cost of assembling + * an entity's renderable array is saved on cache-hit requests. * * @param array $build_list * A renderable array containing build information and context for an diff --git a/core/lib/Drupal/Core/Entity/entity.api.php b/core/lib/Drupal/Core/Entity/entity.api.php index 2114addd13e..7131c905070 100644 --- a/core/lib/Drupal/Core/Entity/entity.api.php +++ b/core/lib/Drupal/Core/Entity/entity.api.php @@ -1537,7 +1537,7 @@ function hook_ENTITY_TYPE_view(array &$build, \Drupal\Core\Entity\EntityInterfac * the particular entity type template, if there is one (e.g., node.html.twig). * * See the @link themeable Default theme implementations topic @endlink and - * drupal_render() for details. + * \Drupal\Core\Render\RendererInterface::render() for details. * * @param array &$build * A renderable array representing the entity content. @@ -1576,7 +1576,7 @@ function hook_entity_view_alter(array &$build, \Drupal\Core\Entity\EntityInterfa * the particular entity type template, if there is one (e.g., node.html.twig). * * See the @link themeable Default theme implementations topic @endlink and - * drupal_render() for details. + * \Drupal\Core\Render\RendererInterface::render() for details. * * @param array &$build * A renderable array representing the entity content. @@ -1659,7 +1659,7 @@ function hook_entity_view_mode_alter(&$view_mode, \Drupal\Core\Entity\EntityInte } /** - * Alter entity renderable values before cache checking in drupal_render(). + * Alter entity renderable values before cache checking during rendering. * * Invoked for a specific entity type. * @@ -1685,7 +1685,7 @@ function hook_ENTITY_TYPE_build_defaults_alter(array &$build, \Drupal\Core\Entit } /** - * Alter entity renderable values before cache checking in drupal_render(). + * Alter entity renderable values before cache checking during rendering. * * The values in the #cache key of the renderable array are used to determine if * a cache entry exists for the entity's rendered output. Ideally only values diff --git a/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php b/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php index 011cc1af490..f904bc5f7a2 100644 --- a/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php +++ b/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php @@ -17,11 +17,11 @@ use Symfony\Component\HttpKernel\KernelEvents; /** * Subscriber that wraps controllers, to handle early rendering. * - * When controllers call drupal_render() (RendererInterface::render()) outside - * of a render context, we call that "early rendering". Controllers should - * return only render arrays, but we cannot prevent controllers from doing early - * rendering. The problem with early rendering is that the bubbleable metadata - * (cacheability & attachments) are lost. + * When controllers call RendererInterface::render() outside of a render + * context, we call that "early rendering". Controllers should return + * only render arrays, but we cannot prevent controllers from doing + * early rendering. The problem with early rendering is that the + * bubbleable metadata (cacheability & attachments) are lost. * * This can lead to broken pages (missing assets), stale pages (missing cache * tags causing a page not to be invalidated) or even security problems (missing @@ -36,8 +36,8 @@ use Symfony\Component\HttpKernel\KernelEvents; * ::renderPlain() methods. In that case, no bubbleable metadata is lost. * * If the render context is not empty, then the controller did use - * drupal_render(), and bubbleable metadata was collected. This bubbleable - * metadata is then merged onto the render array. + * RendererInterface::render(), and bubbleable metadata was collected. + * This bubbleable metadata is then merged onto the render array. * * In other words: this just exists to ease the transition to Drupal 8: it * allows controllers that return render arrays (the majority) and @@ -124,8 +124,8 @@ class EarlyRenderingControllerWrapperSubscriber implements EventSubscriberInterf }); // If early rendering happened, i.e. if code in the controller called - // drupal_render() outside of a render context, then the bubbleable metadata - // for that is stored in the current render context. + // RendererInterface::render() outside of a render context, then the + // bubbleable metadata for that is stored in the current render context. if (!$context->isEmpty()) { /** @var \Drupal\Core\Render\BubbleableMetadata $early_rendering_bubbleable_metadata */ $early_rendering_bubbleable_metadata = $context->pop(); diff --git a/core/lib/Drupal/Core/Form/FormBuilderInterface.php b/core/lib/Drupal/Core/Form/FormBuilderInterface.php index 66f75d80227..bcdc9b1a3b7 100644 --- a/core/lib/Drupal/Core/Form/FormBuilderInterface.php +++ b/core/lib/Drupal/Core/Form/FormBuilderInterface.php @@ -245,10 +245,11 @@ interface FormBuilderInterface { * This is one of the three primary functions that recursively iterates a form * array. This one does it for completing the form building process. The other * two are self::doValidateForm() (invoked via self::validateForm() and used - * to invoke validation logic for each element) and drupal_render() (for - * rendering each element). Each of these three pipelines provides ample - * opportunity for modules to customize what happens. For example, during this - * function's life cycle, the following functions get called for each element: + * to invoke validation logic for each element) and + * RendererInterface::render() (for rendering each element). + * Each of these three pipelines provides ample opportunity for modules to + * customize what happens. For example, during this function's life cycle, + * the following functions get called for each element: * - $element['#value_callback']: A callable that implements how user input is * mapped to an element's #value property. This defaults to a function named * 'form_type_TYPE_value' where TYPE is $element['#type']. @@ -269,8 +270,8 @@ interface FormBuilderInterface { * called in postorder traversal, meaning they are called for the child * elements first, then for the parent element. * There are similar properties containing callback functions invoked by - * self::doValidateForm() and drupal_render(), appropriate for those - * operations. + * self::doValidateForm() and RendererInterface::render(), + * appropriate for those operations. * * Developers are strongly encouraged to integrate the functionality needed by * their form or module within one of these three pipelines, using the diff --git a/core/lib/Drupal/Core/Menu/MenuLinkTree.php b/core/lib/Drupal/Core/Menu/MenuLinkTree.php index b0399312fd5..52991cefa61 100644 --- a/core/lib/Drupal/Core/Menu/MenuLinkTree.php +++ b/core/lib/Drupal/Core/Menu/MenuLinkTree.php @@ -171,7 +171,8 @@ class MenuLinkTree implements MenuLinkTreeInterface { $tree_cacheability->applyTo($build); if ($items) { - // Make sure drupal_render() does not re-order the links. + // Make sure Drupal\Core\Render\Element::children() does not re-order the + // links. $build['#sorted'] = TRUE; // Get the menu name from the last link. $item = end($items); diff --git a/core/lib/Drupal/Core/Render/Element.php b/core/lib/Drupal/Core/Render/Element.php index ed7a444980b..dfd4eb099d3 100644 --- a/core/lib/Drupal/Core/Render/Element.php +++ b/core/lib/Drupal/Core/Render/Element.php @@ -57,7 +57,8 @@ class Element { * Identifies the children of an element array, optionally sorted by weight. * * The children of an element array are those key/value pairs whose key does - * not start with a '#'. See drupal_render() for details. + * not start with a '#'. See \Drupal\Core\Render\RendererInterface::render() + * for details. * * @param array $elements * The element array whose children are to be identified. Passed by diff --git a/core/lib/Drupal/Core/Render/Element/HtmlTag.php b/core/lib/Drupal/Core/Render/Element/HtmlTag.php index 94a7ef18cec..8105c487f94 100644 --- a/core/lib/Drupal/Core/Render/Element/HtmlTag.php +++ b/core/lib/Drupal/Core/Render/Element/HtmlTag.php @@ -172,8 +172,8 @@ class HtmlTag extends RenderElement { // technique. See http://wikipedia.org/wiki/Conditional_comment // for details. - // Ensure what we are dealing with is safe. - // This would be done later anyway in drupal_render(). + // Ensure what we are dealing with is safe. This would be done later anyway + // in \Drupal::service('renderer')->render(). $prefix = isset($element['#prefix']) ? $element['#prefix'] : ''; if ($prefix && !($prefix instanceof MarkupInterface)) { $prefix = Xss::filterAdmin($prefix); diff --git a/core/lib/Drupal/Core/Render/Element/Link.php b/core/lib/Drupal/Core/Render/Element/Link.php index 8021a809120..2af8bf0b27a 100644 --- a/core/lib/Drupal/Core/Render/Element/Link.php +++ b/core/lib/Drupal/Core/Render/Element/Link.php @@ -111,9 +111,10 @@ class Link extends RenderElement { * * The purpose of this is to allow links to be logically grouped into related * categories, so that each child group can be rendered as its own list of - * links if drupal_render() is called on it, but calling drupal_render() on - * the parent element will still produce a single list containing all the - * remaining links, regardless of what group they were in. + * links if RendererInterface::render() is called on it, but + * calling RendererInterface::render() on the parent element will + * still produce a single list containing all the remaining links, regardless + * of what group they were in. * * A typical example comes from node links, which are stored in a renderable * array similar to this: diff --git a/core/lib/Drupal/Core/Render/Renderer.php b/core/lib/Drupal/Core/Render/Renderer.php index 25b294c665e..2ea2ca113c0 100644 --- a/core/lib/Drupal/Core/Render/Renderer.php +++ b/core/lib/Drupal/Core/Render/Renderer.php @@ -548,7 +548,7 @@ class Renderer implements RendererInterface { $this->replacePlaceholders($elements); // @todo remove as part of https://www.drupal.org/node/2511330. if ($context->count() !== 1) { - throw new \LogicException('A stray drupal_render() invocation with $is_root_call = TRUE is causing bubbling of attached assets to break.'); + throw new \LogicException('A stray RendererInterface::render() invocation with $is_root_call = TRUE is causing bubbling of attached assets to break.'); } } diff --git a/core/lib/Drupal/Core/Render/theme.api.php b/core/lib/Drupal/Core/Render/theme.api.php index 47a94de36ee..778e48524e7 100644 --- a/core/lib/Drupal/Core/Render/theme.api.php +++ b/core/lib/Drupal/Core/Render/theme.api.php @@ -17,11 +17,12 @@ * hierarchical arrays that include the data to be rendered into HTML (or XML or * another output format), and options that affect the markup. Render arrays * are ultimately rendered into HTML or other output formats by recursive calls - * to drupal_render(), traversing the depth of the render array hierarchy. At - * each level, the theme system is invoked to do the actual rendering. See the - * documentation of drupal_render() and the - * @link theme_render Theme system and Render API topic @endlink for more - * information about render arrays and rendering. + * to \Drupal\Core\Render\RendererInterface::render(), traversing the depth of + * the render array hierarchy. At each level, the theme system is invoked to do + * the actual rendering. See the documentation of + * \Drupal\Core\Render\RendererInterface::render() and the @link theme_render + * Theme system and Render API topic @endlink for more information about render + * arrays and rendering. * * @section sec_twig_theme Twig Templating Engine * Drupal 8 uses the templating engine Twig. Twig offers developers a fast, @@ -241,13 +242,16 @@ * hierarchical associative array containing data to be rendered and properties * describing how the data should be rendered. A render array that is returned * by a function to specify markup to be sent to the web browser or other - * services will eventually be rendered by a call to drupal_render(), which will - * recurse through the render array hierarchy if appropriate, making calls into - * the theme system to do the actual rendering. If a function or method actually - * needs to return rendered output rather than a render array, the best practice - * would be to create a render array, render it by calling drupal_render(), and - * return that result, rather than writing the markup directly. See the - * documentation of drupal_render() for more details of the rendering process. + * services will eventually be rendered by a call to + * \Drupal\Core\Render\RendererInterface::render(), which will recurse through + * the render array hierarchy if appropriate, making calls into the theme system + * to do the actual rendering. If a function or method actually needs to return + * rendered output rather than a render array, the best practice would be to + * create a render array, render it by calling + * \Drupal\Core\Render\RendererInterface::render(), and return that result, + * rather than writing the markup directly. See the documentation of + * \Drupal\Core\Render\RendererInterface::render() for more details of the + * rendering process. * * Each level in the hierarchy of a render array (including the outermost array) * has one or more array elements. Array elements whose names start with '#' are diff --git a/core/modules/block/block.api.php b/core/modules/block/block.api.php index d9626c82728..8c2e5b0b0be 100644 --- a/core/modules/block/block.api.php +++ b/core/modules/block/block.api.php @@ -72,8 +72,9 @@ use Drupal\Core\Access\AccessResult; * If the module wishes to act on the rendered HTML of the block rather than * the structured content array, it may use this hook to add a #post_render * callback. Alternatively, it could also implement hook_preprocess_HOOK() for - * block.html.twig. See drupal_render() documentation or the - * @link themeable Default theme implementations topic @endlink for details. + * block.html.twig. See \Drupal\Core\Render\RendererInterface::render() + * documentation or the @link themeable Default theme implementations topic + * @endlink for details. * * In addition to hook_block_view_alter(), which is called for all blocks, there * is hook_block_view_BASE_BLOCK_ID_alter(), which can be used to target a diff --git a/core/modules/book/src/BookManager.php b/core/modules/book/src/BookManager.php index 0edcdf08440..12d023cd391 100644 --- a/core/modules/book/src/BookManager.php +++ b/core/modules/book/src/BookManager.php @@ -596,7 +596,8 @@ class BookManager implements BookManagerInterface { $build = []; if ($items) { - // Make sure drupal_render() does not re-order the links. + // Make sure Drupal\Core\Render\Element::children() does not re-order the + // links. $build['#sorted'] = TRUE; // Get the book id from the last link. $item = end($items); diff --git a/core/modules/contextual/src/Element/ContextualLinks.php b/core/modules/contextual/src/Element/ContextualLinks.php index 4e43de8e40a..c4bd3b21f71 100644 --- a/core/modules/contextual/src/Element/ContextualLinks.php +++ b/core/modules/contextual/src/Element/ContextualLinks.php @@ -86,7 +86,8 @@ class ContextualLinks extends RenderElement { // Allow modules to alter the renderable contextual links element. static::moduleHandler()->alter('contextual_links_view', $element, $items); - // If there are no links, tell drupal_render() to abort rendering. + // If there are no links, tell \Drupal::service('renderer')->render() to + // abort rendering. if (empty($element['#links'])) { $element['#printed'] = TRUE; } diff --git a/core/modules/image/tests/src/Functional/ImageDimensionsTest.php b/core/modules/image/tests/src/Functional/ImageDimensionsTest.php index 4820e5d14d4..4007281f56c 100644 --- a/core/modules/image/tests/src/Functional/ImageDimensionsTest.php +++ b/core/modules/image/tests/src/Functional/ImageDimensionsTest.php @@ -296,11 +296,12 @@ class ImageDimensionsTest extends BrowserTestBase { /** * Render an image style element. * - * Function drupal_render() alters the passed $variables array by adding a new - * key '#printed' => TRUE. This prevents next call to re-render the element. - * We wrap drupal_render() in a helper protected method and pass each time a - * fresh array so that $variables won't get altered and the element is - * re-rendered each time. + * Function \Drupal\Core\Render\RendererInterface::render() alters the passed + * $variables array by adding a new key '#printed' => TRUE. This prevents next + * call to re-render the element. We wrap + * \Drupal\Core\Render\RendererInterface::render() in a helper protected + * method and pass each time a fresh array so that $variables won't get + * altered and the element is re-rendered each time. */ protected function getImageTag($variables) { return str_replace("\n", NULL, \Drupal::service('renderer')->renderRoot($variables)); diff --git a/core/modules/system/tests/modules/theme_legacy_test/theme_legacy_test.module b/core/modules/system/tests/modules/theme_legacy_test/theme_legacy_test.module index 6001e4fd00e..8eb95efb242 100644 --- a/core/modules/system/tests/modules/theme_legacy_test/theme_legacy_test.module +++ b/core/modules/system/tests/modules/theme_legacy_test/theme_legacy_test.module @@ -63,12 +63,12 @@ function theme_theme_test_function_template_override($variables) { } /** - * Theme function for testing rendering of child elements via drupal_render(). + * Theme function for testing rendering of child elements. * * Theme hooks defining a 'render element' add an internal '#render_children' - * property. When this property is found, drupal_render() avoids calling - * the 'theme.manager' service 'render' method on the top-level element to - * prevent infinite recursion. + * property. When this property is found, \Drupal::service('renderer')->render() + * avoids calling the 'theme.manager' service's ThemeManagerInterface::render() + * method on the top-level element to prevent infinite recursion. * * @param array $variables * An associative array containing: diff --git a/core/modules/system/tests/src/Functional/Common/RenderWebTest.php b/core/modules/system/tests/src/Functional/Common/RenderWebTest.php index 8c5c54db296..fce229cfbd1 100644 --- a/core/modules/system/tests/src/Functional/Common/RenderWebTest.php +++ b/core/modules/system/tests/src/Functional/Common/RenderWebTest.php @@ -8,7 +8,7 @@ use Drupal\Tests\BrowserTestBase; use Drupal\Tests\system\Functional\Cache\AssertPageCacheContextsAndTagsTrait; /** - * Performs integration tests on drupal_render(). + * Performs integration tests on \Drupal::service('renderer')->render(). * * @group Common */ diff --git a/core/modules/system/tests/src/Kernel/Common/FormElementsRenderTest.php b/core/modules/system/tests/src/Kernel/Common/FormElementsRenderTest.php index c9d1cdca985..9c833045562 100644 --- a/core/modules/system/tests/src/Kernel/Common/FormElementsRenderTest.php +++ b/core/modules/system/tests/src/Kernel/Common/FormElementsRenderTest.php @@ -7,7 +7,7 @@ use Drupal\Core\Url; use Drupal\KernelTests\KernelTestBase; /** - * Performs integration tests on drupal_render(). + * Performs integration tests on \Drupal::service('renderer')->render(). * * @group system */ diff --git a/core/modules/system/tests/src/Kernel/Theme/ThemeTest.php b/core/modules/system/tests/src/Kernel/Theme/ThemeTest.php index 5a072ea434e..dedc1705d8b 100644 --- a/core/modules/system/tests/src/Kernel/Theme/ThemeTest.php +++ b/core/modules/system/tests/src/Kernel/Theme/ThemeTest.php @@ -135,7 +135,7 @@ class ThemeTest extends KernelTestBase { '#markup' => 'Foo', ], ]; - $this->assertThemeOutput('theme_test_render_element_children', $element, 'Foo', 'drupal_render() avoids #theme recursion loop when rendering a render element.'); + $this->assertThemeOutput('theme_test_render_element_children', $element, 'Foo', "\Drupal::service('renderer')->render() avoids #theme recursion loop when rendering a render element."); $element = [ '#theme_wrappers' => ['theme_test_render_element_children'], @@ -143,7 +143,7 @@ class ThemeTest extends KernelTestBase { '#markup' => 'Foo', ], ]; - $this->assertThemeOutput('theme_test_render_element_children', $element, 'Foo', 'drupal_render() avoids #theme_wrappers recursion loop when rendering a render element.'); + $this->assertThemeOutput('theme_test_render_element_children', $element, 'Foo', "\Drupal::service('renderer')->render() avoids #theme_wrappers recursion loop when rendering a render element."); } /** diff --git a/core/modules/toolbar/src/Element/Toolbar.php b/core/modules/toolbar/src/Element/Toolbar.php index e2a9a7ff3ba..9546533fae6 100644 --- a/core/modules/toolbar/src/Element/Toolbar.php +++ b/core/modules/toolbar/src/Element/Toolbar.php @@ -50,7 +50,7 @@ class Toolbar extends RenderElement { } /** - * Builds the Toolbar as a structured array ready for drupal_render(). + * Builds the Toolbar as a structured array ready for rendering. * * Since building the toolbar takes some time, it is done just prior to * rendering to ensure that it is built only if it will be displayed. diff --git a/core/modules/views/src/Plugin/views/field/FieldHandlerInterface.php b/core/modules/views/src/Plugin/views/field/FieldHandlerInterface.php index 2562b954c05..f332e4b7bd1 100644 --- a/core/modules/views/src/Plugin/views/field/FieldHandlerInterface.php +++ b/core/modules/views/src/Plugin/views/field/FieldHandlerInterface.php @@ -255,7 +255,7 @@ interface FieldHandlerInterface extends ViewsHandlerInterface { public function getRenderTokens($item); /** - * Passes values to drupal_render() using $this->themeFunctions() as #theme. + * Renders row values using $this->themeFunctions() as #theme. * * @param \Drupal\views\ResultRow $values * Holds single row of a view's result set. diff --git a/core/tests/Drupal/KernelTests/Core/Entity/EntityViewBuilderTest.php b/core/tests/Drupal/KernelTests/Core/Entity/EntityViewBuilderTest.php index fe68e84a350..61ffb8dd160 100644 --- a/core/tests/Drupal/KernelTests/Core/Entity/EntityViewBuilderTest.php +++ b/core/tests/Drupal/KernelTests/Core/Entity/EntityViewBuilderTest.php @@ -45,7 +45,7 @@ class EntityViewBuilderTest extends EntityKernelTestBase { $cache_contexts_manager = \Drupal::service("cache_contexts_manager"); $cache = \Drupal::cache(); - // Force a request via GET so we can get drupal_render() cache working. + // Force a request via GET so cache is rendered. $request = \Drupal::request(); $request_method = $request->server->get('REQUEST_METHOD'); $request->setMethod('GET'); @@ -99,7 +99,8 @@ class EntityViewBuilderTest extends EntityKernelTestBase { $renderer = $this->container->get('renderer'); $cache_contexts_manager = \Drupal::service("cache_contexts_manager"); - // Force a request via GET so we can get drupal_render() cache working. + // Force a request via GET so we can get + // \Drupal::service('renderer')->render() cache working. $request = \Drupal::request(); $request_method = $request->server->get('REQUEST_METHOD'); $request->setMethod('GET'); diff --git a/core/tests/Drupal/KernelTests/Core/Render/Element/RenderElementTypesTest.php b/core/tests/Drupal/KernelTests/Core/Render/Element/RenderElementTypesTest.php index 286ea3554ed..b589d0e5f69 100644 --- a/core/tests/Drupal/KernelTests/Core/Render/Element/RenderElementTypesTest.php +++ b/core/tests/Drupal/KernelTests/Core/Render/Element/RenderElementTypesTest.php @@ -7,7 +7,7 @@ use Drupal\Core\Url; use Drupal\KernelTests\KernelTestBase; /** - * Tests the markup of core render element types passed to drupal_render(). + * Tests the rendered markup of core render element types. * * @group Common */ @@ -182,7 +182,7 @@ class RenderElementTypesTest extends KernelTestBase { foreach ($elements as $element) { $xml = new \SimpleXMLElement(\Drupal::service('renderer')->renderRoot($element['value'])); $result = $xml->xpath($element['expected']); - $this->assertNotEmpty($result, '"' . $element['name'] . '" input rendered correctly by drupal_render().'); + $this->assertNotEmpty($result, '"' . $element['name'] . '" input rendered correctly.'); } } @@ -213,7 +213,7 @@ class RenderElementTypesTest extends KernelTestBase { foreach ($elements as $element) { $xml = new \SimpleXMLElement(\Drupal::service('renderer')->renderRoot($element['value'])); $result = $xml->xpath($element['expected']); - $this->assertNotEmpty($result, '"' . $element['name'] . '" is rendered correctly by drupal_render().'); + $this->assertNotEmpty($result, '"' . $element['name'] . '" is rendered correctly.'); } // Set admin compact mode on for additional tests. @@ -229,7 +229,7 @@ class RenderElementTypesTest extends KernelTestBase { $xml = new \SimpleXMLElement(\Drupal::service('renderer')->renderRoot($element['value'])); $result = $xml->xpath($element['expected']); - $this->assertNotEmpty($result, '"' . $element['name'] . '" is rendered correctly by drupal_render().'); + $this->assertNotEmpty($result, '"' . $element['name'] . '" is rendered correctly.'); } } diff --git a/core/tests/Drupal/KernelTests/Core/Render/RenderTest.php b/core/tests/Drupal/KernelTests/Core/Render/RenderTest.php index ad1d112e68a..db369a238cd 100644 --- a/core/tests/Drupal/KernelTests/Core/Render/RenderTest.php +++ b/core/tests/Drupal/KernelTests/Core/Render/RenderTest.php @@ -5,7 +5,7 @@ namespace Drupal\KernelTests\Core\Render; use Drupal\KernelTests\KernelTestBase; /** - * Performs functional tests on drupal_render(). + * Performs functional tests on \Drupal::service('renderer')->render(). * * @group Common */ diff --git a/core/tests/Drupal/Tests/Core/Render/RendererTest.php b/core/tests/Drupal/Tests/Core/Render/RendererTest.php index c67e9a7558d..44ccb5b73c2 100644 --- a/core/tests/Drupal/Tests/Core/Render/RendererTest.php +++ b/core/tests/Drupal/Tests/Core/Render/RendererTest.php @@ -507,8 +507,9 @@ class RendererTest extends RendererTestBase { $this->assertTrue($elements['#sorted'], "'#sorted' => TRUE was added to the array"); // Pass $elements through \Drupal\Core\Render\Element::children() and - // ensure it remains sorted in the correct order. drupal_render() will - // return an empty string if used on the same array in the same request. + // ensure it remains sorted in the correct order. + // \Drupal::service('renderer')->render() will return an empty string if + // used on the same array in the same request. $children = Element::children($elements); $this->assertSame('first', array_shift($children), 'Child found in the correct order.'); $this->assertSame('second', array_shift($children), 'Child found in the correct order.'); diff --git a/core/tests/Drupal/Tests/EntityViewTrait.php b/core/tests/Drupal/Tests/EntityViewTrait.php index e2891b9498d..6f7fad29467 100644 --- a/core/tests/Drupal/Tests/EntityViewTrait.php +++ b/core/tests/Drupal/Tests/EntityViewTrait.php @@ -15,11 +15,11 @@ trait EntityViewTrait { * * Entities postpone the composition of their renderable arrays to #pre_render * functions in order to maximize cache efficacy. This means that the full - * renderable array for an entity is constructed in drupal_render(). Some - * tests require the complete renderable array for an entity outside of the - * drupal_render process in order to verify the presence of specific values. - * This method isolates the steps in the render process that produce an - * entity's renderable array. + * renderable array for an entity is constructed in + * \Drupal::service('renderer')->render(). Some tests require the complete + * renderable array for an entity outside of the render process in order to + * verify the presence of specific values. This method isolates the steps in + * the render process that produce an entity's renderable array. * * @param \Drupal\Core\Entity\EntityInterface $entity * The entity to prepare a renderable array for. diff --git a/core/themes/claro/claro.theme b/core/themes/claro/claro.theme index dd4497f1699..5916898c02c 100644 --- a/core/themes/claro/claro.theme +++ b/core/themes/claro/claro.theme @@ -42,9 +42,8 @@ function claro_theme_suggestions_details_alter(&$suggestions, $variables) { /** * Implements hook_preprocess_HOOK() for menu-local-tasks templates. * - * Use preprocess hook to set #attached to child elements - * because they will be processed by Twig and drupal_render will - * be invoked. + * Use preprocess hook to set #attached to child elements because they will be + * processed by Twig and \Drupal::service('renderer')->render() will be invoked. */ function claro_preprocess_menu_local_tasks(&$variables) { if (!empty($variables['primary'])) { diff --git a/core/themes/seven/seven.theme b/core/themes/seven/seven.theme index f82c38d2329..8aa5ed8f717 100644 --- a/core/themes/seven/seven.theme +++ b/core/themes/seven/seven.theme @@ -30,9 +30,8 @@ function seven_preprocess_html(&$variables) { /** * Implements hook_preprocess_HOOK() for menu-local-tasks templates. * - * Use preprocess hook to set #attached to child elements - * because they will be processed by Twig and drupal_render will - * be invoked. + * Use preprocess hook to set #attached to child elements because they will be + * processed by Twig and \Drupal::service('renderer')->render() will be invoked. */ function seven_preprocess_menu_local_tasks(&$variables) { if (!empty($variables['primary'])) {