function AttributeClassDiscoveryAutomatedProviders::prepareAttributeDefinition

Prepares the attribute definition.

Parameters

\Drupal\Component\Plugin\Attribute\AttributeInterface $attribute: The attribute derived from the plugin.

string $class: The class used for the plugin.

Throws

\LogicException When the attribute class does not allow for multiple providers.

Overrides AttributeClassDiscovery::prepareAttributeDefinition

File

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

Class

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

Namespace

Drupal\migrate\Plugin\Discovery

Code

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);
}

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