Now that #2073823: [META] Remove drupal_add_js() calls and #2073819: [META] Remove direct calls to drupal_add_css() are completed, we need to stop any new code, core or contrib, from using drupal_add_js/css() directly to add assets.
However, those functions are also used indirectly by core code, such as drupal_render(), and there's not a viable replacement for them yet. As a temporary measure (copying my comment from the other issue):
Add a leading underscore to the function to make it private and update the docs to make it clear no code should call it. That will at least break existing usage to force people to use #attached.
Patch would need to add the leading underscore, convert the remaining uses, and add the extra docs.
Comment | File | Size | Author |
---|---|---|---|
#14 | rename-drupal-add-2168113-14.patch | 69.31 KB | penyaskito |
#13 | rename-drupal-add-2168113-13.patch | 69.42 KB | penyaskito |
#10 | rename-drupal-add-2168113-10.patch | 69.3 KB | jessebeach |
#5 | 2168113-rename_drupal_add.patch | 68.14 KB | penyaskito |
Comments
Comment #1
catchThis is the actual API change, so marking as such.
Comment #2
Wim LeersLovely title :)
Comment #3
webchickThis would also be a simple patch to write, so tagging novice. :)
Comment #4
catchComment #5
penyaskitoLet's do this before more people continue using them.
Added the leading underscore to both functions and usages.
Both were already deprecated and documented the use of #attached.
Comment #7
jessebeach CreditAttribution: jessebeach commentedTests are calling these functions directly, which seems fine for now, no? They'll need underscores. We'll probably eventually want methods on
WebTestBase
to add CSS and JS for tests.call_user_func('drupal_add_css', 'core/themes/stark/css/layout.css', Array)
Comment #8
jessebeach CreditAttribution: jessebeach commentedAh! A little string magic that might have escaped a regex search in
drupal_process_attached
.Comment #9
jessebeach CreditAttribution: jessebeach commentedI found a few more with this regex:
[^_\$]drupal_add_(js|css|')+
Comment #10
jessebeach CreditAttribution: jessebeach commentedGo bot, go.
Comment #11
tstoecklerMinor:
Since this is already being changed, can we add the () ?
Comment #12
tstoecklerActually since #11 is very minor, and I couldn't find anything to complain and it passes tests: marking RTBC.
Comment #13
penyaskitoFixed #11.
Comment #14
penyaskitoThe patch at #13 mangled with file permissions of default.settings.php, sorry.
Comment #16
tstoecklerStill RTBC. ++
Comment #17
webchickAwesome!
This changes stuff in quite a few files, but I just checked manually and it doesn't conflict with any RTBC criticals. (Wasn't able to check the majors, though.)
I was also surprised to see we have absolutely no change notification from any of the previous issues warning that these functions are deprecated (only change notices talking about their new features, which should also be updated accordingly), so let's please get on that as soon as possible so that the message gets heard loud and clear by contrib maintainers and we don't undo the awesome effort that was done here.
Committed and pushed to 8.x. Thanks!
Comment #18
Tim Bozeman CreditAttribution: Tim Bozeman commentedI'm going to write the API change notification!
Comment #19
Tim Bozeman CreditAttribution: Tim Bozeman commentedProposed Change Notice.
Summary
Before
After
Comment #20
webchickHm. While that would work for your average issue needing a change notice, I think for this one we need to be more explicit than that. It should be something more along the lines of:
---
Title: drupal_add_js()/drupal_add_css() should no longer be used
Body: In Drupal 7, drupal_add_js() and drupal_add_css() could be used to add JS and CSS to a page. In Drupal 8, these functions are now private to the internals of the render system and should not be called by modules. Instead, you should use #attached in a render array.
// Code example D7
// Code example D8
---
You can find some examples from the two metas linked in the issue summary.
Comment #21
Tim Bozeman CreditAttribution: Tim Bozeman commentedProposed Change Notice.
drupal_add_js()/drupal_add_css() should no longer be used
Add CSS Code Example D7
Add CSS Code Example D8
Add JS Code Example D7
Add JS Code Example D8
Comment #22
Tim Bozeman CreditAttribution: Tim Bozeman commentedI added the change notice.
Comment #23
Tim Bozeman CreditAttribution: Tim Bozeman commentedComment #24
ianthomas_ukShould this say "must not"? Should and must could be considered technical terms, as they are widely used with RFC 2119 definitions. http://www.ietf.org/rfc/rfc2119.txt
Comment #25
star-szr@ianthomas_uk - agreed, made a couple edits to clarify that.
Comment #26
Wim LeersYay! Now let's get #2171071: Rename drupal_add_library() to _drupal_add_library() and remove its uses in to finish this.