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: drupal_add_js() should allow the specification of custom attributes.
For example,
<?php
drupal_add_js($theme_path . '/path/to/require.js', array(
'type' => 'file',
'scope' => 'footer',
'weight' => 5,
'attributes' => array(
'data-main' => $theme_path . '/path/to/main.js',
),
)
);
?>
should produce:
<script data-main="/path/to/main.js" src="/path/to/require.js"></script>
Solution: Patch core with D8 backport of drupal_add_js(). See #1664602: Allow attributes to be passed to drupal_add_[css|js] (SRI)
Problem: Aurora hijacks drupal_get_js(), but does not respect custom attributes.
Comment | File | Size | Author |
---|---|---|---|
#5 | custom_attributes-1910040-5.patch | 1.91 KB | jmoughon |
#1 | custom_attributes-1910040-2.patch | 1.89 KB | Anonymous (not verified) |
Comments
Comment #1
Anonymous (not verified) CreditAttribution: Anonymous commentedHere is a patch that implements the necessary changes to aurora_get_js_old().
Comment #2
Snugug CreditAttribution: Snugug commentedI'm not sure I understand exactly what you're asking. If you are using the "move js to footer" option in Aurora (and therefore
aurora_get_js_old()
), the code is identical todrupal_get_js
, if not you're using Core'sdrupal_get_js
. Currently,drupal_get_js
does not respect attributes, soaurora_get_js_old()
behaves correctly. If, on the other hand, you'd like us to add this functionality, it won't go intoaurora_get_js_old
but ratheraurora_get_js
as that's where our experimental JS handling goes as that patch hasn't been officially backported yet.If you'd like this in
aurora_get_js_old
and in Core'sdrupal_get_js
, I'd highly encourage you to review the patch and get it committed into Core, then we'll backport it into our implementation. If, however, you'd like to use this inside Aurora right now, before it's gotten officially backported, please reroll this patch againstaurora_get_js
and be aware that you'll need to turn on the experimental JS handling option in order to use this.Comment #3
Anonymous (not verified) CreditAttribution: Anonymous commentedI ran into the issue, because I need that patch to core, but it didn't behave as expected because Aurora implements the original unpatched version. So, I just ported the patch over so that I can pull it into my make file.
Comment #4
Anonymous (not verified) CreditAttribution: Anonymous commentedI'm changing this to a feature request. Because, as you point out, this is not technically a bug :-) Just something I needed.
Comment #5
jmoughon CreditAttribution: jmoughon commentedRerolled patch with a code fix.
Comment #6
iamcarrico CreditAttribution: iamcarrico commentedUntil that piece is actually implemented into core---- we shouldn't add it here too. Once this patch is implemented into core, then we can go ahead and implement it here.
Closing until that is resolved.