If there is more than one message, theme_status_message() returns the message items as an unordered list. However, with single messages, it returns the message naked without any container what so ever.
This creates problems for anyone who is attempting to style more elegant status messages. If you decide to use background images as icons for the messages (like an Alert box in MacOS ), you'd want to use padding to position the icon. Using CSS, this is very easy to do for the messages that are returned within a UL(because you can select the UL to position the text, and style it as needed), but it becomes troublesome for the containerless single message.
Though, I've been able to work around this by changing text-alignments for UL's vs the DIV, and zeroing out the list's margins -- it just seems silly.
All styling difficulties can be avoided entirely by surrounding single messages in paragraph tags. The paragraph tags also make the markup semantically correct (IMHO). Here's a tested one line patch that resolves the issue.
| Comment | File | Size | Author |
|---|---|---|---|
| theme_status.patch | 356 bytes | Nick Lewis |
Comments
Comment #1
dries commentedComment #2
drummWhy not make it consistent and always use a list?
Comment #3
dries commentedWe probably want to make it always return a list, as hinted by Drumm. Would that work?
Comment #4
Steven commentedBut then we should set a class on the UL and add a default style to drupal.css which hides the useless lone bullet (list-item-style: none).
Comment #5
Stefan Nagtegaal commented@Steven: why?
Comment #6
Nick Lewis commentedWell, I suppose it could go either way. Its just seems weird to output "Your blog entry was created." as a list item, as opposed to a paragraph -- given that there are no other items in that list. That said, I suppose making it consistant would remove 2 lines of code (never a bad thing.) Personally, I'd like the freedom to style single messages and multiple messages differently (but that's just me.) I'd be happy to reroll the patch to return it as a single list item if that's the bidding of the group, however.
Comment #7
dries commentedHaving to add a CSS class to hide a bullet seems overkill. Either we're ok with the bullet, or we go with the current patch?
Comment #8
Nick Lewis commentedWell, I vote for paragraphs:
1. Its more flexible from a CSS perspective. Having a P and UL requires less code to achieve a decent style; it removes the need to override a theme function if you want to emulate desktop OS's interface. The single list item, on the otherhand, would create a need.
2. A single message is not part of a series. Therefore it shouldn't be in a list.
3. the bullet will cause the messages to look worse than they do now. The paragraph merely corrects the issue, and adds the p margins. This will cause the message to look consistant with the rest of the site's typography.
I rest my case.
Comment #9
drummDon't think we want to do markup changes like this for Drupal 5.
Comment #10
bdragon commentedPatch no longer applies.
Comment #11
jody lynnComment #12
jacineNice patch! I agree with #8.
Comment #13
marcingy commentedThis is still an issue in d8.
Comment #14
Nick Lewis commentedComment #15
pasqualleIn D7 add the container to the page.tpl.php
for example /themes/bartik/templates/page.tpl.php
In D8 /core/modules/system/templates/status-messages.html.twig already has the container