Problem/Motivation
A module can alter name
and date
(in hook_preprocess_node()
), but for those changes to actually show up, it'll also need to alter submitted
.
Use case: annotating which fields and properties are editable, for in-place editing through the Edit module.
The easiest solution would be for name
and date
to become themeable. But it's probably better to tie this in to the Entity API changes: #1346214-29: [meta] Unified Entity Field API.
Proposed resolution
Remove the $submitted variable entirely, use author and date in templates directly.
Remaining tasks
- Update all templates to print author and date instead of submitted (node, comment)
- Update preprocess functions to remove submitted variable (node, comment)
- Remove theme function for submitted info
- Update RDF to add it's attributes into the p tag instead of adding a span
User interface changes
none
API changes
none
Related Issues
#1757550: [Meta] Convert core theme functions to Twig templates
#1898432: node.module - Convert PHPTemplate templates to Twig
#1898054: comment.module - Convert PHPTemplate templates to Twig
#1898444: rdf.module - Convert theme_ functions to Twig
#364470: Easier theming of "Submitted by author, on date"
Also see http://drupal.org/update/themes/6/7#submitted_by.
Comments
Comment #1
Wim LeersComment #2
Wim LeersReferenced by #1706688: [meta] In-place editing, inline macros, editables, and Wysiwyg in core.
Comment #3
jenlamptonThe solution here is to get rid of the $submitted variable entirely.
Here's what the submitted info in our new Twig comment template looks like:
Here's what the submitted info our new Twig node template looks like:
Comment #4
jenlamptonMore accurate title.
Comment #4.0
jenlamptonissue summary initiative
Comment #4.1
jenlamptonupdate TODO list
Comment #5
thedavidmeister CreditAttribution: thedavidmeister commentedYeah.. I'm doing #1898054: comment.module - Convert PHPTemplate templates to Twig - be aware that I've *not* incorporated this in what I'm doing there because I'm aiming for 1:1 parity with core until the comment templates are actually in core. So the comment template part of this issue is essentially waiting on that to happen.
Also, be aware that the markup generated by:
is slightly different to:
The span that was wrapping all of "submitted" in the latter wraps just the author link in the former so I assume we'd have to write something somewhere for theme upgrade path notes?
Comment #5.0
thedavidmeister CreditAttribution: thedavidmeister commentedupdate todo list
Comment #6
Dave ReidI know there is a large use case for site-builders that don't actually want to modify templates that want to alter the submitted text. It would be nice if by by default we got rid of $display_submitted and only checked if $submitted was empty or not, and output that. While the idea of hard-coding the submitted string in the template itself is nice, it removes a lot of flexibility from everyone else except for the template developers.
Comment #7
jenlamptonI don't see how the opinion of people who don't want to edit templates should affect our decision to improve the experience of people who do want to edit templates :) Let's just make it better for the people who will use it.
Honestly, I also dislike $display_submitted (it should be a separate checkbox for both author and date, and it should appear on the Manage Display tab, not the Edit tab), but I dislike $submitted even more. It hides one of the things most frequently changed from the people who are trying to change it, and is a big frustration for 100% of front-end devs I've asked about it.
If there are people who don't want to edit template files, and there is a contrib module that makes their experience awesome so they don't have to, then that module can create a $submitted variable and preprocess it into the template. But there's no need leave it in core and continue to upset everyone else.
Comment #8
thedavidmeister CreditAttribution: thedavidmeister commented#7 - +1, I've hated the "submitted" black box since forever >.<
I think I can count the number of times it's lined up with designs that I've been handed on one hand. I also kind of feel like the module referenced in #6 only exists *because* it's currently a black box in core that can't be overridden inside a template, or am I missing something?
Comment #9
andypost+1 hre to remove, "submited_by module Reported installs: 3297" points that theme developers prefer to change templates
Comment #10
thedavidmeister CreditAttribution: thedavidmeister commentedThis can't really happen until #1898054: comment.module - Convert PHPTemplate templates to Twig lands though.
Comment #11
Dave ReidHow would this be possible if we're hardcoding the submitted string in the template???
Comment #12
andypostSuppose another approach here is to move $submited to hook_field_extra_fields() and use fields to control visibility
PS: No reason to postpone this.
Comment #13
thedavidmeister CreditAttribution: thedavidmeister commented#12 - The reason that I postponed this is because the two examples from @jenlampton in #3, while great and probably will be the final solution, return *slightly* different markup to what's in core at the moment - simply because of the way HTML attributes work in Twig.
Since the Twig template issues at #1757550: [Meta] Convert core theme functions to Twig templates all need 1:1 markup with the current markup output by core, we will either have to:
- get this issue into core before both nodes and comments are converted, then modify re-roll the already-nearly-RTBC node and comment patches to match what's here.
- wait until node and comment are both in core then do the work required here once without de-railing efforts elsewhere (this could even become a novice issue at that point).
The first option is obviously undesirable. If there's a third option I can't figure out what it is so I'd love to see a patch for it :)
Comment #14
jenlampton{% codeblock %}
)so the only part of the original template it modifies is the submitted lineComment #15
markhalliwellDup of #2047095: Remove $submitted from node templates and needs to use the new Twig
{% trans %}
tag.Comment #15.0
markhalliwelladd node, comment, and RDF as related issues