Problems when layout module is enabled then later disabled

Created on 28 May 2018, about 6 years ago
Updated 5 August 2023, 11 months ago

From 8.5 the layout module is included in the drupal core. With the layout module enabled, the title field and other properties are present in the manage display interface, but then not rendered in the layout. If you debug in the hook_ENTITY_TYPE_view() in the $display->getComponents() you can find the title field, but no "region" is set, almost in the default view mode.

The following make a workaround for us (I put it here in case it helps to understand what is happening).

/**
 * Implements hook_ENTITY_TYPE_view().
 */
function modulename_node_view(array &$build, \Drupal\Core\Entity\EntityInterface $entity, \Drupal\Core\Entity\Display\EntityViewDisplayInterface $display, $view_mode) {

  if($view_mode == 'full'){
    $view_mode = 'default';
  }
  $title = $display->getComponent('title');
  $renderer = \Drupal::service('entity_type.manager')
    ->getStorage('entity_view_display')
    ->load($entity->getEntityTypeId() . '.' . $entity->bundle() . '.'.$view_mode)
    ->getRenderer('title');

  $title['region'] = 'header';
  $title['type'] = $renderer->getPluginId();
  $title['settings'] = $renderer->getSettings();
  $display->setComponent('title', $title);
  $build = $display->build($entity);
  
}

πŸ› Bug report
Status

Active

Component

Code

Created by

πŸ‡ͺπŸ‡ΈSpain akalam

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • πŸ‡¬πŸ‡§United Kingdom AdamPS

    Thanks for the extra report.

    The scenario is complex. It could have been a glitch or after 2 years there could have been a fix in Core. It would be useful if anyone else can confirm the bug.

  • πŸ‡ΊπŸ‡ΈUnited States aangel

    I'm getting this error now. The title is not rendering and I just turned off Layout for the content type. This is in 10.0.

    My workaround is to add {{ content.title } to the pipeline in hook_preprocess_node(&$variables).

  • πŸ‡¬πŸ‡§United Kingdom AdamPS

    Thanks for the update @aangel

Production build 0.69.0 2024