Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
By tim.plunkett on
Change record status:
Published (View all published change records)
Project:
Introduced in branch:
8.x
Issue links:
Description:
When accessing a node's title, do not use the property itself, but rather the Entity::label() method.
This will allow for improvements to the translatability of a node's title.
//D7
function book_outline($node) {
drupal_set_title($node->title);
return drupal_get_form('book_outline_form', $node);
}
//D8
function book_outline(Node $node) {
drupal_set_title($node->label());
return drupal_get_form('book_outline_form', $node);
}
However, setting the node title directly will still use $node->title = $new_title;
.
In the same vein, entity forms exposing the label for input should use the property, not the result of the label()
method. For example:
$form['title'] = array(
'#type' => 'textfield',
'#title' => t('Title'),
'#default_value' => $node->title,
);
Impacts:
Module developers