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.
To do:
NIL
Done:
- #2095335: Remove drupal_add_css() and drupal_add_js() from the ajax system Assigned to: vijaycs85
- #1969916: Remove drupal_add_js/css from seven.theme
- #2010636: Remove drupal_add_css() and drupal_add_js() from color.module — use #attached Assigned to: Wim Leers
- #732022: drupal_add_tabledrag() still using drupal_add_(js|library)(), should return array for #attached Assigned to: vijaycs85
- #2160603: Remove drupal_add_js() from Bartik
- #2160577: Remove drupal_add_js() + drupal_add_library() from batch.inc
- #2160589: Remove drupal_add_js() from theme.inc
- #2160597: Remove drupal_add_js() from simpletest.theme.inc
- #2160599: Remove drupal_add_js() from system module
- #2160581: Remove drupal_add_js() + drupal_add_library() from install.core.inc
Comments
Comment #1
catchComment #2
Wim LeersNew: #2095335: Remove drupal_add_css() and drupal_add_js() from the ajax system.
Comment #3
nod_tag
Comment #4
hass CreditAttribution: hass commentedI've found an issue in Google Analytics and I have no clue how to solve if
drupal_add_js()
is going to be removed.Are the designers of this idea able to help here, please?
Comment #5
hass CreditAttribution: hass commentedAdding Contributed project blocker as a removed drupal_add_js() will block a Google Analytics release.
Comment #6
xjmComment #7
nod_$variables['#attached']['js']['window.googleanalytics_search_results = ' . intval($pager_total_items[0]) . ';'] = array('type' => 'inline', 'group' => JS_LIBRARY-1);
should be
And that should work. We have to keep a way to do this because that's how
drupalSettings
is added to the page. So I wouldn't worry about this use-case.and if it doesn't, then it means $variables isn't a render array, and #attached is used on a render array so it might be the wrong hook to put that in.
Comment #8
hass CreditAttribution: hass commentedThat is the same like your array...
This is the only workaround-hook where I'm able to grab the required information I need as the required hooks are missing in core. If you like it or not... this will not work as this $variables is not a render array as I know. It looks like core need to add the appropiate search hooks or drupal_add_js() cannot removed.
Comment #9
catchAdding more search hooks is fine, please open an issue for that.
As a workaround in preprocess you can set up an #attached array with the js/css/library and call drupal_render() on it. That doesn't fix the root problem (still relies on global state) but gives us at least a central place to fix things. instead of five.
Comment #10
Wim LeersAs nod_ said in #7, you're using
#attached
incorrectly in #4, so this is not true:Comment #11
hass CreditAttribution: hass commented@nod_: thx. Gave you the credit for 3 other changes at http://drupalcode.org/project/google_analytics.git/commit/1701fa1
@catch: Cannot get it working...
gives me:
Comment #12
catchThat's a normal PHP error. Set up the variable first, then pass it to drupal_render(). Also you don't need to use $variables here can just be its own thing.
Comment #13
nod_Thanks :þ
Attach first, then do adrupal_render will look for andrupal_render($variables)
.#attached
key.(edit) yeah like catch says.
Comment #14
hass CreditAttribution: hass commentedFinally done. http://drupalcode.org/project/google_analytics.git/commit/6798d24 thank you all.
Opened two cases to get rid of this wonky code at all:
Maybe you like to join :-)
Comment #14.0
hass CreditAttribution: hass commentedUpdated issue summary.
Comment #15
xjmComment #16
catchComment #17
joelpittetComment #18
joelpittetComment #19
vijaycs85Comment #20
Wim Leers#732022: drupal_add_tabledrag() still using drupal_add_(js|library)(), should return array for #attached was completed. I created issues for all the remaining ones:
Comment #21
MustangGB CreditAttribution: MustangGB commentedComment #22
Wim LeersThe work that needed to be done in #2160577: Remove drupal_add_js() + drupal_add_library() from batch.inc was done in another issue, so that's already taken care of.
I reviewed all other issues; most have been RTBC'd.
Much thanks to vijaycs85 for tackling most of them!
Comment #23
Wim LeersComment #24
Wim Leersgot committed — yay, almost there :)
Comment #25
Wim Leers#2160581: Remove drupal_add_js() + drupal_add_library() from install.core.inc was also committed just now. That leaves just one: #2160593: Remove drupal_add_js() from menu.module/remove inline JavaScript from menu.module Assigned to: Wim Leers, which is blocked on approval by nod_. Almost there!
Comment #26
webchickI just committed the last of these. :) WOOHOO!!
Now we need to do something to signal to people it's for internal use only. Prefix with an underscore, mark @deprecated?
Comment #27
catchWe're in the same position with drupal_add_css(). There's a bit of discussion on what to do on https://drupal.org/comment/8311981#comment-8311981 downwards.
Might want to open a new issue to do whatever we end up doing to both of these functions, and close these metas as fixed?
Comment #28
Wim Leers#27: that sounds good :)
Comment #29
catchOpened #2168113: Add leading underscore and other discouragement to drupal_add_css() and drupal_add_js() and #2168111: Allow drupal_render() to pass up #attached to parents. Marking this fixed.
Comment #30
vijaycs85Comment #32
webchickHere is some developer feedback from a themer actively trying to use this to add in an external JS library to a theme: #2298551: Documentation updates adding/adjusting inline/external JS in themes Would love suggestions there on how we could've made this not an hours-long task, but still retain the benefits of what these initiatives are trying to do.
Comment #33
corbacho CreditAttribution: corbacho commentedAsking also for best practices here, maybe it's helpful for others.
I'm wondering why this stopped working:
Replacing
drupal_render
fordrupal_process_attached
works, but is the best approach? #2396983: Header Logo with Bartik won't change in settings preview