function AttributeDiscoveryWithAnnotations::parseClass

Same name and namespace in other branches
  1. 10 core/lib/Drupal/Core/Plugin/Discovery/AttributeDiscoveryWithAnnotations.php \Drupal\Core\Plugin\Discovery\AttributeDiscoveryWithAnnotations::parseClass()

Parses attributes from a class.

Parameters

class-string $class: The class to parse.

\SplFileInfo $fileinfo: The SPL file information for the class.

Return value

array An array with the keys 'id' and 'content'. The 'id' is the plugin ID and 'content' is the plugin definition.

Overrides AttributeClassDiscovery::parseClass

1 method overrides AttributeDiscoveryWithAnnotations::parseClass()
AttributeDiscoveryWithAnnotationsAutomatedProviders::parseClass in core/modules/migrate/src/Plugin/Discovery/AttributeDiscoveryWithAnnotationsAutomatedProviders.php
Parses attributes from a class.

File

core/lib/Drupal/Core/Plugin/Discovery/AttributeDiscoveryWithAnnotations.php, line 77

Class

AttributeDiscoveryWithAnnotations
Enables both attribute and annotation discovery for plugin definitions.

Namespace

Drupal\Core\Plugin\Discovery

Code

protected function parseClass(string $class, \SplFileInfo $fileinfo) : array {
  // Parse using attributes first.
  $definition = parent::parseClass($class, $fileinfo);
  if (isset($definition['id'])) {
    return $definition;
  }
  // The filename is already known, so there is no need to find the
  // file. However, StaticReflectionParser needs a finder, so use a
  // mock version.
  $finder = MockFileFinder::create($fileinfo->getPathName());
  $parser = new StaticReflectionParser($class, $finder, TRUE);
  $reflection_class = $parser->getReflectionClass();
  /** @var \Drupal\Component\Annotation\AnnotationInterface $annotation */
  if ($annotation = $this->getAnnotationReader()
    ->getClassAnnotation($reflection_class, $this->pluginDefinitionAnnotationName)) {
    $this->prepareAnnotationDefinition($annotation, $class);
    $id = $annotation->getId();
    $shortened_annotation_name = '@' . substr($this->pluginDefinitionAnnotationName, strrpos($this->pluginDefinitionAnnotationName, '\\') + 1);
    // phpcs:ignore
    @trigger_error(sprintf('Using %s annotation for plugin with ID %s is deprecated and is removed from drupal:13.0.0. Use a %s attribute instead. See https://www.drupal.org/node/3395575', $shortened_annotation_name, $id, $this->pluginDefinitionAttributeName), E_USER_DEPRECATED);
    return [
      'id' => $id,
      'content' => $annotation->get(),
    ];
  }
  return [
    'id' => NULL,
    'content' => NULL,
  ];
}

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