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

#1757550: 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

Wim Leers’s picture

Title:Impossible to alter author & date in "Submitted by author, on date"» Ability to alter author & date in "Submitted by author, on date"
Wim Leers’s picture

jenlampton’s picture

Category:feature» task
Issue tags:+Twig, +theme system cleanup

The 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:

<p class="submitted">{{ 'by !author on !date' | t({'!author': author, '!date': created})}}</p>

Here's what the submitted info our new Twig node template looks like:

<p class="submitted">{{ 'Submitted by !author on !date' | t({'!author': name, '!date': date}) }}</p>
jenlampton’s picture

Title:Ability to alter author & date in "Submitted by author, on date"» remove 'submitted' variable in templates for ease of theme development
Issue tags:+Increases learning curve

More accurate title.

jenlampton’s picture

Issue summary:View changes

issue summary initiative

jenlampton’s picture

Issue summary:View changes

update TODO list

thedavidmeister’s picture

Yeah.. 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:

<p class="submitted">{{ 'by !author on !date' | t({'!author': author, '!date': created})}}</p>

is slightly different to:

<p class="submitted">{{ submitted }}</p>

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?

thedavidmeister’s picture

Issue summary:View changes

update todo list

Dave Reid’s picture

I 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.

jenlampton’s picture

I 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.

thedavidmeister’s picture

#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?

andypost’s picture

+1 hre to remove, "submited_by module Reported installs: 3297" points that theme developers prefer to change templates

thedavidmeister’s picture

Status:Active» Postponed

This can't really happen until #1898054: comment.module - Convert PHPTemplate templates to Twig lands though.

Dave Reid’s picture

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.

How would this be possible if we're hardcoding the submitted string in the template???

andypost’s picture

Status:Postponed» Active

Suppose another approach here is to move $submited to hook_field_extra_fields() and use fields to control visibility

PS: No reason to postpone this.

thedavidmeister’s picture

#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: 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 :)

jenlampton’s picture

How would this be possible if we're hardcoding the submitted string in the template???

  1. contrib module preprocesses in a variable $submitted that concatenates whatever is configured in the UI.
  2. contrb module theme_hook_suggestion_alter's in it's new template that prints that var instead, perhaps using Twig template inheritance ({% codeblock %})so the only part of the original template it modifies is the submitted line
  3. content is rendered using contrib module template + new vars :)
markcarver’s picture

Status:Active» Closed (duplicate)

Dup of #2047095: Remove $submitted from node templates and needs to use the new Twig {% trans %} tag.

markcarver’s picture

Issue summary:View changes

add node, comment, and RDF as related issues