class ViewModeDeriver in Entity Embed 8
Provides Entity Embed Display plugin definitions for view modes.
Hierarchy
- class \Drupal\Component\Plugin\Derivative\DeriverBase implements DeriverInterface
- class \Drupal\entity_embed\Plugin\Derivative\ViewModeDeriver implements ContainerDeriverInterface
Expanded class hierarchy of ViewModeDeriver
See also
\Drupal\entity_embed\FieldFormatterEntityEmbedDisplayBase
File
- src/
Plugin/ Derivative/ ViewModeDeriver.php, line 16
Namespace
Drupal\entity_embed\Plugin\DerivativeView source
class ViewModeDeriver extends DeriverBase implements ContainerDeriverInterface {
/**
* The entity display repository.
*
* @var \Drupal\Core\Entity\EntityDisplayRepositoryInterface
*/
protected $entityDisplayRepository;
/**
* The config factory service.
*
* @var \Drupal\Core\Config\ConfigFactoryInterface
*/
protected $configFactory;
/**
* Constructs a ViewModeDeriver object.
*
* @param \Drupal\Core\Entity\EntityDisplayRepositoryInterface $entity_display_repository
* The entity display repository.
* @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory
* A config factory for retrieving required config objects.
*/
public function __construct(EntityDisplayRepositoryInterface $entity_display_repository, ConfigFactoryInterface $config_factory) {
$this->entityDisplayRepository = $entity_display_repository;
$this->configFactory = $config_factory;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container, $base_plugin_id) {
return new static($container
->get('entity_display.repository'), $container
->get('config.factory'));
}
/**
* {@inheritdoc}
*/
public function getDerivativeDefinitions($base_plugin_definition) {
$no_ui = $this->configFactory
->get('entity_embed.settings')
->get('rendered_entity_mode');
foreach ($this->entityDisplayRepository
->getAllViewModes() as $view_modes) {
foreach ($view_modes as $view_mode => $definition) {
$this->derivatives[$definition['id']] = [
'label' => $definition['label'],
'view_mode' => $view_mode,
'entity_types' => [
$definition['targetEntityType'],
],
'no_ui' => $no_ui,
// Check if the plugin should run through MediaImageDecorator. A more
// fine-grained access check happens there.
'supports_image_alt_and_title' => $definition['targetEntityType'] === 'media',
] + $base_plugin_definition;
}
}
return $this->derivatives;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
DeriverBase:: |
protected | property | List of derivative definitions. | 1 |
DeriverBase:: |
public | function |
Gets the definition of a derivative plugin. Overrides DeriverInterface:: |
|
ViewModeDeriver:: |
protected | property | The config factory service. | |
ViewModeDeriver:: |
protected | property | The entity display repository. | |
ViewModeDeriver:: |
public static | function |
Creates a new class instance. Overrides ContainerDeriverInterface:: |
|
ViewModeDeriver:: |
public | function |
Gets the definition of all derivatives of a base plugin. Overrides DeriverBase:: |
|
ViewModeDeriver:: |
public | function | Constructs a ViewModeDeriver object. |