function DerivativeDiscoveryDecorator::getDeriverClass

Same name and namespace in other branches
  1. 9 core/lib/Drupal/Component/Plugin/Discovery/DerivativeDiscoveryDecorator.php \Drupal\Component\Plugin\Discovery\DerivativeDiscoveryDecorator::getDeriverClass()
  2. 8.9.x core/lib/Drupal/Component/Plugin/Discovery/DerivativeDiscoveryDecorator.php \Drupal\Component\Plugin\Discovery\DerivativeDiscoveryDecorator::getDeriverClass()
  3. 10 core/lib/Drupal/Component/Plugin/Discovery/DerivativeDiscoveryDecorator.php \Drupal\Component\Plugin\Discovery\DerivativeDiscoveryDecorator::getDeriverClass()

Gets the deriver class name from the base plugin definition.

Parameters

array $base_definition: The base plugin definition to build derivatives.

Return value

string|null The name of a class implementing \Drupal\Component\Plugin\Derivative\DeriverInterface.

Throws

\Drupal\Component\Plugin\Exception\InvalidDeriverException Thrown if the 'deriver' class specified in the plugin definition does not implement \Drupal\Component\Plugin\Derivative\DerivativeInterface.

2 calls to DerivativeDiscoveryDecorator::getDeriverClass()
ContainerDerivativeDiscoveryDecorator::getDeriver in core/lib/Drupal/Core/Plugin/Discovery/ContainerDerivativeDiscoveryDecorator.php
Gets a deriver for a base plugin.
DerivativeDiscoveryDecorator::getDeriver in core/lib/Drupal/Component/Plugin/Discovery/DerivativeDiscoveryDecorator.php
Gets a deriver for a base plugin.

File

core/lib/Drupal/Component/Plugin/Discovery/DerivativeDiscoveryDecorator.php, line 205

Class

DerivativeDiscoveryDecorator
Base class providing the tools for a plugin discovery to be derivative aware.

Namespace

Drupal\Component\Plugin\Discovery

Code

protected function getDeriverClass($base_definition) {
    $class = NULL;
    $id = NULL;
    if ($base_definition instanceof DerivablePluginDefinitionInterface) {
        $class = $base_definition->getDeriver();
        $id = $base_definition->id();
    }
    if ((is_array($base_definition) || ($base_definition = (array) $base_definition)) && isset($base_definition['deriver'])) {
        $class = $base_definition['deriver'];
        $id = $base_definition['id'];
    }
    if ($class) {
        if (!class_exists($class)) {
            throw new InvalidDeriverException(sprintf('Plugin (%s) deriver "%s" does not exist.', $id, $class));
        }
        if (!is_subclass_of($class, '\\Drupal\\Component\\Plugin\\Derivative\\DeriverInterface')) {
            throw new InvalidDeriverException(sprintf('Plugin (%s) deriver "%s" must implement \\Drupal\\Component\\Plugin\\Derivative\\DeriverInterface.', $id, $class));
        }
    }
    return $class;
}

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