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.
Current theme function
Located in includes/theme.inc:
function theme_mark($variables) {
$type = $variables['type'];
global $user;
if ($user->uid) {
if ($type == MARK_NEW) {
return ' <span class="marker">' . t('new') . '</span>';
}
elseif ($type == MARK_UPDATED) {
return ' <span class="marker">' . t('updated') . '</span>';
}
}
}
Potential Changes
- The tag should be changed to
<mark>
. - The class should be removed. It's superflous. The element speaks for itself and context can be derived from the wrapper.
- The core/theme CSS needs to adjusted where targeting
.marker
.<mark>
element has a yellow background and black foreground by default so we can remove the core styling from system.theme.css and style it however in the core themes, if at all. - The code itself could be cleaned up and simplified. Maybe it could take the string as an argument instead of dealing with constants. I say this because there are other places where it could be used easier if that were the case, such as
comment.tpl.php
:
<?php if ($new): ?> <span class="new"><?php print $new ?></span> <?php endif; ?>
When to Use the MARK Element
- Showing search results
- Highlight text in a quotation
- Indicate new items in a list
- Show the current date in a calendar
- Highlighting an error
References
http://webdesign.about.com/od/html5tags/a/understanding-the-mark-element...
https://www.w3.org/wiki/HTML/Elements/mark
https://developer.mozilla.org/en/docs/Web/HTML/Element/mark
Related Issues
Comment | File | Size | Author |
---|---|---|---|
#76 | interdiff.txt | 558 bytes | lauriii |
#76 | use_mark_element_for-1311372-76.patch | 3.6 KB | lauriii |
Comments
Comment #1
karschsp CreditAttribution: karschsp commentedHere's a first stab at this.
Comment #3
karschsp CreditAttribution: karschsp commentedHere's an updated patch for the /core change and removing one last MARK_NEW from common.inc.
Comment #4
karschsp CreditAttribution: karschsp commentedneeds review
Comment #6
karschsp CreditAttribution: karschsp commentedMissed a stray MARK_READ in that last patch.
Comment #8
karschsp CreditAttribution: karschsp commentedRe-queuing due to testbot failures seemingly unrelated to this patch.
Comment #9
karschsp CreditAttribution: karschsp commented#6: 1311372-theme_mark.006.patch queued for re-testing.
Comment #10
JacineHey @karschsp, thanks so much for the patch! Sorry for taking so long to get to it.
Hey, can we add the $type as a class here.
Hey, can we add the $type as a class here.
Comment #11
cosmicdreams CreditAttribution: cosmicdreams commentedon my list for tonight
Comment #12
cosmicdreams CreditAttribution: cosmicdreams commentedRerolled and made the one-liner that jacine requested in #10
Comment #13
Niklas Fiekas CreditAttribution: Niklas Fiekas commentedThank you for the patch.
We should not use t() for class names. We also can't call t() on a variable -- the first parameter to t() must be a string literal. That's why there were MARK_NEW, MARK_UPDATED and MARK_READ and why they probably should stay.
Comment #14
JacineWell maybe, but they are not good enough. This needs to be more flexible, or it's useless. This theme function isn't used everywhere it could be right now. It should be used for other things like a published/unpublished status as well. It's not flexible enough IMO. There has to be a way around this.
Comment #15
JohnAlbinI agree that MARK_NEW, etc should stay, but for completely different reasons. Drupal uses node_mark() to mark nodes and comments as read, new or updated. It's simplest if node_mark returns a constant rather then a translated string and a class name.
So let's make theme_mark more useful by having an optional $content variable which takes a translated string containing the text that should be placed inside the mark element. If $content is not given but a $type is given, then we put some default text into $content and wrap that in the mark element.
This new $content variable will allow theme_mark() to be used for any legitimate usage of the HTML5 mark element, e.g. marking a highlighted passage of an existing document.
I've removed the leading space from theme_mark because that was dumb and only needed in one place in Drupal core. I've also removed the global $user bit because it was redundant with the check done in node_mark() and because it was incredibly brain-dead to put business logic in a theme function.
I've also removed the implicit check for MARK_READ in theme_mark() before returning a themed mark. theme_mark() now assumes that if you called theme('mark') that you really did want a mark element. The check for MARK_READ (i.e. I do not want a mark element) is now done before theme('mark') is called.
And now it is, I think. :-) I've made the comment.tpl's $new variable and the outdated translation marker use theme_mark.
So you can now use theme_mark in 2 ways:
Comment #17
JohnAlbinUpdated patch
Comment #18
JohnAlbinCNR
Comment #19
cosmicdreams CreditAttribution: cosmicdreams commentedLooks good
Comment #20
webchickThis makes a lot of sense.
These two things seem to contradict each other. If $content is optional, then shouldn't we do an isset() check in that line below?
Is attributes required? Or is it also optional? I think it's optional, in which case it's weird that's not specified, where it is on type and content.
Comment #21
JohnAlbinGood question! But all 3 of those variables have default values set in hook_theme(). Note this hunk in the patch:
So they will definitely exist when theme_mark is called.
Which means I'm not explaining the variables properly. Technically, most variables in the theme system will have default values and, thus, are "optional". I just rewrote that docblock to make it obvious how the "type" variable effects the other variables.
Comment #22
JohnAlbinGuh. Wrong patch. This one please.
Comment #23
sannejn CreditAttribution: sannejn commentedAfter applying the latest patch I get the following whitescreen-error:
Fatal error: Call to undefined function drupal_attributes() in /core/includes/theme.inc on line 2002
Is this a new function yet to be implemented?
Comment #24
JohnAlbin#22: 1311372-22-mark-html5.patch queued for re-testing.
Comment #26
JohnAlbinHere's a re-rolled patch.
Comment #27
JohnAlbinReview!
Comment #29
JohnAlbin#26: 1311372-26-mark-html5.patch queued for re-testing.
Comment #31
JohnAlbinAfter talking with Jen Lapton, we decided we should remove this entire theme hook.
Comment #32
JohnAlbinHere's the patch that removes the theme function.
Comment #33
JohnAlbinlol. totally wrong patch file.
Comment #34
JohnAlbin*sigh* Third time's a charm.
Comment #36
JohnAlbinRe-roll.
Comment #38
andypost@JohnAlbin I've trying to refactor
theme_mark()
in another issue #2062097: Remove calls to deprecated global $user in theme.inc and came to nearly the same idea.The function needed for node, comment, tracker and translation modules so should be shared because comment module could be used for any entity soon #1907960-381: Helper issue for "Comment field"
The only thing I suggest is remove access check from theme function
Comment #38.0
joelpittetUpdated issue summary.
Comment #39
joelpittetRe-rolled again.
Comment #41
RainbowArrayRe-rolled the patch to apply cleanly against 8.x.
Comment #43
Wim LeersYou'll want to update
HistoryTimestampTest
, i.e. replace$result = $this->xpath('//span[@class=:class]', array(':class' => 'marker'));
with
$result = $this->xpath('//span[@class=:class]', array(':class' => 'mark--new'));
Questions:
Comment #44
mgiffordComment #45
mgiffordComment #46
markhalliwellWe're losing the render array structure by adding in static markup. This makes it difficult to replace (or change classes accordingly).
In retrospect, these table rows really should be using a render array for the data/link instead of
l()
. That would allow us to append the render array with a new "marker" renderable child. This would allow us to replace just the$row['title']['data']['marker']['#markup']
instead of having to do apreg_replace()
on the string.Also, FWIW, we're kind of duplicating the efforts in #1939092: Convert theme_mark() to Twig... although this issue is completely removing the "mark" template entirely (which isn't a really good idea IMO). Twig caches everything so having a separate "mark" theme hook for the
<mark>
tag makes sense. It shouldn't be subject to theMARKED_NEW and MARKED_UPDATE
constants though, it should be abstracted so the classes are added via preprocess and not in the template:Comment #48
mgiffordHappy to mark this as a duplicate and focus efforts on #1939092: Convert theme_mark() to Twig. I was just trying to nudge this issue along.
Comment #49
markhalliwellI think this should be a separate issue (as it's changing the markup), so just postponing it until that issue is resolved.
Comment #50
markhalliwellForgot to some other issue cleanup
Comment #51
mgiffordComment #52
andypostIt's not clear what is a current proposal after #1939092: Convert theme_mark() to Twig
Comment #53
akalata CreditAttribution: akalata commented@andypost I think the distinction is clear; this issue is about the markup, and that issue was about how to deliver the markup.
Comment #54
mgiffordI'm going to mark this as a duplicate as it's being addressed over here #867830: "Unpublished" style of rendered entities is not accessible (and looks bad). Can we focus our efforts on this patch?
Comment #55
mgiffordOk, we're moving this back here.
Comment #56
joelpittetCrap we missed this, the only tricky part is maybe getting this logged_in status check moved out of the template and onto the render array.
Here's a rough conversion that will likely fail, and I'm not supposed to change stable/classy so likely have to revert that change later... just want to kick the tires on this a bit...
And there is a bug fix in here now too AND this likely doesn't work well with render cache as it probably needs some cache tags and context when it's being built.
Comment #58
lauriiiDo we want to show the mark element even when the text is empty?
Comment #59
dawehnerI'm curious whether this logic should/could be part of the template instead?
Comment #60
mikemiles86Comment #61
mikemiles86To address comment #58 by @lauriii , based on all my digging into standards around the tag it is valid for it to be empty. don't think we'd want to hide it if text is empty.
@dawehner keeping that logic within theme.inc seems like a cleaner approach then moving it into the template. If moved into the template, we would end up with a template looking something like this:
That seems like a not-ideal scenario.
I have made an update to patch #56. Noticed that the render method in HistoryUserTimestamp.php was using the depreciated drupal_render().
Comment #62
mikemiles86Add this time to attach the correct patch file...
Comment #63
mikemiles86Comment #65
dawehnerThis looks something which could be totally moved to the template. Well these days we try to basically remove preprocess functions as much as possible.
This would need a cache context so it changes between authenticated and non authenticated users.
Comment #66
lauriiiComment #67
joelpittetLet's please move the
logged_in
check out of this template, that logic doesn't need to be representative of a mark tag, it should be more controller logic deciding when to use that element.Comment #68
lauriiiRerolled new patch without macros and added missing comma for HistoryUserTimestamp
Comment #71
joelpittetThank you @lauriii. Here's an iteration on that and fix the missing variable bug and removes the markup changes in stable.
Comment #72
Manuel Garcia CreditAttribution: Manuel Garcia as a volunteer and at Appnovation commentedThis looks beautiful to me, issues mentioned on #65 are addressed as well.
Comment #73
Wim LeersThis cache context does not match the logic. It describes far more variations than what's actually going on here: a binary "anon or auth" variation.
The proper cache context to use here is
user.roles:authenticated
.SO MUCH BETTER!
Except this is new? We never had
markers before. This is a huge visual change. Let's have screenshots to properly assess this before committing.Comment #74
Wim LeersNote the cache context was okay: it would have ensured correct render caching. But it is not optimal, because it causes more variations than necessary.
So, this is not about security or correctness, this is about efficiency.
Comment #75
mikemiles86Are we getting rid of the 'mark-XXX' classes? Or should this section be updated to be
{{ attributes.addClass('mark-XXX') }}
Comment #76
lauriii#73.3: It is not actually a change for core's use cases because we never actually show that when it is read.
'#access' => ($mark == MARK_NEW || $mark == MARK_UPDATED)
#75: We didn't use to have any classes in core so this doesn't affect the situation at all. What we do is simply wrap the text with mark element.
Comment #77
Wim LeersInteresting/fair.
Comment #78
catchDoesn't this also need the user.roles.authenticated cache context?
Comment #79
catchAlso while I'm here, the docs for mark don't make me 100% confident it's the right thing here for 'new'/'updated'. https://developer.mozilla.org/en/docs/Web/HTML/Element/mark
i.e. we should definitely be using it in https://api.drupal.org/api/drupal/core%21modules%21search%21search.modul... instead of strong tags because that's explicitly about highlighting a particular section of text based on the context that it's being shown in a search result for the word that's highlighted.
I don't see the same applicability to new/updated.
Of course if we don't use it, that makes the 'mark' element very unfortunately named.
Comment #80
Wim Leers#78: that is already there, see #76.
Comment #81
catch@WimLeers I see it in HistoryUserTimestamp but not in NodeListBuilder?
Comment #82
star-szrSince it hasn't really been discussed on this issue I'd love to see a response to #79. I did a brief search and turned up this:
– http://webdesign.about.com/od/html5tags/a/understanding-the-mark-element...
Not sure I'd consider webdesign.about.com the best resource but at least it's not totally unheard of…
Comment #83
mgiffordFrom the W3C: "The element represents a run of text in one document marked or highlighted for reference purposes, due to its relevance in another context. "
Hmm.. Yes.. This doesn't quite seem what what they meant. New & Updated are useful to highlight, but don't seem to fit well with examples. Even "Indicate new items in a list" would probably be a matter of wrapping the string with the new item, rather than attaching a New behind it.
Updating the summary with some references.
Comment #85
RainbowArrayHere's another article about the mark element: HTML5 Doctors: Draw attention with mark.
One of the items in the W3C definition:
Coming to a page and seeing items that are new or updated seems like items of special relevance to a user's current activity. There isn't always a perfect HTML element to convey the right semantics, and I can see that the mark element may be a bit of a stretch here. That said, I think the mark element conveys better and more useful semantics than a simple span, so I think it is worth making the change.
Comment #99
andypostLet's replace constants as well here
Comment #100
catchI'm still not convinced that this is applicable at all, see for example https://developer.mozilla.org/en-US/docs/Web/HTML/Element/mark
Comment #101
catch