function title_entity_prepare_view in Title 8.2
Same name and namespace in other branches
- 7 title.module \title_entity_prepare_view()
Implements hook_entity_prepare_view().
File
- ./
title.module, line 136 - Convert titles into fields which can be display manipulated.
Code
function title_entity_prepare_view($entity_type_id, array $entities, array $displays, $view_mode) {
if ($entity_type_id !== 'node') {
return;
}
// This is only required because template_preprocess_node assumes there
// is a key inside the renderable array inside the elements array:
// $variables['label'] = $variables['elements']['title'];
// Since it can be display configured to be removed, it disappaers from the
// elements list. We must reinstate if it has been hidden from display,
// but without content.
$config = \Drupal::service('title.config_manager');
foreach ($entities as $entity) {
if (!$config
->getEnabled($entity
->bundle())) {
continue;
}
$display = $displays[$entity
->bundle()];
if (!$display
->getComponent('title')) {
$display
->setComponent('title', [
'hidden' => TRUE,
]);
}
}
}