You are here

abstract class PluginManagerBase in Service Container 7.2

Same name in this branch
  1. 7.2 src/Plugin/PluginManagerBase.php \Drupal\service_container\Plugin\PluginManagerBase
  2. 7.2 lib/Drupal/Component/Plugin/PluginManagerBase.php \Drupal\Component\Plugin\PluginManagerBase
Same name and namespace in other branches
  1. 7 src/Plugin/PluginManagerBase.php \Drupal\service_container\Plugin\PluginManagerBase

Base class for plugin managers.

Hierarchy

Expanded class hierarchy of PluginManagerBase

File

src/Plugin/PluginManagerBase.php, line 17
Contains \Drupal\service_container\Plugin\PluginManagerBase

Namespace

Drupal\service_container\Plugin
View source
abstract class PluginManagerBase implements PluginManagerInterface {

  /**
   * 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;

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

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

  /**
   * {@inheritdoc}
   */
  public function hasDefinition($plugin_id) {
    return (bool) $this->discovery
      ->hasDefinition($plugin_id);
  }

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

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

  /**
   * {@inheritdoc}
   */
  public function getInstance(array $options) {

    // 90% of core does not use the generic $mapper functionality, so use a
    // sane default function.
    if (isset($options['id'])) {
      return $this
        ->createInstance($options['id']);
    }
    return FALSE;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
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::createInstance public function Creates a pre-configured instance of a plugin. Overrides FactoryInterface::createInstance
PluginManagerBase::getDefinition public function Gets a specific plugin definition. Overrides DiscoveryInterface::getDefinition
PluginManagerBase::getDefinitions public function Gets the definition of all plugins for this type. Overrides DiscoveryInterface::getDefinitions
PluginManagerBase::getInstance public function Gets a preconfigured instance of a plugin. Overrides MapperInterface::getInstance
PluginManagerBase::hasDefinition public function Indicates if a specific plugin definition exists. Overrides DiscoveryInterface::hasDefinition