function AnnotatedDiscoveryAutomatedProvidersTrait::prepareAnnotationDefinition

Prepares the annotation definition.

This is modified from the prepareAnnotationDefinition method from annotated class discovery to account for multiple providers.

Parameters

\Drupal\Component\Annotation\AnnotationInterface $annotation: The annotation derived from the plugin.

class-string $class: The class used for the plugin.

\Drupal\Component\Annotation\Doctrine\StaticReflectionParser|null $parser: Static reflection parser.

See also

\Drupal\Component\Annotation\Plugin\Discovery\AnnotatedClassDiscovery::prepareAnnotationDefinition()

\Drupal\Core\Plugin\Discovery\AnnotatedClassDiscovery::prepareAnnotationDefinition()

2 calls to AnnotatedDiscoveryAutomatedProvidersTrait::prepareAnnotationDefinition()
AnnotatedClassDiscoveryAutomatedProviders::getDefinitions in core/modules/migrate/src/Plugin/Discovery/AnnotatedClassDiscoveryAutomatedProviders.php
Gets the definition of all plugins for this type.
AttributeDiscoveryWithAnnotationsAutomatedProviders::parseClass in core/modules/migrate/src/Plugin/Discovery/AttributeDiscoveryWithAnnotationsAutomatedProviders.php
Parses attributes from a class.

File

core/modules/migrate/src/Plugin/Discovery/AnnotatedDiscoveryAutomatedProvidersTrait.php, line 41

Class

AnnotatedDiscoveryAutomatedProvidersTrait
Provides method for annotation discovery with multiple providers.

Namespace

Drupal\migrate\Plugin\Discovery

Code

protected function prepareAnnotationDefinition(AnnotationInterface $annotation, $class, ?BaseStaticReflectionParser $parser = NULL) : void {
  if (!$annotation instanceof MultipleProviderAnnotationInterface) {
    throw new \LogicException('AnnotatedClassDiscoveryAutomatedProviders annotations must implement ' . MultipleProviderAnnotationInterface::class);
  }
  if (!$parser) {
    throw new \LogicException('Parser argument must be passed for automated providers discovery.');
  }
  if (!method_exists($this, 'getProviderFromNamespace')) {
    throw new \LogicException('Classes using \\Drupal\\migrate\\Plugin\\Discovery\\AnnotatedDiscoveryAutomatedProvidersTrait must have getProviderFromNamespace() method.');
  }
  // @see \Drupal\Component\Annotation\Plugin\Discovery\AnnotatedClassDiscovery::prepareAnnotationDefinition()
  $annotation->setClass($class);
  $providers = $annotation->getProviders();
  // Loop through all the parent classes and add their providers (which we
  // infer by parsing their namespaces) to the $providers array.
  do {
    $providers[] = $this->getProviderFromNamespace($parser->getNamespaceName());
  } while ($parser = StaticReflectionParser::getParentParser($parser, $this->finder));
  $providers = array_diff(array_unique(array_filter($providers)), [
    'component',
  ]);
  $annotation->setProviders($providers);
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.