You are here

public function DefaultSelectionDeriver::getDerivativeDefinitions in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/lib/Drupal/Core/Entity/Plugin/Derivative/DefaultSelectionDeriver.php \Drupal\Core\Entity\Plugin\Derivative\DefaultSelectionDeriver::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

core/lib/Drupal/Core/Entity/Plugin/Derivative/DefaultSelectionDeriver.php, line 55
Contains \Drupal\Core\Entity\Plugin\Derivative\DefaultSelectionDeriver.

Class

DefaultSelectionDeriver
Provides derivative plugins for the DefaultSelection plugin.

Namespace

Drupal\Core\Entity\Plugin\Derivative

Code

public function getDerivativeDefinitions($base_plugin_definition) {
  foreach ($this->entityManager
    ->getDefinitions() as $entity_type_id => $entity_type) {
    $this->derivatives[$entity_type_id] = $base_plugin_definition;
    $this->derivatives[$entity_type_id]['entity_types'] = array(
      $entity_type_id,
    );
    $this->derivatives[$entity_type_id]['label'] = t('@entity_type selection', array(
      '@entity_type' => $entity_type
        ->getLabel(),
    ));
    $this->derivatives[$entity_type_id]['base_plugin_label'] = (string) $base_plugin_definition['label'];

    // If the entity type doesn't provide a 'label' key in its plugin
    // definition, we have to use the alternate PhpSelection class as default
    // plugin, which allows filtering the target entities by their label()
    // method. The major downside of PhpSelection is that it is more expensive
    // performance-wise than SelectionBase because it has to load all the
    // target entities in order to perform the filtering process, regardless
    // of whether a limit has been passed.
    // @see \Drupal\Core\Entity\Plugin\EntityReferenceSelection\PhpSelection
    if (!$entity_type
      ->hasKey('label')) {
      $this->derivatives[$entity_type_id]['class'] = 'Drupal\\Core\\Entity\\Plugin\\EntityReferenceSelection\\PhpSelection';
    }
  }
  return parent::getDerivativeDefinitions($base_plugin_definition);
}