The label of an ECK entity with enabled title base field is not documented in code comment block how to get printed in the eck-entity.html.twig file in a way how it is common to Drupal content entities and nodes.

In node.html.twig the label is documented in the comment block and printable like expected by using the label tag. Same goes for custom entities created by drush generate content:entity. In the latter the comment block mentions content.label and this is exactly the way to print the label in the respective twig file.

Proposed solution

Assuming that many use cases of ECK entities will use the title base field, make title base field documented in eck-entity.html.twig and add the correct tag to be used to the comment block.

Additional task

Assuming that ECK needs to deal with many possibly scenarios including entities without a label base field, it needs a twig logic to check against if label exist before printing it. This should be added to the code comment block too.

Issue fork eck-3482263

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

dqd created an issue. See original summary.

dqd’s picture

Issue summary: View changes
dqd’s picture

Title: Base field label (title) exposed and commented to print in twig template » Make base field label (title) exposed and commented to print in twig template
dqd’s picture

Title: Make base field label (title) exposed and commented to print in twig template » Document how to print title base field in twig template
Issue summary: View changes

Like I have expected, I found out the correct twig tag after further investigating and trying. Since I already mentioned that to possibly happen in the issue summary in the previously existing consideration section, I immediately changed the scope if the issue accordingly and removed the last part in the issue summary about it.

dqd’s picture

Status: Active » Needs review
dqd’s picture

Additionally we should consider to add

     {% if content.title %}
        {{ title_prefix }}
          <h2{{ title_attributes }}>
            {% if view_mode != 'full' %}
              <a href="{{ url }}" rel="bookmark">{{ content.title }}</a>
            {% else %}
              {{ content.title }}
            {% endif %}
          </h2>
        {{ title_suffix }}
      {% endif %}

in templates/eck-entity.html.twig before {{ content }}.