As discussed in #1616962: Replace $node->title with $node->label() and #1616972: Replace $term->name with $term->label(), the recent changes in Entity API have clarified the dichotomy between Entity::label() and the properties from which its data comes, like $node->title and $term->name, among others.

One expected followup from this is the introduction of a generic label token and variable in entity templates, which would reference the result of the label() method, whereas the "native" property-based equivalent (title, name, ...) would remain, helping to avoid use conflicts.

Comments

fago’s picture

Title: Unify use of entity labels vs the properties carrying them. » Make use of entity labels in templates

trying to improve the issue title.

More details using the node example:
When linking to a node the node->label() is used instead of the node title. But when something specifically refers to the node title, as $title in templates - we've been staying with the node title. Considering that the label property can be altered, it would be weird to don't get the title in $title. So, if we want to go with entity labels in the templates as well it should probably be $label or $entity_label, while $title could be available as well.

schnitzel’s picture

StatusFileSize
new3.16 KB

I spoke with some themers at the coding sprint drupalcon munich (mortendk and others).

they agreed that we should use the same terminology for the themers and the developers.
Because it makes no real sense to show the title (node.tpl.php and taxonomy_term.tpl.php are mostly used to show something to the user) we agreed to use the label instead. To not confuse themers we remove the $title completly.

attached patch does this.

I also wanted to first change the $title_prefix and $title_attributes variables. but I saw in block.tpl.php this:

  <?php print render($title_prefix); ?>
<?php if ($block->subject): ?>
  <h2<?php print $title_attributes; ?>><?php print $block->subject ?></h2>
<?php endif;?>
  <?php print render($title_suffix); ?>

so we are already mixing title and non title things, which I decided to not change $title_prefix to $label_prefix

schnitzel’s picture

Status: Active » Needs review
gábor hojtsy’s picture

Status: Needs review » Reviewed & tested by the community
Issue tags: +D8MI, +sprint, +language-content

Based on all the feedback you got and the cross-check with existing subsystems, I think this should be ready to go.

berdir’s picture

Status: Reviewed & tested by the community » Needs work
Issue tags: -D8MI, -sprint, -language-content

This change looks good to me, I agree with everything in #2.

+++ b/core/modules/taxonomy/taxonomy-term.tpl.phpundefined
@@ -12,7 +12,7 @@
  * - $term_url: Direct url of the current term.
- * - $term_name: Name of the current term.
+ * - $term_label: Name of the current term.
  * - $attributes: An instance of Attributes class that can be manipulated as an

Note that there's also $name a few lines above. I think we should actually just have $label and remove $name and $term_name.

berdir’s picture

Issue tags: +D8MI, +sprint, +language-content

Oh, cross-post. Re-adding tags. I do think the $name/$term_name thing should be fixed. Given that $term_name is used in the template, $name might not even exist and might just be a documentation bug.

berdir’s picture

Status: Needs work » Reviewed & tested by the community

Ah, yes, if there's already an issue then this is fine with me. Still not 100% about $term_label vs. $label.

schnitzel’s picture

Status: Reviewed & tested by the community » Needs review
StatusFileSize
new3.32 KB

discussed with Berdir in IRC, we agreed to unify the variables so that they are the same in node.tpl.php

berdir’s picture

Status: Needs review » Reviewed & tested by the community

Looks good. Will conflict with #1637342: Add entity_url() and entity_l() wrapper functions to simplify using EntityInterface::uri(), might make sense to get that one in first.

catch’s picture

Status: Reviewed & tested by the community » Fixed

Hmm the other one is already CNW for a re-roll, so I'm going to go ahead and commit this so it's out of the way. This all seems reasonable to me. Committed/pushed to 8.x.

gábor hojtsy’s picture

Issue tags: -sprint

Change notice posted at http://drupal.org/node/1776718 (aimed at themers, although twig might change this altogether anyway :D) I don't think this deserves a CHANGELOG.txt entry, so off we go (off from the sprint that is). Thanks all!

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

webchick’s picture

Note that this caused XSS vulnerabilities in D7 templates that are ported to D8: #1811684: XSS: Bartik's node.tpl.php prone to XSS (prints $title)