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.
I'm not sure if this is a bug on the module's part but there is a work around. The issue is that the Javascript being added via the hook_page_attachments_alter is being truncated/escaped. I've managed to fix this myself by adding code of the form
use Drupal\Core\Render\Markup;
...
$attachments['#attached']['html_head'][$i] = [
[
'#type' => 'html_tag',
'#tag' => $script_tag,
'#value' => Markup::create($value),
],
'header-and-footer-scripts-' . $i,
];
And that appears to allow the script to pass through and function. There appears to be a support request in the Issue queue for D8 core that I believe is related to this problem.
Comments
Comment #2
akbuje CreditAttribution: akbuje as a volunteer commentedI found your fix useful in my usecase @edvard.radau, thank you.
This case seems to duplicate two other issues though, which I have updated the case to include.
Comment #3
akbuje CreditAttribution: akbuje as a volunteer commentedSince I am using the change edward.radau has made, I have made his change into a patch to be reviewed for later use, if others find it useful.
Comment #4
akbuje CreditAttribution: akbuje as a volunteer commentedComment #5
dhanlal CreditAttribution: dhanlal at Valuebound commentedthis patch not tested that why i update the this issue
Comment #6
dhanlal CreditAttribution: dhanlal at Valuebound commentedneed review
Comment #7
dhanlal CreditAttribution: dhanlal at Valuebound commentedComment #8
dhanlal CreditAttribution: dhanlal at Valuebound commentedComment #9
gislePatch in #6 by dhanlal in #6 is identical to the one submitted by akbuje in #3.
Plagiarism is just as bad as spam. Please take into account when assigning credit.
Comment #10
Jesmaster CreditAttribution: Jesmaster commentedThe original patch missed a few spots, here's an updated version.
Comment #11
Nitesh Sethia CreditAttribution: Nitesh Sethia as a volunteer and at Syngenta commentedUpdated the patch as per the different comments and the coding standards.
Comment #12
sasiddiqui CreditAttribution: sasiddiqui commentedThis issue was fixed in v3.0.0.
Comment #13
sasiddiqui CreditAttribution: sasiddiqui commentedComment #14
sasiddiqui CreditAttribution: sasiddiqui commented