Problem/Motivation
Look at this code, this is an inconsistent mess:
<?php print render($title_prefix); ?>
<?php if (!$page): ?>
<h2<?php print $title_attributes; ?>><a href="<?php print $node_url; ?>" rel="bookmark"><?php print $label; ?></a></h2>
<?php endif; ?>
<?php print render($title_suffix); ?>
Proposed resolution
I understand the need to call the label() method on the node object instead of directly referencing the $node->title, but I don't understand why that needs to trickle all the way down to the theme layer. Can we please be consistent with our variable names and call this a title? We can preprocess it in, or do it as part of the Twig __to_string() method on rendering a node.title but in the template file we should really be calling this a title.
Alternatively, we could rename everything else in these templates that contains "title" into a label. label_prefix, label_suffix, label_attributes.
Remaining tasks
- make our templates consistent
User interface changes
- none
API changes
- none
Related Issues
#1939224: Change block "label" so thad a title like everything else in the template file (and all other template files)
#1591806: Change block "subject" so that it's called a (admin_)label like everything else on the theme layer
#1591830: Change comment "subject" so that it's called a title like everything else in the template file (and all other template files)
#1825216: Name variables consistently across all templates (preprocess)
#2004966: Markup and variable cleanup for titles and attributes in all templates
| Comment | File | Size | Author |
|---|---|---|---|
| #15 | 1939234-node-label-to-title-15.patch | 3.57 KB | Vikas.Kumar |
| #14 | 1939234-node-label-to-title-14.patch | 4.45 KB | Sethie |
| #7 | 1939234-node-label-to-title-7.patch | 4.4 KB | lahoosascoots |
| #3 | 1939234-node-label-to-title-3.patch | 4.98 KB | joelpittet |
Comments
Comment #0.0
jenlamptonother
Comment #0.1
jenlamptonless snark
Comment #1
xmacinfoI do not understand the need to call the label() method on the node object. Nevertheless, in the node template I agree, we should have $title, not $label.
The decision should be simple, use $title everywhere we need to display a title.
Comment #1.0
xmacinfoA
Comment #1.1
dead_armAdd related issue
Comment #2
xjm(Merging "node system" and "node.module" components for 8.x; disregard.)
Comment #3
joelpittetLet's see if testbot has any grievances.
Comment #4
mlncn commented3: 1939234-node-label-to-title-3.patch queued for re-testing.
Comment #6
mlncn commentedWorked 3 months ago so probably just needs re-roll.
Comment #7
lahoosascoots commentedRe-rolled
Comment #8
xmacinfoGreen! Do we need to patch only three files?
Comment #9
berdirI'm honestly not sure why node of all things was updated to use label, but the advantage of label is that it's the generic name on the entity level.
Comments have subjects (uses title in the template too, that's also weird), terms (uses name) and users have names (doesn't use anything in the template). All those things are exposed as the entity label.
But completely agree that having title_* and then label is weird., would have to be renamed consistently to label, better to be title consistently than what we have right now.
I suggest that you also update the $node->label() call to $node->getName(), wherever it's set.
Comment #12
mgiffordComment #13
Sethie commentedI'll reroll it.
Comment #14
Sethie commentedHere's the patch.
Comment #15
Vikas.Kumar commentedComment #16
Vikas.Kumar commentedComment #17
xmacinfoWell done!
I did not apply the patch, though, so not marking RTBC.
Comment #18
mgiffordI applied the patch. Looks like a good change for consistency.
Comment #21
lauriiiPutting back because of random test failure
Comment #22
lauriiiI guess the beta evaluation could be added there actually..
Comment #23
xmacinfo@lauriii: What do you mean by:
Comment #26
lauriiiBeta evaluation template
Comment #29
star-szrSorry, indeed this stuff is a bit of a mess as far as consistency, but postponing for the same reasons as #1939224-28: Change block "label" so thad a title like everything else in the template file (and all other template files).
Comment #30
catchI think we could duplicate the variable and update the template in a minor release, then remove the duplication in 9.x
Doesn't make it less messy in 8.x, but it does make it forward compatible with a less-messy 9.x.
Comment #31
berdirWe could but the problem there is modules that are altering it in preprocess, they'd have to be updated to support both.
Comment #32
catchWe could do the duplication after preprocess runs.
Comment #48
acbramley commentedThis issue has gone stale for almost 10 years.
I'm actually somewhat against this change,
labelis a consistent Drupalism applied to all entity types. Title is not. E.g in #1939224: Change block "label" so thad a title like everything else in the template file (and all other template files) blocks don't have a title, they have a block description or label.If anything, the title_prefix/suffix/attributes should be the ones to change?
Comment #49
xmacinfoTo get more developers on Drupal, some "Drupalism" needs to go.
Developers are typically giving a name to the things they create.
- Name of the block
- Name of the variable
- Name of the function
- Name of the field
A label is a tag attached to an item.
So either we continue putting Drupal in a corner with its "Drupalism" or we adopt more generalized standards.
Comment #50
acbramley commentedThinking about this more, I think
labelis the better name to keep. We use it all over the place in Drupal such as in entity keys, other entity metadata keys (label_count),$entity->label()and many other areas.Repeating #48 if anything I think title_prefix/suffix/attributes should be the thing to change but I don't feel strongly enough to open a follow up. If anyone else does, feel free :)