You are here

protected function ContainerDerivativeDiscoveryDecorator::getDeriver in Plug 7

Gets a deriver for a base plugin.

Parameters

string $base_plugin_id: The base plugin id of the plugin.

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

Return value

\Drupal\Component\Plugin\Derivative\DeriverInterface|null A DerivativeInterface or NULL if none exists for the plugin.

Throws

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

Overrides DerivativeDiscoveryDecorator::getDeriver

File

lib/Drupal/Core/Plugin/Discovery/ContainerDerivativeDiscoveryDecorator.php, line 17
Contains \Drupal\Core\Plugin\Discovery\ContainerDerivativeDiscoveryDecorator.

Class

ContainerDerivativeDiscoveryDecorator

Namespace

Drupal\Core\Plugin\Discovery

Code

protected function getDeriver($base_plugin_id, $base_definition) {
  if (!isset($this->derivers[$base_plugin_id])) {
    $this->derivers[$base_plugin_id] = FALSE;
    $class = $this
      ->getDeriverClass($base_definition);
    if ($class) {

      // If the deriver provides a factory method, pass the container to it.
      if (is_subclass_of($class, '\\Drupal\\Core\\Plugin\\Discovery\\ContainerDeriverInterface')) {

        /** @var \Drupal\Core\Plugin\Discovery\ContainerDeriverInterface $class */
        $this->derivers[$base_plugin_id] = $class::create(\Drupal::getContainer(), $base_plugin_id);
      }
      else {
        $this->derivers[$base_plugin_id] = new $class($base_plugin_id);
      }
    }
  }
  return $this->derivers[$base_plugin_id] ?: NULL;
}