entityTypeManager = $entity_type_manager; $this->entityFieldManager = $entity_field_manager; $this->stringTranslation = $string_translation; $this->tokenEntityMapper = $token_entity_mapper; } /** * {@inheritdoc} */ public static function create(ContainerInterface $container, $base_plugin_id) { return new static( $container->get('entity_type.manager'), $container->get('entity_field.manager'), $container->get('string_translation'), $container->get('token.entity_mapper') ); } /** * {@inheritdoc} */ 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; } }