I don't like the idea of falling back to another block (as I wanted a title field) or to needing to set the title in templates (too much logic in templates can get difficult to maintain on the long run). At least there seems to be some ongoing discussion on DO how to [META] Expose Title and other base fields in Manage Display after the loved Title module seems to be abandoned.
I also wouldn't recommend to install the pretty massive Display Suite for such a small thing. The new experimental core module Layouts Builder (video) might cover that, but still seems quite fiddly to configure.
So for now I live with the following little gem (source 1, source 2) that adds a new pseudo field to the display settings of each content type to render the page title as simple markup at the corresponding position inside the node's $content
.
use Drupal\node\Entity\NodeType;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Entity\Display\EntityViewDisplayInterface;
/**
* Implements hook_entity_extra_field_info().
*/
function MYMODULE_entity_extra_field_info() {
$extra = [];
foreach (NodeType::loadMultiple() as $bundle) {
$extra['node'][$bundle->id()]['display']['title_field'] = [
'label' => t('Title'),
'description' => t('Title field'),
'weight' => 100,
'visible' => TRUE,
];
}
return $extra;
}
/**
* Implements hook_ENTITY_TYPE_view().
*/
function MYMODULE_node_view(array &$build, EntityInterface $entity, EntityViewDisplayInterface $display, $view_mode) {
// You could get the node ID or anything else
// you want from the node object here.
$title = $entity->getTitle();
if ($display->getComponent('title_field')) {
$build['title_field'] = [
'#type' => 'inline_template',
'#template' => '<h1>{{ title }}</h1>',
'#context' => [
'title' => $title,
],
];
}
}
Just found out there already is a little module which does exactly that: Pseudo Title.
Pseudo Title creates a pseudo field that can be used to move up and
down the content of the title in the same administration page where
the display of other fields are managed.
And there also is the Manage display module.
This project makes base fields such as 'title' available in "Manage
Display".
This very simple module uses the framework that is already in Core
rather than inventing anything new. The goal is that most or all of
this module will be absorbed into core #2353867: [META] Expose
Title and other base fields in Manage Display.