public function Panelizer::setPanelizerSettings in Panelizer 8.3
Same name and namespace in other branches
- 8.5 src/Panelizer.php \Drupal\panelizer\Panelizer::setPanelizerSettings()
- 8.4 src/Panelizer.php \Drupal\panelizer\Panelizer::setPanelizerSettings()
Parameters
string $entity_type_id: The entity type id.
string $bundle: The bundle.
string $view_mode: The view mode.
array $settings: An associative array with the same keys as the associative array returned by getPanelizerSettings().
\Drupal\Core\Entity\Display\EntityViewDisplayInterface|NULL $display: If the caller already has the correct display, it can optionally be passed in here so the Panelizer service doesn't have to look it up; otherwise, this argument can bo omitted.
Overrides PanelizerInterface::setPanelizerSettings
See also
PanelizerInterface::getPanelizerSettings()
File
- src/
Panelizer.php, line 492
Class
- Panelizer
- The Panelizer service.
Namespace
Drupal\panelizerCode
public function setPanelizerSettings($entity_type_id, $bundle, $view_mode, array $settings, EntityViewDisplayInterface $display = NULL) {
if (!$display) {
$display = $this
->getEntityViewDisplay($entity_type_id, $bundle, $view_mode);
}
$display
->setThirdPartySetting('panelizer', 'enable', !empty($settings['enable']));
$display
->setThirdPartySetting('panelizer', 'custom', !empty($settings['enable']) && !empty($settings['custom']));
$display
->setThirdPartySetting('panelizer', 'allow', !empty($settings['enable']) && !empty($settings['allow']));
$display
->setThirdPartySetting('panelizer', 'default', $settings['default']);
if (!empty($settings['enable'])) {
// Set the default display.
$displays = $display
->getThirdPartySetting('panelizer', 'displays', []);
if (empty($displays['default'])) {
/** @var \Drupal\panelizer\Plugin\PanelizerEntityInterface $panelizer_entity_plugin */
$panelizer_entity_plugin = $this->panelizerEntityManager
->createInstance($display
->getTargetEntityTypeId(), []);
$displays['default'] = $this->panelsManager
->exportDisplay($panelizer_entity_plugin
->getDefaultDisplay($display, $display
->getTargetBundle(), $display
->getMode()));
$settings['default'] = "{$display->getTargetEntityTypeId()}__{$display->getTargetBundle()}__{$view_mode}__default";
$display
->setThirdPartySetting('panelizer', 'displays', $displays);
}
// Make sure the field exists.
if ($settings['custom'] || $settings['allow']) {
$field_storage = $this->entityTypeManager
->getStorage('field_storage_config')
->load($entity_type_id . '.panelizer');
if (!$field_storage) {
$field_storage = $this->entityTypeManager
->getStorage('field_storage_config')
->create([
'entity_type' => $entity_type_id,
'field_name' => 'panelizer',
'type' => 'panelizer',
'cardinality' => -1,
'settings' => [],
'status' => TRUE,
]);
$field_storage
->save();
}
$field = $this->entityTypeManager
->getStorage('field_config')
->load($entity_type_id . '.' . $bundle . '.panelizer');
if (!$field) {
$field = $this->entityTypeManager
->getStorage('field_config')
->create([
'field_storage' => $field_storage,
'bundle' => $bundle,
'label' => $this
->t('Panelizer'),
'settings' => [],
]);
$field
->save();
}
}
}
$display
->save();
}