1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Drupal\entity_embed\Plugin\Derivative; |
4
|
|
|
|
5
|
|
|
use Drupal\Component\Plugin\Derivative\DeriverBase; |
6
|
|
|
use Drupal\Core\Config\ConfigFactoryInterface; |
7
|
|
|
use Drupal\Core\Entity\EntityDisplayRepositoryInterface; |
8
|
|
|
use Drupal\Core\Plugin\Discovery\ContainerDeriverInterface; |
9
|
|
|
use Drupal\Core\StringTranslation\TranslatableMarkup; |
10
|
|
|
use Symfony\Component\DependencyInjection\ContainerInterface; |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* Provides Entity Embed Display plugin definitions for view modes. |
14
|
|
|
* |
15
|
|
|
* @see \Drupal\entity_embed\FieldFormatterEntityEmbedDisplayBase |
16
|
|
|
*/ |
17
|
|
|
class ViewModeDeriver extends DeriverBase implements ContainerDeriverInterface { |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* The entity display repository. |
21
|
|
|
* |
22
|
|
|
* @var \Drupal\Core\Entity\EntityDisplayRepositoryInterface |
23
|
|
|
*/ |
24
|
|
|
protected $entityDisplayRepository; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* The config factory service. |
28
|
|
|
* |
29
|
|
|
* @var \Drupal\Core\Config\ConfigFactoryInterface |
30
|
|
|
*/ |
31
|
|
|
protected $configFactory; |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* Constructs a ViewModeDeriver object. |
35
|
|
|
* |
36
|
|
|
* @param \Drupal\Core\Entity\EntityDisplayRepositoryInterface $entity_display_repository |
37
|
|
|
* The entity display repository. |
38
|
|
|
* @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory |
39
|
|
|
* A config factory for retrieving required config objects. |
40
|
|
|
*/ |
41
|
|
|
public function __construct(EntityDisplayRepositoryInterface $entity_display_repository, ConfigFactoryInterface $config_factory) { |
42
|
|
|
$this->entityDisplayRepository = $entity_display_repository; |
43
|
|
|
$this->configFactory = $config_factory; |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* {@inheritdoc} |
48
|
|
|
*/ |
49
|
|
|
public static function create(ContainerInterface $container, $base_plugin_id) { |
50
|
|
|
return new static( |
51
|
|
|
$container->get('entity_display.repository'), |
52
|
|
|
$container->get('config.factory') |
53
|
|
|
); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* {@inheritdoc} |
58
|
|
|
*/ |
59
|
|
|
public function getDerivativeDefinitions($base_plugin_definition) { |
60
|
|
|
$mode = $this->configFactory->get('entity_embed.settings')->get('rendered_entity_mode'); |
61
|
|
|
foreach ($this->entityDisplayRepository->getAllViewModes() as $view_modes) { |
62
|
|
|
foreach ($view_modes as $view_mode => $definition) { |
63
|
|
|
$this->derivatives[$definition['id']] = $base_plugin_definition; |
64
|
|
|
$this->derivatives[$definition['id']]['label'] = new TranslatableMarkup($definition['label']); |
65
|
|
|
$this->derivatives[$definition['id']]['view_mode'] = $view_mode; |
66
|
|
|
$this->derivatives[$definition['id']]['entity_types'] = $definition['targetEntityType']; |
67
|
|
|
$this->derivatives[$definition['id']]['no_ui'] = $mode; |
68
|
|
|
} |
69
|
|
|
} |
70
|
|
|
return $this->derivatives; |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
} |
74
|
|
|
|