Closed (fixed)
Project:
Drupal core
Version:
8.8.x-dev
Component:
render system
Priority:
Normal
Category:
Task
Assigned:
Unassigned
Issue tags:
Reporter:
Created:
14 Oct 2016 at 17:27 UTC
Updated:
12 Sep 2023 at 12:06 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #2
ieguskiza commentedComment #3
dhirendra.mishra commentedUploading a patch.
Comment #4
nickdickinsonwildeMany of those should have the service injected rather than calling \Drupal:Service()
Comment #5
sidharthaphere is the updated patch as per #4.
Thanks @NickWilde
Comment #6
ieguskiza commentedHi,
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 :(
Comment #8
nickdickinsonwilde@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.
Comment #9
sidharthap@ieguskiza: I was not notice you are working on it, my bad!! Please carry on.
Comment #10
amit.drupal commentedUse 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 .
Comment #11
nickdickinsonwilde@amit.drupal: defnitely not in this patch - it is deprecated but will be left until Drupal 9 for backwards compatibility.
Comment #12
ieguskiza commentedAt 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.
Comment #13
xjmReuploading #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!
Comment #14
xjmThanks @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:
The differences between this issue and that one were:
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 ofdrupal_render_root()are already in classes, so there is a single conceptual change.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!
Comment #15
poornima.n commentedComment #16
poornima.n commentedComment #17
sidharthapThanks @poornima,
Can you please provide an interdiff?
Comment #18
amit.drupal commentedPlease 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);
}
Comment #19
poornima.n commented@sidharthap interdiff for (2818677_15.patch) patch
Comment #20
nickdickinsonwilde@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.
Comment #21
nickdickinsonwildeOne note (mostly for xjm or other reviewers):
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)
Comment #23
nickdickinsonwilde:( missed semicolon.
Comment #25
nickdickinsonwildeharrumph I clearly should have tested locally first.
Comment #27
nickdickinsonwildePerhaps I shouldn't have been doing *anything* yesterday... went and didn't include one of the changes after local testing.
Comment #29
nickdickinsonwildephew! that should be all.
Comment #31
nickdickinsonwildeprotip: 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.
Comment #32
nickdickinsonwildeComment #34
dimaro commentedThe latest patch no longer applies against 8.4.x
Rerolled #31
Comment #35
keshavv commentedComment #36
keshavv commentedRerolled again
Comment #37
keshavv commentedComment #39
dimaro commentedI don't know what happened in the last patch, anyway #34 apply correctly against 8.4.x
Comment #41
dimaro commentedI raise the patch again (#34), to prevent the bot from putting this task back in "Need work". I think that needs review.
Comment #44
msankhala commentedThis patch #41 does not apply to 8.6.x.
Comment #45
msankhala commentedComment #46
msankhala commentedHere is a rerolled patch.
Comment #47
mahtab_alam commentedComment #50
msankhala commentedHere is updated patch. Hopefully this time all the tests will pass.
Comment #51
msankhala commentedComment #53
msankhala commentedUpdated patch with fix reported by test bot. Hopefully this time all the tests will pass.
Comment #54
msankhala commentedComment #56
borisson_I have 2 very small nitpicks, but otherwise this is looking great!
Not sure if this makes a lot of sense now.
incorrect version, should be 8.7.x.
Comment #57
msankhala commentedThis patch #53 does not apply anymore on 8.6.x. Needs reroll.
Comment #58
msankhala commented@borisson_ Thanks for the review.
Yes, this still makes sense. The more appropriate version can be Wraps \Drupal\Core\Render\RendererInterface::renderRoot()
Comment #59
msankhala commentedHere is the updated patch.
Comment #60
borisson_Awesome, thanks for fixing my nits.
Comment #62
alexpottThis need to trigger the deprecation. Something like
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()todrupal_render_root()to prove we've replaced all usages.Comment #63
msankhala commentedHere 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
@deprecatedtag.I wonder why
@trigger_error()is not added todrupal_render()function when #2704871: Replace usages of deprecated method drupal_render() got fixed.Comment #65
alexpott@msankhala
because the deprecation policy and support for testing was only implemented during the 8.4.x cycle.
Comment #66
msankhala commentedNow 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?Comment #67
alexpott@msankhala yep or the function is not deprecated.
Comment #68
msankhala commentedHere is updated patch.
Comment #69
msankhala commentedAhh.. Missed the actual patch
Comment #71
msankhala commentedI had a look at the error thrown by test bot. This is the error:
By looking at the stack trace it is clear that issue is with
\Drupal\Core\Render\Renderer::getCurrentRenderContext()where
$this->requestStackis null. I am not sure why requestStack is null.Or the issue is with
\Drupal\Tests\Core\Controller\TestAjaxRendererclass which is extending\Drupal\Core\Render\MainContent\AjaxRendererOr the issue is with the mock being created in
\Drupal\Tests\Core\Controller\AjaxRendererTest::setUp()something likeAny help is appreciated.
Comment #72
alexpott@msankhala we need to mock the renderer so we can test the
\Drupal\Core\Render\MainContent\AjaxRendererclass in isolation.Comment #73
alexpottThis 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.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.
Comment #74
msankhala commentedThanks @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.
Comment #75
msankhala commentedThe patch #73 is not applying anymore needs reroll.
Comment #76
msankhala commentedHere is the rerolled patch.
Comment #77
msankhala commentedNow Patch #76 is no more valid. Patch #73 is valid again because of revert issue #2822382: Make every $modules property protected on classes extending BrowserTestBase and KernelTestBase
See https://cgit.drupalcode.org/drupal/commit/core/modules/filter/tests/src/...
Comment #78
surbz commentedI can confirm patch #73 applies cleanly and remove all the uses of
drupal_render_root()function. After applying this patch i verified with grep.Comment #79
surbz commentedComment #81
msankhala commentedSetting it to rtbc.
Comment #82
alexpottThe rtbc patch need to be the latest on the issue
Comment #83
wim leerss/8.0.x/8.7.x/
Here it is correct.
Comment #84
alexpott@Wim Leers drupal_render_root() has been deprecated for ever.
Comment #85
wim leersD'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. 😅
Comment #86
larowlanThis needs to reference a change record
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)
Comment #87
alexpott@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_DEPRECATIONplus it is good practice to have some test coverage.Comment #88
dhirendra.mishra commentedlooks ok to me.
Comment #89
dhirendra.mishra commentedComment #91
berdir8.0.0, and with the now officially accepted new rules, "drupal:8.0.0"?
maybe use the new approach that checks $renderer, above the assignment and updates that?
we use $this->rendered only in a single place, lets not assign this to $this->renderer?
this one does use it in 3 different methods, but maybe switch to \Drupal::service()?
why are we using a mockBuilder here on the actual class, can't we mock with \Drupal\Core\Render\RendererInterface?
I personally find unit test for constructor deprecations overkill, but if it's already here..
Comment #92
berdirAddressed my review as nobody else seemed very eager to do so :p
Comment #93
berdirFixed a left-over getMock() call.
Comment #95
berdirUpdating the deprecation messages (again) and their tests.
Comment #96
andypostLooks all reviews addressed
Comment #97
catchWhy 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;
Like here.
Comment #98
berdir1. Yeah, no reason, just old code, updated the other one but not this.
Comment #99
andypostback to rtbc!
Comment #100
alexpottCommitted b5238ac and pushed to 8.8.x. Thanks!
Comment #102
alexpottCredited @xjm, @ieguskiza, @borisson_, @catch, @larowlan for issue management and review.
Comment #103
dhirendra.mishra commentedComment #104
catchComment #106
quietone commentedpublish the change record