abstract class PanelizerEntityBase in Panelizer 8.4
Same name and namespace in other branches
- 8.5 src/Plugin/PanelizerEntityBase.php \Drupal\panelizer\Plugin\PanelizerEntityBase
- 8.3 src/Plugin/PanelizerEntityBase.php \Drupal\panelizer\Plugin\PanelizerEntityBase
Base class for Panelizer entity plugins.
Hierarchy
- class \Drupal\Component\Plugin\PluginBase implements DerivativeInspectionInterface, PluginInspectionInterface
- class \Drupal\panelizer\Plugin\PanelizerEntityBase implements ContainerFactoryPluginInterface, PanelizerEntityInterface uses StringTranslationTrait
Expanded class hierarchy of PanelizerEntityBase
3 files declare their use of PanelizerEntityBase
- PanelizerNode.php in src/
Plugin/ PanelizerEntity/ PanelizerNode.php - PanelizerTerm.php in src/
Plugin/ PanelizerEntity/ PanelizerTerm.php - PanelizerUser.php in src/
Plugin/ PanelizerEntity/ PanelizerUser.php
File
- src/
Plugin/ PanelizerEntityBase.php, line 18
Namespace
Drupal\panelizer\PluginView source
abstract class PanelizerEntityBase extends PluginBase implements PanelizerEntityInterface, ContainerFactoryPluginInterface {
use StringTranslationTrait;
/**
* @var \Drupal\Panels\PanelsDisplayManager
*/
protected $panelsManager;
/**
* @var \Drupal\Core\Entity\EntityFieldManagerInterface
*/
protected $entityFieldManager;
/**
* @param array $configuration
* A configuration array containing information about the plugin instance.
* @param string $plugin_id
* The plugin_id for the plugin instance.
* @param mixed $plugin_definition
* The plugin implementation definition.
* @param \Drupal\Panels\PanelsDisplayManager $panels_manager
* The Panels display manager.
* @param \Drupal\Core\Entity\EntityFieldManagerInterface $entity_field_manager
* The entity field manager.
*/
public function __construct(array $configuration, $plugin_id, $plugin_definition, PanelsDisplayManager $panels_manager, EntityFieldManagerInterface $entity_field_manager) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
$this->panelsManager = $panels_manager;
$this->entityFieldManager = $entity_field_manager;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
return new static($configuration, $plugin_id, $plugin_definition, $container
->get('panels.display_manager'), $container
->get('entity_field.manager'));
}
/**
* {@inheritdoc}
*/
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('layout_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' => 'content',
'weight' => $weight,
]);
}
}
return $panels_display;
}
/**
* {@inheritdoc}
*/
public function alterBuild(array &$build, EntityInterface $entity, PanelsDisplayVariant $panels_display, $view_mode) {
// By default, do nothing!
}
/**
* {@inheritdoc}
*/
public function preprocessViewMode(array &$variables, EntityInterface $entity, PanelsDisplayVariant $panels_display, $view_mode) {
$entity_type_id = $this
->getPluginId();
// Add some default classes.
$variables['attributes']['class'][] = $entity_type_id;
$variables['attributes']['class'][] = $entity_type_id . '--type-' . $entity
->bundle();
$variables['attributes']['class'][] = $entity_type_id . '--view-mode-' . $view_mode;
$variables['attributes']['class'][] = 'clearfix';
// Don't render the title in the template
if ($view_mode == 'full') {
$variables['title'] = '';
}
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
PanelizerEntityBase:: |
protected | property | ||
PanelizerEntityBase:: |
protected | property | ||
PanelizerEntityBase:: |
public | function |
Alter the built entity view in an entity specific way before rendering. Overrides PanelizerEntityInterface:: |
3 |
PanelizerEntityBase:: |
public static | function |
Creates an instance of the plugin. Overrides ContainerFactoryPluginInterface:: |
|
PanelizerEntityBase:: |
public | function |
Creates a default Panels display from the core Entity display. Overrides PanelizerEntityInterface:: |
3 |
PanelizerEntityBase:: |
public | function |
Preprocess the variables for the view mode template. Overrides PanelizerEntityInterface:: |
1 |
PanelizerEntityBase:: |
public | function |
Overrides PluginBase:: |
|
PluginBase:: |
protected | property | Configuration information passed into the plugin. | 1 |
PluginBase:: |
protected | property | The plugin implementation definition. | 1 |
PluginBase:: |
protected | property | The plugin_id. | |
PluginBase:: |
constant | A string which is used to separate base plugin IDs from the derivative ID. | ||
PluginBase:: |
public | function |
Gets the base_plugin_id of the plugin instance. Overrides DerivativeInspectionInterface:: |
|
PluginBase:: |
public | function |
Gets the derivative_id of the plugin instance. Overrides DerivativeInspectionInterface:: |
|
PluginBase:: |
public | function |
Gets the definition of the plugin implementation. Overrides PluginInspectionInterface:: |
3 |
PluginBase:: |
public | function |
Gets the plugin_id of the plugin instance. Overrides PluginInspectionInterface:: |
|
PluginBase:: |
public | function | Determines if the plugin is configurable. | |
StringTranslationTrait:: |
protected | property | The string translation service. | 1 |
StringTranslationTrait:: |
protected | function | Formats a string containing a count of items. | |
StringTranslationTrait:: |
protected | function | Returns the number of plurals supported by a given language. | |
StringTranslationTrait:: |
protected | function | Gets the string translation service. | |
StringTranslationTrait:: |
public | function | Sets the string translation service to use. | 2 |
StringTranslationTrait:: |
protected | function | Translates a string to the current language or to a given language. |