You are here

private function LayoutBuilderMigration::doProcessEntity in Panelizer 8.5

Migrates a custom entity-specific Panelizer layout to Layout Builder.

Parameters

\Drupal\Core\Entity\FieldableEntityInterface $entity: The entity that has the custom layout.

File

src/LayoutBuilderMigration.php, line 150

Class

LayoutBuilderMigration
Provides functionality to migrate Panelizer data to Layout Builder.

Namespace

Drupal\panelizer

Code

private function doProcessEntity(FieldableEntityInterface $entity) {
  $entity_type_id = $entity
    ->getEntityTypeId();
  $bundle = $entity
    ->bundle();
  foreach ($entity->panelizer as $panelizer_item) {
    if ($panelizer_item->view_mode === 'full') {
      if ($panelizer_item->panels_display) {
        $configuration = $panelizer_item->panels_display;
        $section = $this
          ->toSection($configuration, $entity_type_id, $bundle);

        /** @var \Drupal\layout_builder\Field\LayoutSectionItemList $sections */
        $sections = $entity
          ->get(OverridesSectionStorage::FIELD_NAME);
        $sections
          ->appendSection($section);

        // The Panels display may have been modified by ::toSection() in order
        // to make the entity save-able.
        $panelizer_item->panels_display = $configuration;
      }
      if ($panelizer_item->default && $panelizer_item->default !== '__bundle_default__' && $entity
        ->hasField('layout_selection')) {
        $entity->layout_selection->target_id = implode('_', [
          $entity_type_id,
          $bundle,
          $panelizer_item->view_mode,
          $panelizer_item->default,
        ]);
      }
      $this->entityTypeManager
        ->getStorage($entity_type_id)
        ->save($entity);
      break;
    }
  }
}