Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Problem/Motivation
All of the dependencies of drupal_process_attached()
are marked as deprecated for Drupal 8.0.0, being worked on here: #2477223: Refactor _drupal_add_html_head, drupal_get_html_head, _drupal_add_html_head_link into the attachments processor, remove from common.inc.
Once we've done all that deprecation, drupal_process_attached()
is left as a no-op function.
Proposed resolution
Deprecate and/or remove drupal_process_attached().
Remaining tasks
- Document API change.
- Create change record.
User interface changes
API changes
Remove drupal_process_attached()
, replaced with the render system which processes attachments in HtmlResponseAttachmentsProcessor
.
Data model changes
Beta phase evaluation
Issue category | Task because we're changing the docblock of a funciton. |
---|---|
Issue priority | Normal. This issue does not have broad impact. |
Disruption | Disruptive because it changes the way you deal with headers and head tags in Drupal. Also quite a few documentation changes will be required to complete the API change. |
Comment | File | Size | Author |
---|---|---|---|
#76 | 2552865_76.patch | 1.77 KB | Mile23 |
Comments
Comment #2
Mile23Comment #3
andypost+1 to remove
Comment #4
Mile23Patch marks
drupal_process_attached()
as deprecated for Drupal 8.0.0.We should remove this function before the 8.0.0 release so that there isn't a wrong way to add attachments.
Comment #5
cilefen CreditAttribution: cilefen commentedWouldn't the right thing be to just remove it?
It hasn't had a deprecation phase, so this is weird.
Comment #6
Mile23That *is* the question, @cilefen. :-)
Comment #7
Mile23Just removing the function won't pass tests until the other deprecations happen, so it's marked as deprecated for 8.0.0 in the patch above.
Comment #8
Crell CreditAttribution: Crell at Palantir.net commented+1 for deprecate and then quickly remove.
Comment #9
Mile23Sure would help if someone would RTBC. :-)
Comment #10
andypostSuppose everyone agree
Comment #11
Mile23Comment #12
Mile23Follow-up issue to do the removal: #2554771: Remove deprecated drupal_process_attached()
Comment #13
cilefen CreditAttribution: cilefen commentedThis seems like a "going through the motions" for nobody's benefit, considering we are almost at RC. It is like saying "we deprecated this a week ago and now you are upset we removed it today?". This reminds me of https://youtu.be/DDYWdABRQIo?t=50s
Comment #14
Mile23OK then. If we're almost at RC then let's prevent that by flipping a switch.
Comment #15
xjmThere are specific criteria for critical issues. See here: https://www.drupal.org/core/issue-priority#critical
This issue does not meet those criteria. Based on my assessment as a release manager, the correct priority for this issue is normal. Thanks!
Comment #16
xjmOh also, if we do decide to deprecate this, it should be deprecated for removal for 9.x instead. The release of beta 1 was the point at which we stopped deprecating things for removal in 8.x.
Comment #17
xjmComment #18
xjmComment #19
Mile23Again: If we deprecate the *other* functions, we will have:
1) A no-op
drupal_process_attached()
.2) ...Which we *must* support until Drupal 9.0.0.
Which is stupid.
Comment #20
xjmDiscussed with @Mile23.
What actually needs to happen here is that the helpers actually need to be deprecated for 9.x at this point (and not removed), since this function was not marked deprecated and there is already D8 contrib code using it.
Comment #21
ianthomas_ukI definitely support the deprecation of drupal_process_attached for removal in 9.x, since it is too late to remove it for 8.x. The documentation needs to be clearer for people who are trying to upgrade their 7.x modules though, just "Specify attached resources and directives in the render array." doesn't really tell a developer new to 8.x what they need to do, so they'll probably end up just leaving the call to drupal_process_attached.
Should the docs be rolled into https://www.drupal.org/node/2169605 which can then be referenced from drupal_process_attached?
Comment #22
Mile23OK, so hang on...
No, we don't. Those other functions *are* marked as deprecated before 8.0.0, and can be deprecated. If contrib is using *those* functions then it's their fault.
Wait for #2477223: Refactor _drupal_add_html_head, drupal_get_html_head, _drupal_add_html_head_link into the attachments processor, remove from common.inc.
Comment #23
Mile23OK, so this patch marks drupal_process_attached() as deprecated before D9. Which really means never, but who's counting?
Added a
@see
tohook_html_head_alter()
, which I bet you didn't know exists, did you? This issue needs a followup documentinghook_html_head_alter()
, which is documented in D7, but not in D8.Comment #24
Mile23Followup: #2555069: Remove invocation of hook_html_head_alter()
Comment #25
Mile23Comment #26
Wim LeersThat'd be very sad, because…
… I don't think it's true that D8 contrib code is using it. If there is such code, I'd bet that it's because they were doing it in D7 and haven't upgraded it since.
We may not have marked
drupal_process_attached()
as deprecated, but that's because it's really an internal API. Since January 21, 2015 (#2368797: Optimize ajaxPageState to keep Drupal 8 sites fast on high-latency networks, prevent CSS/JS aggregation from taking down sites and use HTTP GET for AJAX requests),drupal_process_attached()
already ignores['#attached']['library']
and['#attached']['drupalSettings']
. Since a week ago (#2467759: Refactor drupal_process_attached() so it doesn't depend on drupal_add_http_header()), it also doesn't do anything for['#attached']['http_header']
and once #2477223: Refactor _drupal_add_html_head, drupal_get_html_head, _drupal_add_html_head_link into the attachments processor, remove from common.inc. lands,drupal_process_attached()
will be an empty shell.The reason #2467759 and #2477223 are able to land at this time is because they remove already-deprecated functions. So, effectively,
drupal_process_attached()
has only been calling deprecated functions for a very long time now. We simply forgot to deprecate it also.So, sure, we could keep it around, but it'd literally be a no-op. The only modules in contrib/custom that were calling this in D7 were those that had AJAX responses, which is a tiny fraction. In D8, they'd use
AjaxResponse
, which already handles#attached
for them (also since January 21, 2015, but in a different issue: #2347469: Rendering forms in AjaxResponses does not attach assets automatically).In conclusion: it really makes no sense to keep this. It is indeed very unfortunate that we forgot to deprecate this function. But at the same time, all of the things it calls were already deprecated, and it really was a kind of internal API anyway (as further evidenced by the calls in D7 core).
Comment #27
cilefen CreditAttribution: cilefen commentedThat's what I mean—if it is going to be useless, remove it.
Comment #28
Mile23In IRC the other night xjm mentioned that this was evidence that the other functions (drupal_add_head() or whatever) shouldn't have been deprecated. I disagree, and it sounds like others do, too.
There's also the issue of services. One could swap out render services and contrib's drupal_process_attached() attachments would stop working.
It just doesn't make any sense to keep it.
If some folks could please address this with xjm or other maintainers that'd be great and we can move forward.
Comment #29
Mile23Changing back to 8.0.0, specified more replacement options in the @deprecated block.
Ready for your review.
Comment #30
Mile23Comment #31
Mile23Comment #32
stefan.r CreditAttribution: stefan.r commentedIt's self explanatory but should we put a little example in a @code block here (and in the non-controller options as needed), so we can refer to "attached elements" in the text and '#attached' in the code block?
applicatons
for the
unrelated change
Comment #33
Mile23Thanks!
This patch takes care of all of those issues, and adds some clarifying language.
Comment #34
stefan.r CreditAttribution: stefan.r commentedSeems people want this gone and #26/ #28 points out why it makes little sense to keep this.
This still needs a change record draft. Also should this be postponed on #2477223: Refactor _drupal_add_html_head, drupal_get_html_head, _drupal_add_html_head_link into the attachments processor, remove from common.inc.?
Double space
s/['#attached']/attached/
Comment #35
Mile23Thanks.
We really need an answer here before proceeding with #2477223: Refactor _drupal_add_html_head, drupal_get_html_head, _drupal_add_html_head_link into the attachments processor, remove from common.inc..
Comment #36
stefan.r CreditAttribution: stefan.r commentedSo let's see about getting an answer
Comment #37
andypostComment #39
Wim LeersBot 3128 was broken, it's now taken out of rotation.
Comment #41
Fabianx CreditAttribution: Fabianx for Acquia commentedThere are three ways forward I can see as discussed with catch in IRC:
1. Keep BC and rename current drupal_process_attached to _drupal_process_attached, have the new drupal_process_attached do:
it won't be in global state, but somewhere on the RenderContext at least, so close enough.
2. Deprecate and throw an Exception() to show that this is really not supported anymore (compared to an empty shell), even google_analytics that uses it in a preprocess function could just use $variables['#attached'] instead. I also agree it was meant as internal and not public API, which is shown by the fact that the examples for this function documentation, never mention the function itself. Also leave _drupal_process_attached for internal core usage until its refactored in the other issue.
3. Rename the function to _drupal_process_attached and remove it before 8.0.0 - stating that this simply was an oversight, have a CR to explain the various ways the same can be achieved. As RenderContext's have been added as a suitable replacement that is compatible with Render and SmartCache caching, this should be fine.
All three have in common to rename current drupal_process_attached to _drupal_process_attached, so apparently I feel strongly about that ;).
Comment #42
Fabianx CreditAttribution: Fabianx for Acquia commentedBumping to major
Comment #43
xjmBut that's the thing; contrib code actually is using it.
http://cgit.drupalcode.org/google_analytics/tree/google_analytics.module...
Comment #44
xjmI think #41 needs consideration. Also, if we are considering this, it must have a change record.
If at all possible, an option that provides BC and deprecates for 9.0.0 is preferable (IMO).
Comment #45
Wim Leers#43: Ok. So then going with #41.1 would make sense.
However, note that if we'd remove it, all they'd need to do (and they could already do what is below TODAY):
to:
That's it.
The reason you're able to find such use cases today is because Google Analytics was ported early, and after the initial port was working, they've (AFAIK) been keeping up in the minimal way possible: when it breaks, fix it. Less than 24 hours ago, the
SafeMarkup
fixes broke it: http://cgit.drupalcode.org/google_analytics/commit/?id=1e30fff.So we could keep it, but we'd basically be actively supporting an API that follows D7 thinking, with lots of globals. Also note that it does not work for all types of attachments in HEAD! You cannot attach asset libraries or JS settings with it!. So we'd actively be supporting a broken API… because it was actually deprecated.
See #26.
Comment #46
Wim LeersI think this is something @xjm and @catch need to decide. I very much prefer to remove it because it was
'library'
and'drupalSettings'
aren't supported anymore, precisely because we were working towards removing itBut I also understand the desire to not break BC unless absolutely necessary. So if we keep BC, #41.1 is a good way. But we'll have to literally unset
'library'
and'drupalSettings'
in that BC-compatible solution too, because otherwise we *also* change the behavior…Comment #47
Mile23This issue is about whether to deprecate the function before 8.0.0 release, or before 9.0.0 release.
#2477223: Refactor _drupal_add_html_head, drupal_get_html_head, _drupal_add_html_head_link into the attachments processor, remove from common.inc. is the implementation details based on this decision.
If we deprecate before 8.0.0 then the implementation is ready to go; we just delete stuff and use #attached in render arrays. We're not bound to have any BC for
drupal_process_attached()
.If we deprecate before 9.0.0, then what we're saying is that
drupal_process_attached()
should work as before, for the next five freakin' years. This means we have to have a static which holds the attachments for processing. I admit I'm not clear howRenderContext
works so I can't speak to #41.1.Adding an underscore in front of the function name does three things: 1) Confuses DX. 2) Confuses DX more. 3) Illustrates that Drupal core can't make important API decisions. Thumbs down.
This really is a no-brainer. We're not actually breaking anything, and we're improving everything, with minimal disruption.
The change record already exists: https://www.drupal.org/node/2549159 Linking it to this issue now, because it will be appropriate regardless of outcome here. Leaving the 'needs change record' tag because we'll probably need to update it.
Comment #48
Fabianx CreditAttribution: Fabianx for Acquia commented#47: To be precise, the idea of the underscore is just temporary until we can remove it. It obviously would also have a @deprecated, removed before 8.0.0 info in there, but would ease the transition of #2477223: Refactor _drupal_add_html_head, drupal_get_html_head, _drupal_add_html_head_link into the attachments processor, remove from common.inc..
Comment #49
Mile23#48: Ah, OK. Change the name so it breaks in a small way. That's reasonable.
Comment #50
ianthomas_ukRe #43 and others: If contrib doesn't need it, then we should be able write patches so that they don't use it. Opened #2562721: Remove call to drupal_process_attached() for Google Analytics, but I'm off out now if anyone else fancies tackling it.
Comment #51
andypostLooking at the core usage
the nice bug https://api.drupal.org/api/drupal/core!themes!bartik!color!color.inc/8
https://api.drupal.org/api/drupal/core!themes!bartik!color!color.inc/8
but settings is not supported...
Comment #52
ianthomas_ukI was able to tackle #2562721: Remove call to drupal_process_attached() after all and the patch is trivial. If they are all that easy I don't mind submitting patches for all contrib projects!
Comment #53
Mile23@andypost #51: #2548991: Remove Bartik's erroneous use of drupal_process_attached(), add tests.
Comment #54
Wim Leers@ianthomas_uk++ for #2562721: Remove call to drupal_process_attached()!
@Mile23++ for #2548991: Remove Bartik's erroneous use of drupal_process_attached(), add tests. — note that that is only possible because we have no test coverage for Color module.
Comment #55
hass CreditAttribution: hass commentedThat is the reason why GA has this code and because $varialbes has not worked a few weeks ago. It has nothing to do with keeping up in the minimal way possible.
Comment #56
Mile23Based on the precedent in
Drupal\KernelTests\KernelTestBase::__get()
, and since this is an internal API, we should deprecate it for removal before 8.2.0.If 8.2.0 seems arbitrary, yeah, I'd have to agree, but so does 9.0.0.
Comment #57
hass CreditAttribution: hass commentedThat is very strange. I would remove better now than later e.g. in #2562721: Remove call to drupal_process_attached() i learned that attachments support #weight, but not if drupal_process_attached() is used. That is api inconsistency with render arrays and I guess we do not like to support this.
If this is kept for final we should at least document this important details and point to attachments with $variables.
Comment #58
Fabianx CreditAttribution: Fabianx for Acquia commentedI agree with #57, keeping it is not an option. I even discussed with catch on potentially making this critical as smart cache potentially increases the problematic-ness of the kept static values.
And especially because contrib code can be updated via:
s/drupal_process_attached(/\Drupal::service('renderer')->render(/g
I don't think this is a very disruptive change.
Overall I personally am for the following resolution:
- Rename current drupal_process_attached to _drupal_process_attached and mark it for removal / do-not-use / @internal.
- Add drupal_process_attached with the following content:
- Then remove drupal_process_attached() before cutting the final release tag.
Of course we could also leave that dead code in till 8.1.0 or whatever.
This gives helpful hints to someone still using that, while not holding up the conversion further, the _drupal_process_attached() will then just vanish once the conversion lands.
@xjm: Thoughts?
Comment #59
andypostWhy throw exception? maybe better assert?
Comment #60
stefan.r CreditAttribution: stefan.r commentedAn assert() does make more sense here...
Comment #61
Mile23@hass: If you could add or suggest a test in #2477223: Refactor _drupal_add_html_head, drupal_get_html_head, _drupal_add_html_head_link into the attachments processor, remove from common.inc. that would help us understand what has to happen. Thanks.
Comment #62
hass CreditAttribution: hass commented@Mile23: Added example to https://www.drupal.org/node/2477223#comment-10299985
Comment #63
Mile23OK, so the consensus here is that
drupal_process_attached()
should die a horrible death before 8.0.0.However, maintainer @xjm in #44 says we need to keep it in a way that doesn't break BC and mark it for removal before 9.0.0.
Regardless of which outcome, we have some information about how to work around drupal_process_attached() in #53.
That patch can be easily modified for any decision from a maintainer.
What is needed now is a technical review of the deprecation message. Is it accurate?
Comment #64
Mile23Unable to make
\Drupal::get('render')->renderRoot()
work. Code and tests: https://www.drupal.org/node/2477223#comment-10312407Comment #65
Fabianx CreditAttribution: Fabianx for Acquia commentedTagging revisit-before-release as with smart_cache on this horribly fails for controllers:
#64:
It must literally be:
not renderRoot().
Comment #66
Mile23Thanks to @wimleers it now works: https://www.drupal.org/node/2477223#comment-10315575
This leaves us with a BC for
drupal_process_attached()
, but it should still be removed. :-)Comment #67
Mile23OK, so we have the following:
Backwards-compatibility for
drupal_process_attached()
: https://www.drupal.org/node/2477223#comment-10315575 {#2477223]Removal of all usages of
drupal_process_attached()
, showing that it's not needed (or even wanted): #2564547: Remove calls to drupal_process_attachedTwo change records. A function-specific one: https://www.drupal.org/node/2565285 and one which tells us generally how this all fits together: https://www.drupal.org/node/2549159
And now this patch which explains to people how not to use
drupal_process_attached()
because it's going away before 8.0.0.If someone else thinks it should go away before 9.0.0 (which means: it's never going away), then they can re-work the patch.
Unfollowing this issue.
Comment #68
andypostso 8.0 or 8.2? who's sign needed?
I see no reason to keep it atm
last patch
Comment #69
Mile23Then RTBC.
Comment #70
Wim LeersGiven:
drupal_process_attached()
would mean we'd have to mimic in the BC layer the fact that'library'
and'drupalSettings'
are not supported by it becausedrupal_process_attached()
in HEAD has not supported for more than seven months (and nobody has complained about it either, further indicating very few usages in contrib)#attached
.… I'm marking this RTBC.
It's now up to a framework manager to decide.
Comment #72
Wim LeersTestbot--
Comment #73
xjmThis too; reviewing now.
Comment #74
xjmThanks for the work getting GA updated and on the excellent patch documentation! #57 through #70 etc. are a compelling case to make this BC break now. So I am okay with this following the work that's now been done.
Can we get the change record in https://www.drupal.org/node/2565285 updated to include some of the same information in the deprecation message (or I guess just a link to https://www.drupal.org/node/2549159), and to clarify that it's going to be removed before 8.0.0? NW for that. Should be easy to fix.
Also, it would be better for accessibility and readability to link the change records to each other with meaningful link text, e.g., drupal_process_attached() is deprecated and will be removed before 8.0.0 (but that's non-blocking I guess.
Comment #75
Mile23Comment #76
Mile23Thanks for the review, @xjm.
Updated change notice: https://www.drupal.org/node/2565285 The various change records now link to each other, hopefully in a readable way. :-)
Also, based on #2555069: Remove invocation of hook_html_head_alter() I've changed the deprecation patch here. It looks like
hook_html_head_alter()
is on its way out, in favor ofhook_page_attachments()
, which should be the preferred Drupal Way(tm) to solve the problem.Comment #77
catchinterdiff looks good. RTBC-ing that and tagging so I don't forget.
Comment #79
catchCommitted/pushed to 8.0.x, thanks!
Comment #80
andypost@Mile23 yay!
published CR
Comment #82
xjm