Improvements to Submitted Formatter

Created on 24 February 2023, over 1 year ago
Updated 26 February 2023, over 1 year ago

Problem/Motivation

The goal is to solve these issues, which currently is difficult for the reasons given.

  1. ✨ Allow for additional submitted templates Fixed : can't add suggestions because the theme needs to have a base theme.
  2. ✨ Add option/setting to change "Submitted" formatter date format Fixed : would need to duplicate a lot of code from TimestampFormatter.
  3. Simplify the template (see below): forced to copy username.html.twig.

Details

Core template (part of node.html.twig):

<footer>
      {{ author_picture }}
      <div{{ author_attributes }}>
        {% trans %}Submitted by {{ author_name }} on {{ date }}{% endtrans %}
        {{ metadata }}
      </div>
    </footer>

This module template (submitted.html.twig)

<footer>
  {{ user_picture }}
  <div{{ author_attributes }}>
    {% if link_path -%}
      {% if date -%}
        {% trans %}Submitted by <a{{ attributes }}>{{ name }}{{ extra }}</a> on {{ date }}{% endtrans %}
      {%- else -%}
        {% trans %}Submitted by <a{{ attributes }}>{{ name }}{{ extra }}</a>{% endtrans %}
      {%- endif -%}
    {%- else -%}
      {% if date -%}
        {% trans %}Submitted by <span{{ attributes }}>{{ name }}{{ extra }}</span> on {{ date }}{% endtrans %}
      {%- else -%}
        {% trans %}Submitted by <span{{ attributes }}>{{ name }}{{ extra }}</span>{% endtrans %}
      {%- endif -%}
    {%- endif -%}
    {{ metadata }}
  </div>
</footer>

Proposed resolution

All 3 issues will become easy to solve if we change the design.

  • Currently SubmittedFormatter is taking the output elements of AuthorFormatter and inserting extra parts within them.
  • Instead SubmittedFormatter can create a 'parent' structure that has several child elements, one of which is AuthorFormatter, another is TimestampFormatter.

The code changes are pretty simple. However the changes aren't fully back-compatible:
Sites that have customised the submitted template will need to update their version.
The manage display configuration changes: previously the created field should be hidden, now it should be configured and the display settings are used to control display of the submitted date.

Remaining tasks

User interface changes

API changes

Data model changes

✨ Feature request
Status

Fixed

Version

3.0

Component

Code

Created by

πŸ‡¬πŸ‡§United Kingdom AdamPS

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Production build 0.69.0 2024