You are here

public function EntityDeriver::getDerivativeDefinitions in Drupal 8

Same name in this branch
  1. 8 core/modules/rest/src/Plugin/Deriver/EntityDeriver.php \Drupal\rest\Plugin\Deriver\EntityDeriver::getDerivativeDefinitions()
  2. 8 core/lib/Drupal/Core/Entity/Plugin/DataType/Deriver/EntityDeriver.php \Drupal\Core\Entity\Plugin\DataType\Deriver\EntityDeriver::getDerivativeDefinitions()
Same name and namespace in other branches
  1. 9 core/lib/Drupal/Core/Entity/Plugin/DataType/Deriver/EntityDeriver.php \Drupal\Core\Entity\Plugin\DataType\Deriver\EntityDeriver::getDerivativeDefinitions()
  2. 10 core/lib/Drupal/Core/Entity/Plugin/DataType/Deriver/EntityDeriver.php \Drupal\Core\Entity\Plugin\DataType\Deriver\EntityDeriver::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 DeriverInterface::getDerivativeDefinitions

See also

getDerivativeDefinition()

1 call to EntityDeriver::getDerivativeDefinitions()
EntityDeriver::getDerivativeDefinition in core/lib/Drupal/Core/Entity/Plugin/DataType/Deriver/EntityDeriver.php
Gets the definition of a derivative plugin.

File

core/lib/Drupal/Core/Entity/Plugin/DataType/Deriver/EntityDeriver.php, line 94

Class

EntityDeriver
Provides data type plugins for each existing entity type and bundle.

Namespace

Drupal\Core\Entity\Plugin\DataType\Deriver

Code

public function getDerivativeDefinitions($base_plugin_definition) {

  // Also keep the 'entity' defined as is.
  $this->derivatives[''] = $base_plugin_definition;

  // Add definitions for each entity type and bundle.
  foreach ($this->entityTypeManager
    ->getDefinitions() as $entity_type_id => $entity_type) {
    $class = $entity_type
      ->entityClassImplements(ConfigEntityInterface::class) ? ConfigEntityAdapter::class : EntityAdapter::class;
    $this->derivatives[$entity_type_id] = [
      'class' => $class,
      'label' => $entity_type
        ->getLabel(),
      'constraints' => $entity_type
        ->getConstraints(),
      'internal' => $entity_type
        ->isInternal(),
    ] + $base_plugin_definition;

    // Incorporate the bundles as entity:$entity_type:$bundle, if any.
    $bundle_info = $this->bundleInfoService
      ->getBundleInfo($entity_type_id);
    if (count($bundle_info) > 1 || $entity_type
      ->getKey('bundle')) {
      foreach ($bundle_info as $bundle => $info) {
        $this->derivatives[$entity_type_id . ':' . $bundle] = [
          'class' => $class,
          'label' => $info['label'],
          'constraints' => $this->derivatives[$entity_type_id]['constraints'],
        ] + $base_plugin_definition;
      }
    }
  }
  return $this->derivatives;
}