You are here

public function EntityAliasTypeDeriver::getDerivativeDefinitions in View Mode Page 3.2.x

Same name and namespace in other branches
  1. 8.3 src/Plugin/Derivative/EntityAliasTypeDeriver.php \Drupal\view_mode_page\Plugin\Derivative\EntityAliasTypeDeriver::getDerivativeDefinitions()
  2. 4.0.x src/Plugin/Derivative/EntityAliasTypeDeriver.php \Drupal\view_mode_page\Plugin\Derivative\EntityAliasTypeDeriver::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/EntityAliasTypeDeriver.php, line 78

Class

EntityAliasTypeDeriver
Deriver that exposes content entities as alias type plugins.

Namespace

Drupal\view_mode_page\Plugin\Derivative

Code

public function getDerivativeDefinitions($base_plugin_definition) {
  foreach ($this->entityTypeManager
    ->getDefinitions() as $entity_type_id => $entity_type) {

    // An entity type must have a canonical link template and support fields.
    if ($entity_type
      ->hasLinkTemplate('canonical') && is_subclass_of($entity_type
      ->getClass(), FieldableEntityInterface::class)) {
      $base_fields = $this->entityFieldManager
        ->getBaseFieldDefinitions($entity_type_id);
      if (!isset($base_fields['path'])) {

        // The entity type does not have a path field and is therefore not
        // supported.
        continue;
      }
      $this->derivatives[$entity_type_id] = $base_plugin_definition;
      $this->derivatives[$entity_type_id]['label'] = $entity_type
        ->getLabel();
      $this->derivatives[$entity_type_id]['types'] = [
        $this->tokenEntityMapper
          ->getTokenTypeForEntityType($entity_type_id),
      ];
      $this->derivatives[$entity_type_id]['provider'] = $entity_type
        ->getProvider();
      $this->derivatives[$entity_type_id]['context'] = [
        $entity_type_id => new ContextDefinition("entity:{$entity_type_id}", $this
          ->t('@label being aliased', [
          '@label' => $entity_type
            ->getLabel(),
        ])),
      ];
    }
  }
  return $this->derivatives;
}