class EntityReferenceField in Synonyms 2.0.x
Same name in this branch
- 2.0.x src/Plugin/Derivative/EntityReferenceField.php \Drupal\synonyms\Plugin\Derivative\EntityReferenceField
- 2.0.x src/Plugin/Synonyms/Provider/EntityReferenceField.php \Drupal\synonyms\Plugin\Synonyms\Provider\EntityReferenceField
Same name and namespace in other branches
- 8 src/Plugin/Derivative/EntityReferenceField.php \Drupal\synonyms\Plugin\Derivative\EntityReferenceField
Derivative for entity_reference synonyms provider plugin.
Hierarchy
- class \Drupal\Component\Plugin\Derivative\DeriverBase implements DeriverInterface
- class \Drupal\synonyms\Plugin\Derivative\EntityReferenceField implements ContainerDeriverInterface
Expanded class hierarchy of EntityReferenceField
File
- src/
Plugin/ Derivative/ EntityReferenceField.php, line 16
Namespace
Drupal\synonyms\Plugin\DerivativeView source
class EntityReferenceField extends DeriverBase implements ContainerDeriverInterface {
/**
* The entity type manager.
*
* @var \Drupal\Core\Entity\EntityTypeManagerInterface
*/
protected $entityTypeManager;
/**
* The entity type bundle info.
*
* @var \Drupal\Core\Entity\EntityTypeBundleInfoInterface
*/
protected $entityTypeBundleInfo;
/**
* The entity field manager.
*
* @var \Drupal\Core\Entity\EntityFieldManagerInterface
*/
protected $entityFieldManager;
/**
* EntityReferenceField constructor.
*/
public function __construct(EntityTypeManagerInterface $entity_type_manager, EntityTypeBundleInfoInterface $entity_type_bundle_info, EntityFieldManagerInterface $entity_field_manager) {
$this->entityTypeManager = $entity_type_manager;
$this->entityTypeBundleInfo = $entity_type_bundle_info;
$this->entityFieldManager = $entity_field_manager;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container, $base_plugin_id) {
return new static($container
->get('entity_type.manager'), $container
->get('entity_type.bundle.info'), $container
->get('entity_field.manager'));
}
/**
* {@inheritdoc}
*/
public function getDerivativeDefinitions($base_plugin_definition) {
foreach ($this->entityTypeManager
->getDefinitions() as $entity_type) {
if ($entity_type instanceof ContentEntityType) {
foreach ($this->entityTypeBundleInfo
->getBundleInfo($entity_type
->id()) as $bundle => $bundle_info) {
$fields = $this->entityFieldManager
->getFieldDefinitions($entity_type
->id(), $bundle);
foreach ($fields as $field) {
if ($field
->getType() == 'entity_reference') {
$derivative_name = implode('.', [
$entity_type
->id(),
$bundle,
$field
->getName(),
]);
$this->derivatives[$derivative_name] = $base_plugin_definition;
$this->derivatives[$derivative_name]['label'] = $field
->getLabel();
$this->derivatives[$derivative_name]['controlled_entity_type'] = $entity_type
->id();
$this->derivatives[$derivative_name]['controlled_bundle'] = $bundle;
$this->derivatives[$derivative_name]['field'] = $field
->getName();
}
}
}
}
}
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:: |
|
EntityReferenceField:: |
protected | property | The entity field manager. | |
EntityReferenceField:: |
protected | property | The entity type bundle info. | |
EntityReferenceField:: |
protected | property | The entity type manager. | |
EntityReferenceField:: |
public static | function |
Creates a new class instance. Overrides ContainerDeriverInterface:: |
|
EntityReferenceField:: |
public | function |
Gets the definition of all derivatives of a base plugin. Overrides DeriverBase:: |
|
EntityReferenceField:: |
public | function | EntityReferenceField constructor. |