CommentFileSizeAuthor
#98 2818677-98-interdiff.txt1001 bytesberdir
#98 2818677-98.patch23.93 KBberdir
#95 2818677-95-interdiff.txt5.79 KBberdir
#95 2818677-95.patch23.95 KBberdir
#93 2818677-93-interdiff.txt872 bytesberdir
#93 2818677-93.patch23.81 KBberdir
#92 2818677-92-interdiff.txt5.92 KBberdir
#92 2818677-92.patch23.8 KBberdir
#87 2818677-87.patch23.45 KBalexpott
#87 82-87-interdiff.txt6.64 KBalexpott
#82 2818677-73.patch19.63 KBalexpott
#76 2818677-76.patch19.64 KBmsankhala
#73 2818677-73.patch19.63 KBalexpott
#73 72-73-interdiff.txt1.49 KBalexpott
#72 2818677-72.patch19.74 KBalexpott
#72 68-72-interdiff.txt1.89 KBalexpott
#69 replace-usase-of-drupal_render_root-8.7.x-2818677-68.patch18.67 KBmsankhala
#68 interdiff-63-68.txt1.12 KBmsankhala
#63 interdiff-59-63.txt1.77 KBmsankhala
#63 replace-usase-of-drupal_render_root-8.7.x-2818677-63.patch17.84 KBmsankhala
#59 interdiff-8.7.x-53-59.txt778 bytesmsankhala
#59 replace-usase-of-drupal_render_root-8.7.x-2818677-59.patch16.91 KBmsankhala
#53 interdiff-50-53.txt2.29 KBmsankhala
#53 replace-usase-of-drupal_render_root-2818677-53.patch18.04 KBmsankhala
#50 interdiff-46-50.txt2.27 KBmsankhala
#50 replace-usase-of-drupal_render_root-2818677-50.patch16.63 KBmsankhala
#47 2818677-47.patch14.33 KBmahtab_alam
#46 replace-usage-of-drupal_render_root-2818677-46.patch14.36 KBmsankhala
#41 replace_usages_of-2818677-41.patch15.52 KBdimaro
#36 replace_usages_of-2818677-35.patch15.52 KBkeshavv
#34 replace_usages_of-2818677-34.patch15.52 KBdimaro
#31 replace_drupal_render_root-2818677-31.patch15.53 KBnickdickinsonwilde
#29 replace_drupal_render_root-2818677-29.patch14.32 KBnickdickinsonwilde
#27 replace_drupal_render_root-2818677-27.patch12.87 KBnickdickinsonwilde
#25 replace_drupal_render_root-2818677-25.patch13.77 KBnickdickinsonwilde
#23 replace_drupal_render_root-2818677-23.patch13.7 KBnickdickinsonwilde
#20 replace_drupal_render_root-2818677-20.patch13.72 KBnickdickinsonwilde
#19 interdiff-2818677-13-15.txt454 bytespoornima.n
#15 2818677_15.patch4.83 KBpoornima.n
#13 replace_drupal_render_root-2818677-3.patch4.93 KBxjm
#5 replace_drupal_render_root-2818677-5.patch7.75 KBsidharthap
#3 replace_drupal_render_root-2818677-3.patch4.93 KBdhirendra.mishra

Comments

ieguskiza created an issue. See original summary.

ieguskiza’s picture

Title: Replace usages of deprecated method drupal render() » Replace usages of deprecated method drupal_render_root()
dhirendra.mishra’s picture

Status: Active » Needs review
StatusFileSize
new4.93 KB

Uploading a patch.

nickdickinsonwilde’s picture

Status: Needs review » Needs work

Many of those should have the service injected rather than calling \Drupal:Service()

sidharthap’s picture

Status: Needs work » Needs review
StatusFileSize
new7.75 KB

here is the updated patch as per #4.
Thanks @NickWilde

ieguskiza’s picture

Hi,
actually when I created the ticket I did it based on this ticket and comment:

https://www.drupal.org/node/2704871#comment-11209689

