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
The Drupal.Message.defaultWrapper()
removes class="hidden"
from the fallback div by using wrapper.removeAttribute('class');
which prevents adding classes needed for styling on the wrapper element.
Proposed resolution
Replace wrapper.removeAttribute('class')
with wrapper.classList.remove('hidden')
.
Remaining tasks
User interface changes
API changes
Data model changes
Release notes snippet
Comment | File | Size | Author |
---|---|---|---|
#8 | Screen Shot 2019-12-11 at 16.53.01.png | 195.3 KB | lauriii |
#7 | interdiff_5-7.txt | 692 bytes | zrpnr |
#7 | 3086723-7.patch | 4.86 KB | zrpnr |
#5 | 3086723-5.patch | 4.64 KB | zrpnr |
#3 | 3086723-3.patch | 1.24 KB | zrpnr |
Comments
Comment #3
zrpnrRemoving the entire attribute does seem like overkill when just the hidden class needs to be removed. If markup from
StatusMessages
was overridden to have additional classes those could be removed by this js.It looks like only the
div[data-drupal-messages-fallback]
is affected by this, if Drupal is already printing a status message it would appear in thediv[data-drupal-messages]
which never has the hidden class and which would be selected instead as thedefaultWrapper
.This patch is what @lauriii suggested in the IS, removing just the hidden class instead of the entire class attribute and any other classes that might already be in place.
I came across this issue from the @todo message in Claro
messages.es6.js
- if this lands we should open a follow-up to change that file.Comment #4
lauriiiIt seems like it would be a good idea to solve the Claro issue as part of this given that Claro is now in core. This way we can ensure that the class can bee indeed added and that the @todo comment in Claro can be removed.
The change itself looks good so I'm moving this to NW to address the Claro @todo.
Comment #5
zrpnrThis fallback markup is added in
StatusMessages::generatePlaceholder
. This patch now adds a method toClaroPreRender
which replaces the markup to add.messages-list
to that placeholder div.Without the change in message.es6.js this new class would be removed along with hidden, and now there is no need to override
Drupal.Message.defaultWrapper
in Claro.Comment #6
lauriiiWe should add a comment for this method. Besides that, this looks great!
Comment #7
zrpnrThanks @lauriii ! Added a comment for
messagePlaceholder
Comment #8
lauriiiThank you @zrpnr! 🙏This looks good now! 🚀Tested manually with cd_tools to confirm that there are no regressions.
Comment #9
alexpottIs there test coverage of this in Claro's tests? And is there test coverage anywhere of the hidden class removal?
Comment #10
lauriiiWe don't have test coverage for JavaScript messages in Claro. We could test this but it might open a rabbit hole to testing all kinds of things given that the class is not needed for functionality but for styling. 🤷♂️
We don't have explicit test coverage for checking that the class is added or removed, but the JavaScript messages system is tested by
Drupal\FunctionalJavascriptTests\Core\JsMessageTest
which tests that the system is functional. Failure to remove the hidden class would certainly cause this test to fail.Comment #11
alexpottI think this is more of a task than a feature.
Committed and pushed 09d69a9f13 to 9.0.x and fe8a46eb80 to 8.9.x. Thanks!