Problem/Motivation

The patch being prepared in #2834889: Replace documentation and string references to drupal_render() was becoming unwieldy so it was decided that it should be split into smaller chunks.

Rewrite one-line summaries that refer to drupal_render(), since unlike most things these aren't going to work as straight string-replaces. They probably shouldn't refer to it anyway; it's an implementation detail. Usually, "during rendering" or such is probably an acceptable substitution in one-line summaries.

Proposed resolution

Update references as appropriate.

Remaining tasks

User interface changes

API changes

Data model changes

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Jo Fitzgerald created an issue. See original summary.

msankhala’s picture

Shouldn't we change this issue title Replace drupal_render() in one-line summaries => Replace drupal_render() in docblock and comments outside of @param, @return, @link, @see and outside of @code - @endcode

because drupal_render is also mentioned in docblocks and comments which are not the one-line summary. Rest drupal_render() in dockblocks are already fixed in #2938970: Replace drupal_render() in @param, @return, @see, @link, etc. and #2938972: Replace drupal_render() in sample code

After fixing this issue drupal_render will only remain in actual code in function/method body, not in docblock or comments which can be fixed in #2938973: Replace drupal_render() within the Render component

msankhala’s picture

Here is my first patch according to my comment #2. After this patch drupal_render() only remains in core/include/common.inc where it is actually referencing to drupal_render() function.

msankhala’s picture

Status: Active » Needs review

Status: Needs review » Needs work

The last submitted patch, 3: 2938969-3.patch, failed testing. View results

msankhala’s picture

Status: Needs work » Needs review
FileSize
27.4 KB

Here is updated patch.

msankhala’s picture

Title: Replace drupal_render() in one-line summaries » Replace drupal_render() in docblock and comments outside of @param, @return, @link, @see and outside of @code - @endcode

Version: 8.6.x-dev » 8.7.x-dev

Drupal 8.6.0-alpha1 will be released the week of July 16, 2018, which means new developments and disruptive changes should now be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

MerryHamster’s picture

FileSize
27.87 KB

reroll to 8.7.x, and added little fixes

msankhala’s picture

Status: Needs review » Reviewed & tested by the community

@MerryHamster Thanks for working on this issue. I can confirm the patch #9 is fixing all the mention of drupal_render() as per issue title. After applying the patch the only places where drupal_render() is remaining is inside the actual render components or tests which should be fixed in #2938973: Replace drupal_render() within the Render component

Mention of drupal_render() inside the core/includes/common.inc is expected.

After applying the patch:

d8core 2938969-replace-drupal_render-outside* rg 'drupal_render\(\)' core
core/includes/common.inc
776: * links if drupal_render() is called on it, but calling drupal_render() on the
958: * The first time render() or drupal_render() is called on an element tree,
961: * render() or drupal_render() will not traverse the child tree of this element
987: * The first time render() or drupal_render() is called on an element tree,
990: * render() or drupal_render() will not traverse the child tree of this element

core/lib/Drupal/Core/Render/Renderer.php
555:        throw new \LogicException('A stray drupal_render() invocation with $is_root_call = TRUE is causing bubbling of attached assets to break.');

core/tests/Drupal/KernelTests/Core/Render/Element/RenderElementTypesTest.php
194:      $this->assertTrue($result, '"' . $element['name'] . '" input rendered correctly by drupal_render().');
225:      $this->assertTrue($result, '"' . $element['name'] . '" is rendered correctly by drupal_render().');
241:    $this->assertTrue($result, '"' . $element['name'] . '" is rendered correctly by drupal_render().');

core/modules/system/tests/src/Kernel/Theme/ThemeTest.php
138:    $this->assertThemeOutput('theme_test_render_element_children', $element, 'Foo', 'drupal_render() avoids #theme recursion loop when rendering a render element.');
146:    $this->assertThemeOutput('theme_test_render_element_children', $element, 'Foo', 'drupal_render() avoids #theme_wrappers recursion loop when rendering a render element.');

I am using ripgrep to search, you can verify the same with grep.

The last submitted patch, 6: 2938969-6.patch, failed testing. View results

catch credited tameeshb.

catch’s picture

catch credited ZeiP.

catch credited alexpott.

catch credited boaloysius.

catch credited darrenwh.

catch credited ritzz.

catch credited wturrell.

catch credited xjm.

catch’s picture

Crediting people from the parent issue.

alexpott’s picture