So basically the scope of the ticket is to simply replace the deprecated method. Service injection would be done in a separate follow up ticket then under [meta] Replace \Drupal with injected services where appropriate in core

Anyhow, I guess since the patch is not too big we can roll with it and do the injection directly.

On another note, it would be nice if you could assign the ticket to yourselves or ask the current assignee before starting working in a ticket. It is a bit disheartening to assign a ticket to yourself, try to work on it only for somebody else come and push a solution for it without notice :(

Status: Needs review » Needs work

The last submitted patch, 5: replace_drupal_render_root-2818677-5.patch, failed testing.

nickdickinsonwilde’s picture

@ieguskiza: ah yes I see that, didn't notice that before. Can't say it makes sense to me but I won't argue with @AlexPott without pretty good reason - generally I'd assume he knows better than me.

sidharthap’s picture

@ieguskiza: I was not notice you are working on it, my bad!! Please carry on.

amit.drupal’s picture

Use Patch #3
If drupal_render_root() replace with \Drupal::service('renderer')->renderRoot(); than remove
-
function drupal_render_root(&$elements) {
return \Drupal::service('renderer')->renderRoot($elements);
}
in common.inc file .

nickdickinsonwilde’s picture

@amit.drupal: defnitely not in this patch - it is deprecated but will be left until Drupal 9 for backwards compatibility.

ieguskiza’s picture

Status: Needs work » Reviewed & tested by the community

At this point I'm keen on moving this to RTBC so that the patch in #3 gets reviewed by the higher ups. If we need to provide dependency injection with it we can work on the patch in #5.

xjm’s picture

StatusFileSize
new4.93 KB

Reuploading #3 -- if the final patch on the issue is not the correct patch, it causes problems for our testing infrastructure and also confuses people. Thanks!

xjm’s picture

Component: node system » render system
Status: Reviewed & tested by the community » Needs work

Thanks @ieguskiza and @NickWilde for being thoughtful about the issue's scope here.

@alexpott and I discussed his feedback in #2704871-20: Replace usages of deprecated method drupal_render() as compared to this issue. For both these functions, we have two overlapping goals:

  1. Remove the use of code that is already deprecated so that core is correct.
  2. Remove uses of globals from classes for better decoupling, unit testing, etc.

The differences between this issue and that one were:

  1. The reason he asked for the issue to be rescoped is that it was originally only scoped to the node module, which is incorrect for the reasons described in https://www.drupal.org/core/scope#files. In this issue, we're already correctly updating all of core -- good work. :)
  2. drupal_render() is used in everything from global includes, to procedural module code, to tests and properly decoupled OO code. That means that the different uses will eventually need different patterns of fix -- so it makes sense to make the most straightforward change first for reviewability and then go from there. However, for this issue, all uses of drupal_render_root() are already in classes, so there is a single conceptual change.
  3. There are over 100 uses of drupal_render() to be updated. In contrast, drupal_render_root() only has seven plus a documentation reference.

It's not that it's wrong to simply replace all the usages with Drupal::service() -- that does make it better, because it solves the first problem of having deprecated code usages. It is still a partial fix, though, and when every single usage will need to be changed again in another way in another issue, and there are fewer than 10 of them, it also doesn't save us too much to do it in two steps.

So let's go ahead and continue with injecting the service.

Thanks everyone!

poornima.n’s picture

StatusFileSize
new4.83 KB
poornima.n’s picture

Status: Needs work » Needs review
sidharthap’s picture

Status: Needs review » Needs work

Thanks @poornima,
Can you please provide an interdiff?

amit.drupal’s picture

Please suggest :

If drupal_render_root() replace with \Drupal::service('renderer')->renderRoot();

than remove function in " core/lib/Drupal/Core/Render/MainContent/AjaxRenderer.php " path

protected function drupalRenderRoot(&$elements) {
return drupal_render_root($elements);
}

poornima.n’s picture

StatusFileSize
new454 bytes

@sidharthap interdiff for (2818677_15.patch) patch

nickdickinsonwilde’s picture

Status: Needs work » Needs review
StatusFileSize
new13.72 KB

@amit.drupal: adjusted the message/added deprecated notice. Not removing so as to maintain BC. Thanks :)

