public function PanelizerEntityBase::getDefaultDisplay in Panelizer 8.3
Same name and namespace in other branches
- 8.5 src/Plugin/PanelizerEntityBase.php \Drupal\panelizer\Plugin\PanelizerEntityBase::getDefaultDisplay()
- 8.4 src/Plugin/PanelizerEntityBase.php \Drupal\panelizer\Plugin\PanelizerEntityBase::getDefaultDisplay()
Creates a default Panels display from the core Entity display.
As much as possible, this should attempt to make the settings on the Panels display match the existing core settings, so that ideally the user doesn't notice any change upon Panelizing an entity's view mode.
Parameters
\Drupal\Core\Entity\Display\EntityViewDisplayInterface $display: The entity view display holding the display options configured for the entity components.
string $bundle: The bundle to panelize.
string $view_mode: The view mode to panelize.
Return value
\Drupal\panels\Plugin\DisplayVariant\PanelsDisplayVariant
Overrides PanelizerEntityInterface::getDefaultDisplay
3 methods override PanelizerEntityBase::getDefaultDisplay()
- PanelizerNode::getDefaultDisplay in src/
Plugin/ PanelizerEntity/ PanelizerNode.php - Creates a default Panels display from the core Entity display.
- PanelizerTerm::getDefaultDisplay in src/
Plugin/ PanelizerEntity/ PanelizerTerm.php - Creates a default Panels display from the core Entity display.
- PanelizerUser::getDefaultDisplay in src/
Plugin/ PanelizerEntity/ PanelizerUser.php - Creates a default Panels display from the core Entity display.
File
- src/
Plugin/ PanelizerEntityBase.php, line 65
Class
- PanelizerEntityBase
- Base class for Panelizer entity plugins.
Namespace
Drupal\panelizer\PluginCode
public function getDefaultDisplay(EntityViewDisplayInterface $display, $bundle, $view_mode) {
$panels_display = $this->panelsManager
->createDisplay();
$panels_display
->setConfiguration([
'label' => $this
->t('Default'),
] + $panels_display
->getConfiguration());
$panels_display
->setLayout('onecol');
// @todo: For now we always use the IPE, but we should support not using the ipe.
$panels_display
->setBuilder('ipe');
$panels_display
->setPattern('panelizer');
// Add all the visible fields to the Panel.
$entity_type_id = $this
->getPluginId();
/**
* @var string $field_name
* @var \Drupal\Core\Field\FieldDefinitionInterface $field_definition
*/
foreach ($this->entityFieldManager
->getFieldDefinitions($entity_type_id, $bundle) as $field_name => $field_definition) {
// Skip the Panelizer field.
if ($field_definition
->getType() == 'panelizer') {
continue;
}
if ($component = $display
->getComponent($field_name)) {
$weight = $component['weight'];
unset($component['weight']);
$panels_display
->addBlock([
'id' => 'entity_field:' . $entity_type_id . ':' . $field_name,
'label' => $field_definition
->getLabel(),
'provider' => 'ctools_block',
'label_display' => '0',
'formatter' => $component,
'context_mapping' => [
'entity' => '@panelizer.entity_context:entity',
],
'region' => 'middle',
'weight' => $weight,
]);
}
}
return $panels_display;
}