You are here

protected function DerivativeDiscoveryDecorator::getDerivatives in Plug 7

Adds derivatives to a list of plugin definitions.

This should be called by the class extending this in DiscoveryInterface::getDefinitions().

1 call to DerivativeDiscoveryDecorator::getDerivatives()
DerivativeDiscoveryDecorator::getDefinitions in lib/Drupal/Component/Plugin/Discovery/DerivativeDiscoveryDecorator.php

File

lib/Drupal/Component/Plugin/Discovery/DerivativeDiscoveryDecorator.php, line 100
Contains \Drupal\Component\Plugin\Discovery\DerivativeDiscoveryDecorator.

Class

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

Namespace

Drupal\Component\Plugin\Discovery

Code

protected function getDerivatives(array $base_plugin_definitions) {
  $plugin_definitions = array();
  foreach ($base_plugin_definitions as $base_plugin_id => $plugin_definition) {
    $deriver = $this
      ->getDeriver($base_plugin_id, $plugin_definition);
    if ($deriver) {
      $derivative_definitions = $deriver
        ->getDerivativeDefinitions($plugin_definition);
      foreach ($derivative_definitions as $derivative_id => $derivative_definition) {
        $plugin_id = $this
          ->encodePluginId($base_plugin_id, $derivative_id);

        // Use this definition as defaults if a plugin already defined
        // itself as this derivative.
        if ($derivative_id && isset($base_plugin_definitions[$plugin_id])) {
          $derivative_definition = $this
            ->mergeDerivativeDefinition($base_plugin_definitions[$plugin_id], $derivative_definition);
        }
        $plugin_definitions[$plugin_id] = $derivative_definition;
      }
    }
    elseif (!isset($plugin_definitions[$base_plugin_id])) {
      $plugin_definitions[$base_plugin_id] = $plugin_definition;
    }
  }
  return $plugin_definitions;
}