Status: Reviewed & tested by the community » Needs work
+++ b/core/lib/Drupal/Core/Entity/entity.api.php
@@ -1604,7 +1604,8 @@ function hook_entity_view_mode_alter(&$view_mode, Drupal\Core\Entity\EntityInter
- * Alter entity renderable values before cache checking in drupal_render().
+ * Alter entity renderable values before cache checking in
+ * \Drupal::service('renderer')->render().

@@ -1630,7 +1631,8 @@ 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 in
+ * \Drupal::service('renderer')->render().

+++ b/core/modules/node/node.module
@@ -816,7 +816,8 @@ function node_view(NodeInterface $node, $view_mode = 'full', $langcode = NULL) {
- * Constructs a drupal_render() style array from an array of loaded nodes.
+ * Constructs a \Drupal\Core\Render\RendererInterface::render() style array from
+ * an array of loaded nodes.

+++ b/core/modules/system/tests/modules/theme_test/theme_test.module
@@ -145,12 +145,13 @@ function template_preprocess_theme_test_render_element(&$variables) {
- * Theme function for testing rendering of child elements via drupal_render().
+ * Theme function for testing rendering of child elements via
+ * \Drupal::service('renderer')->render().

+++ b/core/modules/taxonomy/taxonomy.module
@@ -221,7 +221,8 @@ function taxonomy_term_view(Term $term, $view_mode = 'full', $langcode = NULL) {
- * Constructs a drupal_render() style array from an array of loaded terms.
+ * Constructs a \Drupal\Core\Render\RendererInterface::render() style array from
+ * an array of loaded terms.

+++ b/core/modules/toolbar/src/Element/Toolbar.php
@@ -50,7 +50,8 @@ public function getInfo() {
-   * Builds the Toolbar as a structured array ready for drupal_render().
+   * Builds the Toolbar as a structured array ready for
+   * \Drupal\Core\Render\RendererInterface::render().

+++ b/core/modules/user/user.module
@@ -907,7 +907,8 @@ function user_view($account, $view_mode = 'full', $langcode = NULL) {
- * Constructs a drupal_render() style array from an array of loaded users.
+ * Constructs a \Drupal\Core\Render\RendererInterface::render() style array from
+ * an array of loaded users.

+++ b/core/modules/views/src/Plugin/views/field/FieldHandlerInterface.php
@@ -255,7 +255,8 @@ public function renderText($alter);
-   * Passes values to drupal_render() using $this->themeFunctions() as #theme.
+   * Passes values to \Drupal::service('renderer')->render() using
+   * $this->themeFunctions() as #theme.
    *

+++ b/core/tests/Drupal/KernelTests/Core/Render/Element/RenderElementTypesTest.php
@@ -7,7 +7,8 @@
- * Tests the markup of core render element types passed to drupal_render().
+ * Tests the markup of core render element types passed to
+ * \Drupal::service('renderer')->render().

These need to be a one-liner to comply with coding standards.

dhirendra.mishra’s picture

Assigned: Unassigned » dhirendra.mishra

i am working on it.

dhirendra.mishra’s picture

Assigned: dhirendra.mishra » Unassigned
Status: Needs work » Needs review
FileSize
6.82 KB
28 KB

Pls find the Updated patch and interdiff.

alexpott’s picture

Status: Needs review » Needs work
+++ b/core/lib/Drupal/Core/Entity/entity.api.php
@@ -1633,7 +1633,7 @@ function hook_entity_view_mode_alter(&$view_mode, Drupal\Core\Entity\EntityInter
- * Alter entity renderable values before cache checking in drupal_render().
+ * Alter entity renderable values before cache checking in \Drupal::service('renderer')->render().

@@ -1659,7 +1659,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 in \Drupal::service('renderer')->render().

+++ b/core/modules/node/node.module
@@ -817,7 +817,7 @@ function node_view(NodeInterface $node, $view_mode = 'full', $langcode = NULL) {
- * Constructs a drupal_render() style array from an array of loaded nodes.
+ * Constructs a \Drupal\Core\Render\RendererInterface::render() style array from an array of loaded nodes.

+++ b/core/modules/system/tests/modules/theme_test/theme_test.module
@@ -145,12 +145,12 @@ function template_preprocess_theme_test_render_element(&$variables) {
- * Theme function for testing rendering of child elements via drupal_render().
+ * Theme function for testing rendering of child elements via \Drupal::service('renderer')->render().

+++ b/core/modules/taxonomy/taxonomy.module
@@ -203,7 +203,7 @@ function taxonomy_term_view(Term $term, $view_mode = 'full', $langcode = NULL) {
- * Constructs a drupal_render() style array from an array of loaded terms.
+ * Constructs a \Drupal\Core\Render\RendererInterface::render() style array from an array of loaded terms.

+++ b/core/modules/toolbar/src/Element/Toolbar.php
@@ -50,7 +50,7 @@ public function getInfo() {
-   * Builds the Toolbar as a structured array ready for drupal_render().
+   * Builds the Toolbar as a structured array ready for \Drupal\Core\Render\RendererInterface::render().

+++ b/core/modules/user/user.module
@@ -913,7 +913,7 @@ function user_view($account, $view_mode = 'full', $langcode = NULL) {
+ * Constructs a \Drupal\Core\Render\RendererInterface::render() style array from an array of loaded users.

+++ b/core/modules/views/src/Plugin/views/field/FieldHandlerInterface.php
@@ -255,7 +255,7 @@ public function renderText($alter);
-   * Passes values to drupal_render() using $this->themeFunctions() as #theme.
+   * Passes values to \Drupal::service('renderer')->render() using $this->themeFunctions() as #theme.

+++ b/core/tests/Drupal/KernelTests/Core/Render/Element/RenderElementTypesTest.php
@@ -7,7 +7,7 @@
- * Tests the markup of core render element types passed to drupal_render().
+ * Tests the markup of core render element types passed to \Drupal::service('renderer')->render().

These have to be one line and less than 80 cols. It's tricky.

Also I'm not sure the interdiff is correct because it looks like it is adding new drupal_render() usages being introduced but there are no in the patch.

dhirendra.mishra’s picture

Status: Needs work » Needs review

I don't know what gone wrong with interdiff file in comment #26. But patch file looks ok to me.

@alexpott, If u look at patch file then all changes are already included.

Version: 8.7.x-dev » 8.8.x-dev

Drupal 8.7.0-alpha1 will be released the week of March 11, 2019, which means new developments and disruptive changes should now be targeted against the 8.8.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.0-alpha1 will be released the week of October 14th, 2019, which means new developments and disruptive changes should now be targeted against the 8.9.x-dev branch. (Any changes to 8.9.x will also be committed to 9.0.x in preparation for Drupal 9’s release, but some changes like significant feature additions will be deferred to 9.1.x.). For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.9.x-dev » 9.1.x-dev

Drupal 8.9.0-beta1 was released on March 20, 2020. 8.9.x is the final, long-term support (LTS) minor release of Drupal 8, which means new developments and disruptive changes should now be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 9.1.x-dev » 9.2.x-dev

Drupal 9.1.0-alpha1 will be released the week of October 19, 2020, which means new developments and disruptive changes should now be targeted for the 9.2.x-dev branch. For more information see the Drupal 9 minor version schedule and the Allowed changes during the Drupal 9 release cycle.

Version: 9.2.x-dev » 9.3.x-dev

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

TR’s picture

The patch in #26 did not address the comments in #24 or #27.

Here is a new patch re-rolled against HEAD which fixes all the things pointed out in all the previous comments. This patch also fixes six places that weren't touched by the patch in #26. After this patch there are no more references to drupal_render() in the codebase.

The interdiff is a bit messed up because the line numbers of some of the hunks have changed so much in the past three years that interdiff can't match up the hunks properly. Because the previous patch is so old, I suggest ignoring the interdiff and reviewing this from scratch.

longwave’s picture

Some feedback below.

#2794261: Deprecate render() function in common.inc is tangentially related, if anyone wants to review.

  1. +++ b/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php
    @@ -17,11 +17,12 @@
    + * When controllers call \Drupal::service('renderer')->render()
    

    I think this should just refer to RendererInterface::render().

  2. +++ b/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php
    @@ -36,8 +37,8 @@
    + * \Drupal::service('renderer')->render(), and bubbleable metadata was
    

    Same

  3. +++ b/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php
    @@ -124,8 +125,8 @@ protected function wrapControllerExecutionInRenderContext($controller, array $ar
    +    // \Drupal::service('renderer')->render() outside of a render context, then
    

    Same

  4. +++ b/core/lib/Drupal/Core/Form/FormBuilderInterface.php
    @@ -245,10 +245,11 @@ public function prepareForm($form_id, &$form, FormStateInterface &$form_state);
    +   * \Drupal::service('renderer')->render() (for rendering each element).
    

    And again, because that is where the relevant docs live.

  5. +++ b/core/lib/Drupal/Core/Form/FormBuilderInterface.php
    @@ -269,8 +270,8 @@ public function prepareForm($form_id, &$form, FormStateInterface &$form_state);
    +   * self::doValidateForm() and \Drupal::service('renderer')->render(),
    

    Same.

  6. +++ b/core/lib/Drupal/Core/Menu/MenuLinkTree.php
    @@ -171,7 +171,8 @@ public function build(array $tree) {
           $build['#sorted'] = TRUE;
    

    #sorted is not checked by the renderer itself, should this refer to Element::children()?

  7. +++ b/core/lib/Drupal/Core/Render/Element/Link.php
    @@ -111,9 +111,10 @@ public static function preRenderLink($element) {
    +   * links if \Drupal::service('renderer')->render() is called on it, but
    

    Again I think this should refer to the interface.

  8. +++ b/core/modules/book/src/BookManager.php
    @@ -596,7 +596,8 @@ public function bookTreeOutput(array $tree) {
    +      // Make sure \Drupal::service('renderer')->render() does not re-order the
    

    Same as before, render() does not reorder the links anyway.

  9. +++ b/core/tests/Drupal/KernelTests/Core/Entity/EntityViewBuilderTest.php
    @@ -45,7 +45,8 @@ public function testEntityViewBuilderCache() {
    +    // Force a request via GET so we can get
    +    // \Drupal::service('renderer')->render() cache working.
    

    This could just say "render cache" I think?

  10. +++ b/core/tests/Drupal/KernelTests/Core/Render/Element/RenderElementTypesTest.php
    @@ -182,7 +182,7 @@ public function testMoreLink() {
    +      $this->assertNotEmpty($result, '"' . $element['name'] . '" input rendered correctly by \Drupal::service(\'renderer\')->renderRoot().');
    

    I would just drop "by" and everything after it.

paulocs’s picture

New patch that addresses #35.

gabriel.abdalla’s picture

Status: Needs review » Reviewed & tested by the community
FileSize
11.15 KB
11.17 KB

Hi, patch 2938969-36.patch looks good.

Steps performed:
1. Got code from 9.3.x-dev.
2. Applied 2938969-36.patch.
3. Reviewed all changed files.
4. Checked PHPCS (Drupal and DrupalPractice standards) against all changed files. No issues have been introduced.
5. Tested classes which had changes in assert methods. Tests passed (images attached).

longwave’s picture

Thanks for reviewing, Just to let you know, you don't need to manually check phpcs or run the tests; the bot will do that for you and the box below the patch won't be green if there are coding standards issues or test failures - you also don't need to attach screenshots of the tests passing.

alexpott’s picture

@gabriel.abdalla thank you for looking into this issue.

Posting screenshots of your codebase or command-line interface does not advance the issue, since the automated testing infrastructure tells us whether the change set still applies correctly.

So, I've removed the issue credit for that screenshot. In the future, you can get credit for issues by reading the issue to understand its purpose, and posting your review or testing of that purpose. Thank you!

RTBC'ing a comment changing issue like this one it is quite difficult to meet the standard that would be credited - the review doesn't deal with the most important thing to review which is that no new comments have been introduced using to drupal_render(). The review in #35 is a good example of a comment that will be credited.

alexpott’s picture

Version: 9.3.x-dev » 9.2.x-dev
Status: Reviewed & tested by the community » Fixed

Committed and pushed 84fc7490b1 to 9.3.x and f429dac245 to 9.2.x. Thanks!

As a patch that only changes comments backported to 9.2.x

  • alexpott committed 84fc749 on 9.3.x
    Issue #2938969 by msankhala, dhirendra.mishra, paulocs, TR, MerryHamster...

  • alexpott committed f429dac on 9.2.x
    Issue #2938969 by msankhala, dhirendra.mishra, paulocs, TR, MerryHamster...
alexpott’s picture

We need a follow-up to do the same for references to render() since that function is now deprecated.

longwave’s picture

@alexpott Don't we usually only remove docs references once the deprecated function is actually removed?

alexpott’s picture

@longwave not really. I think documentation should reflect the currently correct way of doing things. Telling people to use deprecated code is a recipe for them having to do future work.

TR’s picture

@alexpott Maybe you can weigh in on #3224178: Remove theme function documentation from theme.api.php then ?

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.