private function LayoutBuilderMigration::doProcessDisplay in Panelizer 8.5
Migrates a layout-able entity view display to Layout Builder.
Parameters
\Drupal\layout_builder\Entity\LayoutEntityDisplayInterface $display: The entity view display.
File
- src/
LayoutBuilderMigration.php, line 81
Class
- LayoutBuilderMigration
- Provides functionality to migrate Panelizer data to Layout Builder.
Namespace
Drupal\panelizerCode
private function doProcessDisplay(LayoutEntityDisplayInterface $display) {
$entity_type_id = $display
->getTargetEntityTypeId();
$bundle = $display
->getTargetBundle();
$mode = $display
->getMode();
$panelizer_settings = $this->panelizer
->getPanelizerSettings($entity_type_id, $bundle, $mode, $display);
if (empty($panelizer_settings['enable'])) {
return;
}
$display_storage = $this->entityTypeManager
->getStorage('entity_view_display');
$layout_storage = $this->entityTypeManager
->getStorage('layout');
$display
->enableLayoutBuilder()
->setOverridable($panelizer_settings['custom'])
->setThirdPartySetting('layout_library', 'enable', $panelizer_settings['allow']);
$panels_displays = $this->panelizer
->getDefaultPanelsDisplays($entity_type_id, $bundle, $mode, $display);
foreach ($panels_displays as $name => $panels_display) {
$configuration = $panels_display
->getConfiguration();
$configuration += [
'static_context' => [],
];
$section = $this
->toSection($configuration, $entity_type_id, $bundle);
$panels_display
->setConfiguration($configuration);
if ($name === $panelizer_settings['default']) {
$display
->appendSection($section);
if ($configuration['static_context']) {
$display
->setThirdPartySetting('core_context', 'contexts', $configuration['static_context']);
}
}
else {
/** @var \Drupal\layout_library\Entity\Layout $layout */
$layout = $layout_storage
->create([
'id' => implode('_', [
$entity_type_id,
$bundle,
$mode,
$name,
]),
'targetEntityType' => $entity_type_id,
'targetBundle' => $bundle,
'label' => $panels_display
->label(),
]);
$layout
->appendSection($section);
if ($configuration['static_context']) {
$layout
->setThirdPartySetting('core_context', 'contexts', $configuration['static_context']);
}
$layout_storage
->save($layout);
}
}
$display_storage
->save($display);
$panelizer_settings['enable'] = FALSE;
$panelizer_settings['allow'] = FALSE;
$panelizer_settings['custom'] = FALSE;
$this->panelizer
->setPanelizerSettings($entity_type_id, $bundle, $mode, $panelizer_settings, $display);
}