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
When using template_preprocess_status_messages()
to add classes to the class
attribute of the wrapper element of status messages, if using the Classy theme, or a subtheme of Classy that does not implement its own instance of status-messages.html.twig
, the classes appear as content below the messages element (not just as an attribute value in the markup).
Proposed resolution
Patch file attached.
Remaining tasks
Needs community review.
User interface changes
The values of the class
attribute will no longer appear as page content beneath the status messages element.
API changes
None.
Data model changes
None.
Comment | File | Size | Author |
---|---|---|---|
#8 | interdiff.txt | 1.83 KB | danmuzyka |
#8 | classy_theme-status_messages_classes_print_on_page-2752413-8-TESTS_ONLY.patch | 2.05 KB | danmuzyka |
#3 | classy_theme-status_messages_classes_print_on_page-2752413-3.patch | 3.81 KB | danmuzyka |
Comments
Comment #3
danmuzyka CreditAttribution: danmuzyka at Phase2 for Workday, Inc. commentedRe-roll of patch.
Comment #4
ccjjmartin CreditAttribution: ccjjmartin as a volunteer commented@danmuzyka If Classy doesn't define templates it inherits them from the stable theme. In this case, the stable theme does have a status-messages.html.twig file defined. See this file on GitHub:
https://github.com/drupal/drupal/blob/8.2.x/core/themes/stable/templates...
If there is a problem with the classes it should be fixed in the file above (the Stable theme) and it will be fixed in Classy (and other subthemes) without having to add the template file. However, Bartik has a status-messages.html.twig file defined which overwrites the default Stable template. So changes will need to be made there too:
https://github.com/drupal/drupal/blob/8.2.x/core/themes/bartik/templates...
Comment #5
danmuzyka CreditAttribution: danmuzyka at Phase2 for Workday, Inc. commented@ccjjmartin,
This template file is already in the Classy theme:
http://cgit.drupalcode.org/drupal/tree/core/themes/classy/templates/misc...
https://github.com/drupal/drupal/blob/8.2.x/core/themes/classy/templates...
There is an error of logic in this line of that file:
The patch file I provided adds a kernel test for this issue, and replaces that line with the following:
There is nothing in this patch file that introduces a new twig template. The only thing it introduces is a new automated test.
Comment #6
Jeff Burnz CreditAttribution: Jeff Burnz commented@ccjjmartin Bartik calls the parent which comes from Classy, the Classy template overrides the Stable template. Only the Classy template set's attribute classes in this way, so no other template needs changes.
Comment #7
jhedstrom@danmuzyka can you attach just the test changes as a test-only patch to demonstrate the issue/fix?
Are these changes intentional as part of this patch?
Comment #8
danmuzyka CreditAttribution: danmuzyka at Phase2 for Workday, Inc. commented@jhedstrom, yes, the changes in
core/modules/big_pipe/src/Tests/BigPipePlaceholderTestCases.php
are intentional. The change in markup in the twig file causes one less linefeed/newline character to appear in the markup string, so I had to change the expected markup string in this test accordingly.I've attached a tests-only version of the patch.
Comment #10
danmuzyka CreditAttribution: danmuzyka at Phase2 for Workday, Inc. commentedThe TESTS_ONLY patch failed as expected.
Comment #11
jhedstromI love it when nice things happen!
This looks good to go I think.
Comment #12
xjmThanks for working on this! Assigning frontend RTBC issues to Cottser for possible review.
Comment #13
alexpottThis change confuses me because attribute.addClass is adding to the storage but this is not removing... I can't see why this is necessary... removeClass returns $this. Very weird.
Comment #14
alexpottLol I see... we can't just call attributes.removeClass() inside a {% %} and {{ }} is about outputting this into the template.
Comment #15
alexpottI'm torn about whether this should go in 8.1.x - it is removing duplicate new lines from the output and therefore the output is changing - but at least one new line is still there, So it probably okay to do this - especially as this is in service of fixing a quite annoying bug.
Comment #16
alexpottLeaving at rtbc for @Cottser to review
Comment #19
star-szrI concur with @alexpott in #15 fixing this annoying (and kinda embarrassing) bug IMO outweighs any possible minor disruptions.
#3 has been committed and pushed 790c021 to 8.2.x and 1014a70 to 8.1.x. Thanks!