abstract class LegacyDiscoveryDecorator

Custom decorator to add legacy plugins.

Legacy plugins are discovered through Drupal\Core\Plugin\Discovery\HookDiscovery, and handled by a legacy class.

Hierarchy

Expanded class hierarchy of LegacyDiscoveryDecorator

2 files declare their use of LegacyDiscoveryDecorator

File

drupal/core/modules/field/lib/Drupal/field/Plugin/Type/LegacyDiscoveryDecorator.php, line 19
Definition of Drupal\field\Plugin\Type\LegacyDiscoveryDecorator.

Namespace

Drupal\field\Plugin\Type
View source
abstract class LegacyDiscoveryDecorator implements DiscoveryInterface {

  /**
   * The name of the hook for Drupal\Core\Plugin\Discovery\HookDiscovery.
   *
   * @var string
   */
  protected $hook;

  /**
   * The decorated discovery object.
   *
   * @var Drupal\Component\Plugin\Discovery\DiscoveryInterface
   */
  protected $decorated;

  /**
   * Creates a Drupal\field\Plugin\Discovery\LegacyDiscoveryDecorator object.
   *
   * @param Drupal\Component\Plugin\Discovery\DiscoveryInterface $discovery
   *   The parent object implementing DiscoveryInterface that is being
   *   decorated.
   */
  public function __construct(DiscoveryInterface $decorated) {
    $this->decorated = $decorated;
  }

  /**
   * Implements Drupal\Component\Plugin\Discovery\DiscoveryInterface::getDefinition().
   */
  public function getDefinition($plugin_id) {
    $definitions = $this
      ->getDefinitions();
    return isset($definitions[$plugin_id]) ? $definitions[$plugin_id] : NULL;
  }

  /**
   * Implements Drupal\Component\Plugin\Discovery\DiscoveryInterface::getDefinitions().
   */
  public function getDefinitions() {
    $definitions = $this->decorated
      ->getDefinitions();
    $legacy_discovery = new HookDiscovery($this->hook);
    if ($legacy_definitions = $legacy_discovery
      ->getDefinitions()) {
      foreach ($legacy_definitions as $plugin_id => $definition) {
        $this
          ->processDefinition($definition);
        if (isset($definition['behaviors']['default value'])) {
          $definition['default_value'] = $definition['behaviors']['default value'];
          unset($definition['behaviors']['default value']);
        }
        $definitions[$plugin_id] = $definition;
      }
    }
    return $definitions;
  }

  /**
   * Massages a legacy plugin definition.
   *
   * @var array $definition
   *   A plugin definition, as discovered by
   *   Drupal\Core\Plugin\Discovery\HookDiscovery.
   *
   * @return array
   *   The massaged plugin definition.
   */
  public abstract function processDefinition(array &$definition);

}

Members

Namesort descending Modifiers Type Description Overrides
LegacyDiscoveryDecorator::$decorated protected property The decorated discovery object.
LegacyDiscoveryDecorator::$hook protected property The name of the hook for Drupal\Core\Plugin\Discovery\HookDiscovery. 2
LegacyDiscoveryDecorator::getDefinition public function Implements Drupal\Component\Plugin\Discovery\DiscoveryInterface::getDefinition(). Overrides DiscoveryInterface::getDefinition
LegacyDiscoveryDecorator::getDefinitions public function Implements Drupal\Component\Plugin\Discovery\DiscoveryInterface::getDefinitions(). Overrides DiscoveryInterface::getDefinitions
LegacyDiscoveryDecorator::processDefinition abstract public function Massages a legacy plugin definition. 2
LegacyDiscoveryDecorator::__construct public function Creates a Drupal\field\Plugin\Discovery\LegacyDiscoveryDecorator object.