You are here

public function EntityReferenceField::getDerivativeDefinitions in Synonyms 2.0.x

Same name and namespace in other branches
  1. 8 src/Plugin/Derivative/EntityReferenceField.php \Drupal\synonyms\Plugin\Derivative\EntityReferenceField::getDerivativeDefinitions()

Gets the definition of all derivatives of a base plugin.

Parameters

array $base_plugin_definition: The definition array of the base plugin.

Return value

array An array of full derivative definitions keyed on derivative id.

Overrides DeriverBase::getDerivativeDefinitions

See also

getDerivativeDefinition()

File

src/Plugin/Derivative/EntityReferenceField.php, line 62

Class

EntityReferenceField
Derivative for entity_reference synonyms provider plugin.

Namespace

Drupal\synonyms\Plugin\Derivative

Code

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;
}