function AttributeClassDiscovery::getClassDependencies

Same name in this branch
  1. main core/lib/Drupal/Component/Plugin/Discovery/AttributeClassDiscovery.php \Drupal\Component\Plugin\Discovery\AttributeClassDiscovery::getClassDependencies()
Same name and namespace in other branches
  1. 11.x core/lib/Drupal/Core/Plugin/Discovery/AttributeClassDiscovery.php \Drupal\Core\Plugin\Discovery\AttributeClassDiscovery::getClassDependencies()
  2. 11.x core/lib/Drupal/Component/Plugin/Discovery/AttributeClassDiscovery.php \Drupal\Component\Plugin\Discovery\AttributeClassDiscovery::getClassDependencies()

File

core/lib/Drupal/Core/Plugin/Discovery/AttributeClassDiscovery.php, line 127

Class

AttributeClassDiscovery
Defines a discovery mechanism to find plugins using attributes.

Namespace

Drupal\Core\Plugin\Discovery

Code

protected function getClassDependencies(\ReflectionClass $reflection_class) : ?array {
  if (!$dependencies = parent::getClassDependencies($reflection_class)) {
    return NULL;
  }
  // Get the providers from all the class namespaces. Exclude 'component',
  // 'core', and the provider for the plugin class itself, since none of those
  // providers will ever be missing.
  $class_provider = $this->getProviderFromNamespace($reflection_class->getName());
  $providers = [];
  foreach ($dependencies as $type_dependencies) {
    foreach ($type_dependencies as $dependency) {
      if (($provider = $this->getProviderFromNamespace($dependency)) && $provider !== $class_provider && !in_array($provider, [
        'component',
        'core',
      ]) && !in_array($provider, $providers)) {
        $providers[] = $provider;
      }
    }
  }
  if ($providers) {
    // Only need to return providers here.
    return [
      'provider' => $providers,
    ];
  }
  return NULL;
}

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