New patch attached. Fully injects the service via the relevant method (container->get or service call) per class.

nickdickinsonwilde’s picture

One note (mostly for xjm or other reviewers):

+++ b/core/modules/rest/src/Tests/Views/StyleSerializerTest.php
@@ -682,8 +690,6 @@ public function testFieldapiField() {
   public function testGroupRows() {
-    /** @var \Drupal\Core\Render\RendererInterface $renderer */
-    $renderer = $this->container->get('renderer');
     $this->drupalCreateContentType(['type' => 'page']);
     // Create a text field with cardinality set to unlimited.
     $field_name = 'field_group_rows';
@@ -726,7 +732,7 @@ public function testGroupRows() {

@@ -726,7 +732,7 @@ public function testGroupRows() {
     // Check if the field_group_rows field is grouped.
     $expected = [];
     $expected[] = [$field_name => implode(', ', $grouped_field_values)];
-    $this->assertEqual($serializer->serialize($expected, 'json'), (string) $renderer->renderRoot($build));
+    $this->assertEqual($serializer->serialize($expected, 'json'), (string) $this->renderer->renderRoot($build));

This could be done in a separate issue but since it was quite minor it seemed to me that it should just be done now/while that file is being edited. (Couple other instances of the equivalent change as well)

Status: Needs review » Needs work

The last submitted patch, 20: replace_drupal_render_root-2818677-20.patch, failed testing.

nickdickinsonwilde’s picture

Status: Needs work » Needs review
StatusFileSize
new13.7 KB

:( missed semicolon.

Status: Needs review » Needs work

The last submitted patch, 23: replace_drupal_render_root-2818677-23.patch, failed testing.

nickdickinsonwilde’s picture

Status: Needs work » Needs review
StatusFileSize
new13.77 KB

harrumph I clearly should have tested locally first.

Status: Needs review » Needs work

The last submitted patch, 25: replace_drupal_render_root-2818677-25.patch, failed testing.

nickdickinsonwilde’s picture

Status: Needs work » Needs review
StatusFileSize
new12.87 KB

Perhaps I shouldn't have been doing *anything* yesterday... went and didn't include one of the changes after local testing.

Status: Needs review » Needs work

The last submitted patch, 27: replace_drupal_render_root-2818677-27.patch, failed testing.

nickdickinsonwilde’s picture

Status: Needs work » Needs review
StatusFileSize
new14.32 KB

phew! that should be all.

Status: Needs review » Needs work

The last submitted patch, 29: replace_drupal_render_root-2818677-29.patch, failed testing.

nickdickinsonwilde’s picture

StatusFileSize
new15.53 KB

protip: Run *all* tests locally not just the classes you think need to be run to avoid issue spam and embarrassment.
confession: I didn't do that.

nickdickinsonwilde’s picture

Status: Needs work » Needs review

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.0-alpha1 will be released the week of January 30, 2017, which means new developments and disruptive changes should now be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

dimaro’s picture

StatusFileSize
new15.52 KB

The latest patch no longer applies against 8.4.x
Rerolled #31

keshavv’s picture

Status: Needs review » Needs work
keshavv’s picture

Issue summary: View changes
StatusFileSize
new15.52 KB

Rerolled again

keshavv’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, 36: replace_usages_of-2818677-35.patch, failed testing.

dimaro’s picture

Status: Needs work » Needs review

I don't know what happened in the last patch, anyway #34 apply correctly against 8.4.x

Status: Needs review » Needs work

The last submitted patch, 36: replace_usages_of-2818677-35.patch, failed testing.

dimaro’s picture

Status: Needs work » Needs review
StatusFileSize
new15.52 KB

I raise the patch again (#34), to prevent the bot from putting this task back in "Need work". I think that needs review.

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.0-alpha1 will be released the week of July 31, 2017, which means new developments and disruptive changes should now be targeted against the 8.5.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.5.x-dev » 8.6.x-dev

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

msankhala’s picture

Issue tags: +Needs reroll

This patch #41 does not apply to 8.6.x.

msankhala’s picture

Status: Needs review » Needs work
msankhala’s picture

Status: Needs work » Needs review
Issue tags: -Needs reroll
StatusFileSize
new14.36 KB

Here is a rerolled patch.

mahtab_alam’s picture

StatusFileSize
new14.33 KB

The last submitted patch, 46: replace-usage-of-drupal_render_root-2818677-46.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

Status: Needs review » Needs work

The last submitted patch, 47: 2818677-47.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

msankhala’s picture

StatusFileSize
new16.63 KB
new2.27 KB

Here is updated patch. Hopefully this time all the tests will pass.

msankhala’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, 50: replace-usase-of-drupal_render_root-2818677-50.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

msankhala’s picture

StatusFileSize
new18.04 KB
new2.29 KB

Updated patch with fix reported by test bot. Hopefully this time all the tests will pass.

msankhala’s picture

Status: Needs work » Needs review

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.

borisson_’s picture

Status: Needs review » Needs work

I have 2 very small nitpicks, but otherwise this is looking great!

  1. +++ b/core/lib/Drupal/Core/Render/MainContent/AjaxRenderer.php
    @@ -75,12 +86,13 @@ public function renderResponse(array $main_content, Request $request, RouteMatch
    -   * Wraps drupal_render_root().
    +   * Wraps renderRoot().
    

    Not sure if this makes a lot of sense now.

  2. +++ b/core/lib/Drupal/Core/Render/MainContent/AjaxRenderer.php
    @@ -75,12 +86,13 @@ public function renderResponse(array $main_content, Request $request, RouteMatch
    +   * @deprecated as of Drupal 8.3.x, will be removed before Drupal 9.0.0. Use
    

    incorrect version, should be 8.7.x.

msankhala’s picture

Issue tags: +Needs reroll

This patch #53 does not apply anymore on 8.6.x. Needs reroll.

msankhala’s picture

@borisson_ Thanks for the review.

Not sure if this makes a lot of sense now.

Yes, this still makes sense. The more appropriate version can be Wraps \Drupal\Core\Render\RendererInterface::renderRoot()

msankhala’s picture

Status: Needs work » Needs review
Issue tags: -Needs reroll
StatusFileSize
new16.91 KB
new778 bytes

Here is the updated patch.

borisson_’s picture

Status: Needs review » Reviewed & tested by the community

Awesome, thanks for fixing my nits.

alexpott’s picture

Status: Reviewed & tested by the community » Needs work
+++ b/core/lib/Drupal/Core/Render/MainContent/AjaxRenderer.php
@@ -75,12 +86,13 @@ public function renderResponse(array $main_content, Request $request, RouteMatch
   /**
-   * Wraps drupal_render_root().
+   * Wraps \Drupal\Core\Render\RendererInterface::renderRoot().
    *
-   * @todo Remove as part of https://www.drupal.org/node/2182149.
+   * @deprecated as of Drupal 8.7.x, will be removed before Drupal 9.0.0. Use
+   *   $this->renderer or the 'renderer' service instead.
    */
   protected function drupalRenderRoot(&$elements) {
-    return drupal_render_root($elements);
+    return $this->renderer->renderRoot($elements);
   }

This need to trigger the deprecation. Something like

@trigger_error('\Drupal\Core\Render\MainContent\AjaxRenderer::drupalRenderRoot() is deprecated as of Drupal 8.7.x, will be removed before Drupal 9.0.0. Use $this->renderer or the 'renderer' service instead. See https://www.drupal.org/node/NID', E_USER_DEPRECATED);

Where NID is the change record that tells people about this. An @see needs to be added too. See https://www.drupal.org/core/deprecation

We also need to add the same @trigger_error() to drupal_render_root() to prove we've replaced all usages.

msankhala’s picture

Status: Needs work » Needs review
StatusFileSize
new17.84 KB
new1.77 KB

Here is the updated patch.

* @deprecated \Drupal\Core\Render\MainContent\AjaxRenderer::drupalRenderRoot()

In the above line, the line length is exceeding 80 characters. @alexpott I am not sure if the line length is allowed to exceed 80 characters if FQN of a method is too long in the @deprecated tag.

I wonder why @trigger_error() is not added to drupal_render() function when #2704871: Replace usages of deprecated method drupal_render() got fixed.

Status: Needs review » Needs work
alexpott’s picture

@msankhala

I wonder why @trigger_error() is not added to drupal_render() function when...

because the deprecation policy and support for testing was only implemented during the 8.4.x cycle.

msankhala’s picture

Now this @trigger_error() added in \Drupal\Core\Render\MainContent\AjaxRenderer::drupalRenderRoot() is making the test fail. Should uses of \Drupal\Core\Render\MainContent\AjaxRenderer::drupalRenderRoot() in all test cases be replaced with rendere service?

alexpott’s picture

@msankhala yep or the function is not deprecated.

msankhala’s picture

Status: Needs work » Needs review
StatusFileSize
new1.12 KB

Here is updated patch.

msankhala’s picture

StatusFileSize
new18.67 KB

Ahh.. Missed the actual patch

Status: Needs review » Needs work
msankhala’s picture

I had a look at the error thrown by test bot. This is the error:

Drupal\Tests\Core\Controller\AjaxRendererTest
exception: [Other] Line 0 of sites/default/files/simpletest/phpunit-22.xml:
PHPunit Test failed to complete; Error: PHPUnit 6.5.10 by Sebastian Bergmann and contributors.

Testing Drupal\Tests\Core\Controller\AjaxRendererTest
E                                                                   1 / 1 (100%)

Time: 206 ms, Memory: 4.00MB

There was 1 error:

1) Drupal\Tests\Core\Controller\AjaxRendererTest::testRenderWithFragmentObject
Error: Call to a member function getCurrentRequest() on null

/var/www/html/core/lib/Drupal/Core/Render/Renderer.php:601
/var/www/html/core/lib/Drupal/Core/Render/Renderer.php:578
/var/www/html/core/lib/Drupal/Core/Render/Renderer.php:140
/var/www/html/core/lib/Drupal/Core/Render/MainContent/AjaxRenderer.php:73
/var/www/html/core/tests/Drupal/Tests/Core/Controller/AjaxRendererTest.php:65

By looking at the stack trace it is clear that issue is with \Drupal\Core\Render\Renderer::getCurrentRenderContext()

  protected function getCurrentRenderContext() {
    $request = $this->requestStack->getCurrentRequest();
    return isset(static::$contextCollection[$request]) ? static::$contextCollection[$request] : NULL;
  }

where $this->requestStack is null. I am not sure why requestStack is null.

Or the issue is with \Drupal\Tests\Core\Controller\TestAjaxRenderer class which is extending \Drupal\Core\Render\MainContent\AjaxRenderer
Or the issue is with the mock being created in \Drupal\Tests\Core\Controller\AjaxRendererTest::setUp() something like

$renderer = $this->getMockBuilder('Drupal\Core\Render\Renderer')
      ->disableOriginalConstructor()
      ->setMethods(NULL)
      ->getMock();

Any help is appreciated.

alexpott’s picture

Status: Needs work » Needs review
StatusFileSize
new1.89 KB
new19.74 KB

@msankhala we need to mock the renderer so we can test the \Drupal\Core\Render\MainContent\AjaxRenderer class in isolation.

alexpott’s picture

StatusFileSize
new1.49 KB
new19.63 KB
  1. +++ b/core/lib/Drupal/Core/Render/MainContent/AjaxRenderer.php
    @@ -75,12 +86,17 @@ public function renderResponse(array $main_content, Request $request, RouteMatch
    +   * is deprecated as of Drupal 8.7.x, will be removed before Drupal 9.0.0. Use
    +   * $this->renderer or the 'renderer' service instead.
    

    This deprecation message doesn't need to say or the 'renderer' service - any class that extends this one and calls this method should use $this->renderer. Fix in attached patch.

  2. +++ b/core/tests/Drupal/Tests/Core/Controller/AjaxRendererTest.php
    @@ -1,16 +1,11 @@
    -/**
    - * @file
    - * Contains \Drupal\Tests\Core\Controller\AjaxRendererTest.
    - */
    -
    

    This is removed here because the PHPCS sniff that tests for these not being there doesn't work on files with more that one class. This file now only has a single class so fails PHPCS without this change.

msankhala’s picture

Thanks @alexpott for the explanation and patch. I learned many things while working on this issue like deprecation policy and support, use of @trigger_error() in the context of deprecation, PHPCS rule for file docblock and mocking a service.

msankhala’s picture

Status: Needs review » Needs work
Issue tags: +Needs reroll

The patch #73 is not applying anymore needs reroll.

git apply -v 2818677-73.patch
Checking patch core/core.services.yml...
Checking patch core/includes/common.inc...
Checking patch core/lib/Drupal/Core/Render/MainContent/AjaxRenderer.php...
Checking patch core/lib/Drupal/Core/Render/MainContent/DialogRenderer.php...
Checking patch core/lib/Drupal/Core/Render/MainContent/ModalRenderer.php...
Checking patch core/lib/Drupal/Core/Render/MainContent/OffCanvasRenderer.php...
Checking patch core/modules/filter/tests/src/Kernel/FilterAPITest.php...
error: while searching for:

  public static $modules = ['system', 'filter', 'filter_test', 'user'];

  protected function setUp() {
    parent::setUp();

    $this->installConfig(['system', 'filter', 'filter_test']);
  }

  /**

error: patch failed: core/modules/filter/tests/src/Kernel/FilterAPITest.php:21
error: core/modules/filter/tests/src/Kernel/FilterAPITest.php: patch does not apply
Checking patch core/modules/rest/tests/src/Functional/Views/StyleSerializerTest.php...
Checking patch core/modules/system/tests/modules/dialog_renderer_test/dialog_renderer_test.services.yml...
Checking patch core/modules/system/tests/modules/dialog_renderer_test/src/Render/MainContent/WideModalRenderer.php...
Checking patch core/modules/views/src/Plugin/views/display/Feed.php...
Checking patch core/tests/Drupal/Tests/Core/Controller/AjaxRendererTest.php...
msankhala’s picture

Status: Needs work » Needs review
Issue tags: -Needs reroll
StatusFileSize
new19.64 KB

Here is the rerolled patch.

msankhala’s picture

surbz’s picture

I can confirm patch #73 applies cleanly and remove all the uses of drupal_render_root() function. After applying this patch i verified with grep.

grep -rn "drupal_render_root" core
core/includes/common.inc:867:function drupal_render_root(&$elements) {
core/includes/common.inc:868:  @trigger_error('drupal_render_root() is deprecated in Drupal 8.0.x and will be removed before Drupal 9.0.0. Use the "renderer" service instead.');
surbz’s picture

Status: Needs review » Reviewed & tested by the community

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 76: 2818677-76.patch, failed testing. View results

msankhala’s picture

Status: Needs work » Reviewed & tested by the community

Setting it to rtbc.

alexpott’s picture

StatusFileSize
new19.63 KB

The rtbc patch need to be the latest on the issue

wim leers’s picture

Status: Reviewed & tested by the community » Needs work
Issue tags: +@deprecated
  1. +++ b/core/includes/common.inc
    @@ -865,6 +865,7 @@ function drupal_pre_render_links($element) {
    +  @trigger_error('drupal_render_root() is deprecated in Drupal 8.0.x and will be removed before Drupal 9.0.0. Use the "renderer" service instead.');
    

    s/8.0.x/8.7.x/

  2. +++ b/core/lib/Drupal/Core/Render/MainContent/AjaxRenderer.php
    @@ -75,12 +86,16 @@ public function renderResponse(array $main_content, Request $request, RouteMatch
    +   * @deprecated in Drupal 8.7.x and will be removed before Drupal 9.0.0. Use
    

    Here it is correct.

alexpott’s picture

Status: Needs work » Reviewed & tested by the community

@Wim Leers drupal_render_root() has been deprecated for ever.

/**
 * Renders final HTML given a structured array tree.
 *
 * @deprecated as of Drupal 8.0.x, will be removed before Drupal 9.0.0. Use the
 *   'renderer' service instead.
 *
 * @see \Drupal\Core\Render\RendererInterface::renderRoot()
 * @see https://www.drupal.org/node/2912696
 */
function drupal_render_root(&$elements) {
  return \Drupal::service('renderer')->renderRoot($elements);
}
wim leers’s picture

D'oh, right. I was blinded by the fact that we're adding that trigger_error() now. But of course, we simply weren't adding that back in the 8.0 days!

Sorry for the distraction. 😅

larowlan’s picture

Status: Reviewed & tested by the community » Needs review
  1. +++ b/core/includes/common.inc
    @@ -865,6 +865,7 @@ function drupal_pre_render_links($element) {
    +  @trigger_error('drupal_render_root() is deprecated in Drupal 8.0.x and will be removed before Drupal 9.0.0. Use the "renderer" service instead.');
    

    This needs to reference a change record

  2. +++ b/core/lib/Drupal/Core/Render/MainContent/AjaxRenderer.php
    @@ -29,14 +30,24 @@ class AjaxRenderer implements MainContentRendererInterface {
    +    $this->renderer = $renderer;
    

    i have quite a few classes in client projects that extend these renderers, we need a change record for this (Even though its allowed under our BC policy)

alexpott’s picture

StatusFileSize
new6.64 KB
new23.45 KB

@larowlan made the deprecation slightly easier on projects that extend the renderers by doing a proper parameter add using the deprecation system :)

I've also added test coverage since the added deprecation forgot to add E_USER_DEPRECATION plus it is good practice to have some test coverage.

dhirendra.mishra’s picture

looks ok to me.

dhirendra.mishra’s picture

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.

berdir’s picture

Status: Needs review » Needs work
  1. +++ b/core/includes/common.inc
    @@ -867,6 +867,7 @@ function drupal_pre_render_links($element) {
     function drupal_render_root(&$elements) {
    +  @trigger_error('drupal_render_root() is deprecated in Drupal 8.0.x and will be removed before Drupal 9.0.0. Use the "renderer" service instead. See https://www.drupal.org/node/2912696.', E_USER_DEPRECATED);
    

    8.0.0, and with the now officially accepted new rules, "drupal:8.0.0"?

  2. +++ b/core/lib/Drupal/Core/Render/MainContent/DialogRenderer.php
    @@ -21,14 +22,28 @@ class DialogRenderer implements MainContentRendererInterface {
    +  public function __construct(TitleResolverInterface $title_resolver, RendererInterface $renderer = NULL) {
         $this->titleResolver = $title_resolver;
    +    $this->renderer = $renderer;
    +    if ($this->renderer === NULL) {
    +      @trigger_error('The $renderer parameter is added in Drupal 8.7.0 and will be required before Drupal 9.0.0. See https://www.drupal.org/node/3009400.', E_USER_DEPRECATED);
    +      $this->renderer = \Drupal::service('renderer');
    +    }
    

    maybe use the new approach that checks $renderer, above the assignment and updates that?

  3. +++ b/core/modules/filter/tests/src/Kernel/FilterAPITest.php
    @@ -291,7 +299,7 @@ public function testProcessedTextElement() {
           '#format' => 'element_test',
         ];
    -    drupal_render_root($build);
    +    $this->renderer->renderRoot($build);
     
    

    we use $this->rendered only in a single place, lets not assign this to $this->renderer?

  4. +++ b/core/modules/rest/tests/src/Functional/Views/StyleSerializerTest.php
    @@ -63,6 +70,7 @@ protected function setUp($import_test_views = TRUE) {
     
         $this->enableViewsTestModule();
    +    $this->renderer = $this->container->get('renderer');
       }
    

    this one does use it in 3 different methods, but maybe switch to \Drupal::service()?

  5. +++ b/core/tests/Drupal/Tests/Core/Controller/AjaxRendererTest.php
    @@ -45,15 +42,25 @@ protected function setUp() {
           ]);
    -    $this->ajaxRenderer = new TestAjaxRenderer($element_info_manager);
    -
    -    $this->renderer = $this->getMockBuilder('Drupal\Core\Render\Renderer')
    +    $renderer = $this->getMockBuilder(Renderer::class)
           ->disableOriginalConstructor()
    -      ->setMethods(NULL)
           ->getMock();
    

    why are we using a mockBuilder here on the actual class, can't we mock with \Drupal\Core\Render\RendererInterface?

  6. +++ b/core/tests/Drupal/Tests/Core/Controller/AjaxRendererTest.php
    @@ -78,24 +85,19 @@ public function testRenderWithFragmentObject() {
    +  public function testConstructorRendererArgument() {
    +    $element_info_manager = $this->getMock(ElementInfoManagerInterface::class);
    +    $container = $this->createMock(ContainerInterface::class);
    +    $container->expects($this->once())
    +      ->method('get')
    +      ->with('renderer')
    +      ->willReturn(NULL);
    +    \Drupal::setContainer($container);
    +    new AjaxRenderer($element_info_manager);
       }
    

    I personally find unit test for constructor deprecations overkill, but if it's already here..

berdir’s picture

Status: Needs work » Needs review
StatusFileSize
new23.8 KB
new5.92 KB

Addressed my review as nobody else seemed very eager to do so :p

berdir’s picture

StatusFileSize
new23.81 KB
new872 bytes

Fixed a left-over getMock() call.

Status: Needs review » Needs work

The last submitted patch, 93: 2818677-93.patch, failed testing. View results

berdir’s picture

Status: Needs work » Needs review
StatusFileSize
new23.95 KB
new5.79 KB

Updating the deprecation messages (again) and their tests.

andypost’s picture

Status: Needs review » Reviewed & tested by the community

Looks all reviews addressed

catch’s picture

Status: Reviewed & tested by the community » Needs work
  1. +++ b/core/lib/Drupal/Core/Render/MainContent/AjaxRenderer.php
    @@ -22,14 +23,28 @@ class AjaxRenderer implements MainContentRendererInterface {
         $this->elementInfoManager = $element_info_manager;
    +    $this->renderer = $renderer;
    +    if ($this->renderer === NULL) {
    

    Why not do the same as we do here (and elsewhere in core), the slightly different logic meant I had to reread this a couple of times to see why it was special;

  2. +++ b/core/lib/Drupal/Core/Render/MainContent/DialogRenderer.php
    @@ -21,14 +22,28 @@ class DialogRenderer implements MainContentRendererInterface {
         $this->titleResolver = $title_resolver;
    +    if ($renderer === NULL) {
    +      @trigger_error('The renderer service must be passed to ' . __METHOD__ . ' and will be required before Drupal 9.0.0. See https://www.drupal.org/node/3009400', E_USER_DEPRECATED);
    +      $renderer = \Drupal::service('renderer');
    +    }
    

    Like here.

berdir’s picture

Status: Needs work » Needs review
StatusFileSize
new23.93 KB
new1001 bytes

1. Yeah, no reason, just old code, updated the other one but not this.

andypost’s picture

Status: Needs review » Reviewed & tested by the community

back to rtbc!

alexpott’s picture

Status: Reviewed & tested by the community » Fixed

Committed b5238ac and pushed to 8.8.x. Thanks!

  • alexpott committed b5238ac on 8.8.x
    Issue #2818677 by msankhala, NickWilde, Berdir, alexpott, dimaro,...
alexpott’s picture

Credited @xjm, @ieguskiza, @borisson_, @catch, @larowlan for issue management and review.

dhirendra.mishra’s picture

catch’s picture

Status: Fixed » Closed (fixed)

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

quietone’s picture

publish the change record