You are here

abstract class PluginManagerBase in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/lib/Drupal/Component/Plugin/PluginManagerBase.php \Drupal\Component\Plugin\PluginManagerBase

Base class for plugin managers.

Hierarchy

Expanded class hierarchy of PluginManagerBase

5 files declare their use of PluginManagerBase
DefaultPluginManager.php in core/lib/Drupal/Core/Plugin/DefaultPluginManager.php
Contains \Drupal\Core\Plugin\DefaultPluginManager.
EntityDisplayFormBase.php in core/modules/field_ui/src/Form/EntityDisplayFormBase.php
Contains \Drupal\field_ui\Form\EntityDisplayFormBase.
MockBlockManager.php in core/modules/system/tests/modules/plugin_test/src/Plugin/MockBlockManager.php
Contains \Drupal\plugin_test\Plugin\MockBlockManager.
StubFallbackPluginManager.php in core/tests/Drupal/Tests/Component/Plugin/StubFallbackPluginManager.php
Contains \Drupal\Tests\Component\Plugin\StubFallbackPluginManager.
TestPluginManager.php in core/modules/system/tests/modules/plugin_test/src/Plugin/TestPluginManager.php
Contains \Drupal\plugin_test\Plugin\TestPluginManager.

File

core/lib/Drupal/Component/Plugin/PluginManagerBase.php, line 16
Contains \Drupal\Component\Plugin\PluginManagerBase.

Namespace

Drupal\Component\Plugin
View source
abstract class PluginManagerBase implements PluginManagerInterface {
  use DiscoveryTrait;

  /**
   * The object that discovers plugins managed by this manager.
   *
   * @var \Drupal\Component\Plugin\Discovery\DiscoveryInterface
   */
  protected $discovery;

  /**
   * The object that instantiates plugins managed by this manager.
   *
   * @var \Drupal\Component\Plugin\Factory\FactoryInterface
   */
  protected $factory;

  /**
   * The object that returns the preconfigured plugin instance appropriate for a particular runtime condition.
   *
   * @var \Drupal\Component\Plugin\Mapper\MapperInterface
   */
  protected $mapper;

  /**
   * Gets the plugin discovery.
   *
   * @return \Drupal\Component\Plugin\Discovery\DiscoveryInterface
   */
  protected function getDiscovery() {
    return $this->discovery;
  }

  /**
   * Gets the plugin factory.
   *
   * @return \Drupal\Component\Plugin\Factory\FactoryInterface
   */
  protected function getFactory() {
    return $this->factory;
  }

  /**
   * {@inheritdoc}
   */
  public function getDefinition($plugin_id, $exception_on_invalid = TRUE) {
    return $this
      ->getDiscovery()
      ->getDefinition($plugin_id, $exception_on_invalid);
  }

  /**
   * {@inheritdoc}
   */
  public function getDefinitions() {
    return $this
      ->getDiscovery()
      ->getDefinitions();
  }

  /**
   * {@inheritdoc}
   */
  public function createInstance($plugin_id, array $configuration = array()) {

    // If this PluginManager has fallback capabilities catch
    // PluginNotFoundExceptions.
    if ($this instanceof FallbackPluginManagerInterface) {
      try {
        return $this
          ->getFactory()
          ->createInstance($plugin_id, $configuration);
      } catch (PluginNotFoundException $e) {
        $fallback_id = $this
          ->getFallbackPluginId($plugin_id, $configuration);
        return $this
          ->getFactory()
          ->createInstance($fallback_id, $configuration);
      }
    }
    else {
      return $this
        ->getFactory()
        ->createInstance($plugin_id, $configuration);
    }
  }

  /**
   * {@inheritdoc}
   */
  public function getInstance(array $options) {
    return $this->mapper
      ->getInstance($options);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
DiscoveryTrait::doGetDefinition protected function Gets a specific plugin definition.
DiscoveryTrait::hasDefinition public function
PluginManagerBase::$discovery protected property The object that discovers plugins managed by this manager.
PluginManagerBase::$factory protected property The object that instantiates plugins managed by this manager.
PluginManagerBase::$mapper protected property The object that returns the preconfigured plugin instance appropriate for a particular runtime condition.
PluginManagerBase::createInstance public function Creates a pre-configured instance of a plugin. Overrides FactoryInterface::createInstance 11
PluginManagerBase::getDefinition public function Gets a specific plugin definition. Overrides DiscoveryTrait::getDefinition
PluginManagerBase::getDefinitions public function Gets the definition of all plugins for this type. Overrides DiscoveryTrait::getDefinitions
PluginManagerBase::getDiscovery protected function Gets the plugin discovery. 1
PluginManagerBase::getFactory protected function Gets the plugin factory. 1
PluginManagerBase::getInstance public function Gets a preconfigured instance of a plugin. Overrides MapperInterface::getInstance 7