You are here

public function EntityMatcherDeriver::getDerivativeDefinitions in Linkit 8.5

Same name and namespace in other branches
  1. 8.4 src/Plugin/Derivative/EntityMatcherDeriver.php \Drupal\linkit\Plugin\Derivative\EntityMatcherDeriver::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/EntityMatcherDeriver.php, line 47

Class

EntityMatcherDeriver
Provides matchers based on active entities.

Namespace

Drupal\linkit\Plugin\Derivative

Code

public function getDerivativeDefinitions($base_plugin_definition) {
  foreach ($this->entityTypeManager
    ->getDefinitions() as $entity_type_id => $entity_type) {
    $canonical = $entity_type
      ->getLinkTemplate('canonical');
    $edit_form = $entity_type
      ->getLinkTemplate('edit-form');

    // Only entities that has a distinct canonical URI that is not the same
    // as the edit-form URI will be derived.
    if ($entity_type instanceof ContentEntityTypeInterface && $canonical && $canonical !== $edit_form || $entity_type_id === 'media') {
      $this->derivatives[$entity_type_id] = $base_plugin_definition;
      $this->derivatives[$entity_type_id]['id'] = $base_plugin_definition['id'] . ':' . $entity_type_id;
      $this->derivatives[$entity_type_id]['label'] = $entity_type
        ->getLabel();
      $this->derivatives[$entity_type_id]['target_entity'] = $entity_type_id;
      $this->derivatives[$entity_type_id]['base_plugin_label'] = (string) $base_plugin_definition['label'];
    }
  }
  return parent::getDerivativeDefinitions($base_plugin_definition);
}