class AttributeClassDiscoveryAutomatedProviders

Determines providers based on the namespaces of a class and its ancestors.

@internal This is a temporary solution to the fact that migration source plugins have more than one provider. This functionality will be moved to core in https://www.drupal.org/node/2786355.

Hierarchy

Expanded class hierarchy of AttributeClassDiscoveryAutomatedProviders

File

core/modules/migrate/src/Plugin/Discovery/AttributeClassDiscoveryAutomatedProviders.php, line 19

Namespace

Drupal\migrate\Plugin\Discovery
View source
class AttributeClassDiscoveryAutomatedProviders extends AttributeClassDiscovery {
  
  /**
   * Prepares the attribute definition.
   *
   * @param \Drupal\Component\Plugin\Attribute\AttributeInterface $attribute
   *   The attribute derived from the plugin.
   * @param string $class
   *   The class used for the plugin.
   *
   * @throws \LogicException
   *   When the attribute class does not allow for multiple providers.
   */
  protected function prepareAttributeDefinition(AttributeInterface $attribute, string $class) : void {
    if (!$attribute instanceof MultipleProviderAttributeInterface) {
      throw new \LogicException('AttributeClassDiscoveryAutomatedProviders must implement ' . MultipleProviderAttributeInterface::class);
    }
    // @see Drupal\Component\Plugin\Discovery\AttributeClassDiscovery::prepareAttributeDefinition()
    $attribute->setClass($class);
    // Loop through all the parent classes and add their providers (which we
    // infer by parsing their namespaces) to the $providers array.
    $providers = $attribute->getProviders();
    do {
      $providers[] = $this->getProviderFromNamespace($class);
    } while (($class = get_parent_class($class)) !== FALSE);
    $providers = array_diff(array_unique(array_filter($providers)), [
      'component',
    ]);
    $attribute->setProviders($providers);
  }

}

Members

Title Sort descending Modifiers Object type Summary Overriden Title Overrides
AttributeClassDiscovery::$directorySuffix protected property Suffix to append to each PSR-4 directory associated with a base namespace.
AttributeClassDiscovery::$fileCache protected property The file cache object.
AttributeClassDiscovery::$namespaceSuffix protected property A suffix to append to each base namespace.
AttributeClassDiscovery::$skipClasses protected static property An array of classes to skip.
AttributeClassDiscovery::getDefinitions public function Gets the definition of all plugins for this type. Overrides DiscoveryTrait::getDefinitions 1
AttributeClassDiscovery::getFileCacheSuffix protected function Gets the file cache suffix. 1
AttributeClassDiscovery::getPluginNamespaces protected function Gets an array of PSR-4 namespaces to search for plugin classes. Overrides AttributeClassDiscovery::getPluginNamespaces
AttributeClassDiscovery::getProviderFromNamespace protected function Extracts the provider name from a Drupal namespace.
AttributeClassDiscovery::parseClass protected function Parses attributes from a class. 1
AttributeClassDiscovery::__construct public function Constructs an AttributeClassDiscovery object. Overrides AttributeClassDiscovery::__construct 1
AttributeClassDiscoveryAutomatedProviders::prepareAttributeDefinition protected function Prepares the attribute definition. Overrides AttributeClassDiscovery::prepareAttributeDefinition
DiscoveryTrait::doGetDefinition protected function Gets a specific plugin definition.
DiscoveryTrait::getDefinition public function 3
DiscoveryTrait::hasDefinition public function

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