1 | <?php |
||
18 | abstract class EntityFieldDeriverBase extends DeriverBase implements ContainerDeriverInterface { |
||
19 | use DependencySerializationTrait; |
||
20 | |||
21 | /** |
||
22 | * Provides plugin definition values from fields. |
||
23 | * |
||
24 | * @param string $entityTypeId |
||
25 | * The host entity type. |
||
26 | * @param \Drupal\Core\Field\FieldStorageDefinitionInterface $fieldDefinition |
||
27 | * Field definition object. |
||
28 | * @param array $basePluginDefinition |
||
29 | * Base definition array. |
||
30 | */ |
||
31 | abstract protected function getDerivativeDefinitionsFromFieldDefinition($entityTypeId, FieldStorageDefinitionInterface $fieldDefinition, array $basePluginDefinition); |
||
32 | |||
33 | /** |
||
34 | * The entity type manager. |
||
35 | * |
||
36 | * @var \Drupal\Core\Entity\EntityTypeManagerInterface |
||
37 | */ |
||
38 | protected $entityTypeManager; |
||
39 | |||
40 | /** |
||
41 | * The entity field manager. |
||
42 | * |
||
43 | * @var \Drupal\Core\Entity\EntityFieldManagerInterface |
||
44 | */ |
||
45 | protected $entityFieldManager; |
||
46 | |||
47 | /** |
||
48 | * The entity bundle info. |
||
49 | * |
||
50 | * @var \Drupal\Core\Entity\EntityTypeBundleInfoInterface |
||
51 | */ |
||
52 | protected $entityBundleInfo; |
||
53 | |||
54 | /** |
||
55 | * The base plugin id. |
||
56 | * |
||
57 | * @var string |
||
58 | */ |
||
59 | protected $basePluginId; |
||
60 | |||
61 | /** |
||
62 | * {@inheritdoc} |
||
63 | */ |
||
64 | public static function create(ContainerInterface $container, $basePluginId) { |
||
65 | return new static( |
||
66 | $container->get('entity_type.manager'), |
||
67 | $container->get('entity_field.manager'), |
||
68 | $container->get('entity_type.bundle.info'), |
||
69 | $basePluginId |
||
70 | ); |
||
71 | } |
||
72 | |||
73 | /** |
||
74 | * RawValueFieldItemDeriver constructor. |
||
75 | * |
||
76 | * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entityTypeManager |
||
77 | * The entity type manager. |
||
78 | * @param \Drupal\Core\Entity\EntityFieldManagerInterface $entityFieldManager |
||
79 | * The entity field manager. |
||
80 | * @param \Drupal\Core\Entity\EntityTypeBundleInfoInterface $entityTypeBundleInfo |
||
81 | * The bundle info service. |
||
82 | * @param string $basePluginId |
||
83 | * The base plugin id. |
||
84 | */ |
||
85 | public function __construct( |
||
86 | EntityTypeManagerInterface $entityTypeManager, |
||
87 | EntityFieldManagerInterface $entityFieldManager, |
||
88 | EntityTypeBundleInfoInterface $entityTypeBundleInfo, |
||
89 | $basePluginId |
||
90 | ) { |
||
91 | $this->basePluginId = $basePluginId; |
||
92 | $this->entityTypeManager = $entityTypeManager; |
||
93 | $this->entityFieldManager = $entityFieldManager; |
||
94 | $this->entityBundleInfo = $entityTypeBundleInfo; |
||
95 | } |
||
96 | |||
97 | /** |
||
98 | * {@inheritdoc} |
||
99 | */ |
||
100 | public function getDerivativeDefinitions($basePluginDefinition) { |
||
101 | foreach ($this->entityTypeManager->getDefinitions() as $entityTypeId => $entityType) { |
||
102 | $interfaces = class_implements($entityType->getClass()); |
||
103 | if (!array_key_exists(FieldableEntityInterface::class, $interfaces)) { |
||
104 | continue; |
||
105 | } |
||
106 | |||
107 | foreach ($this->entityFieldManager->getFieldStorageDefinitions($entityTypeId) as $fieldStorageDefinition) { |
||
108 | if ($derivatives = $this->getDerivativeDefinitionsFromFieldDefinition($entityTypeId, $fieldStorageDefinition, $basePluginDefinition)) { |
||
109 | $this->derivatives = array_merge($this->derivatives, $derivatives); |
||
110 | } |
||
111 | } |
||
112 | } |
||
113 | |||
114 | return $this->derivatives; |
||
115 | } |
||
116 | |||
117 | /** |
||
118 | * Tells if given field has just a single property. |
||
119 | * |
||
120 | * @param \Drupal\Core\Field\FieldStorageDefinitionInterface $definition |
||
121 | * Field definition. |
||
122 | * |
||
123 | * @return bool |
||
124 | */ |
||
125 | protected function isSinglePropertyField(FieldStorageDefinitionInterface $definition) { |
||
129 | |||
130 | } |
||
131 |