class TestPluginManager

Defines a plugin manager used by Plugin API unit tests.

Hierarchy

Expanded class hierarchy of TestPluginManager

2 files declare their use of TestPluginManager
AlterDecoratorTest.php in drupal/core/modules/system/lib/Drupal/system/Tests/Plugin/AlterDecoratorTest.php
Definition of Drupal\system\Tests\Plugin\AlterDecoratorTest.
PluginTestBase.php in drupal/core/modules/system/lib/Drupal/system/Tests/Plugin/PluginTestBase.php
Definition of Drupal\system\Tests\Plugin\PluginTestBase.

File

drupal/core/modules/system/tests/modules/plugin_test/lib/Drupal/plugin_test/Plugin/TestPluginManager.php, line 18
Definition of Drupal\plugin_test\Plugin\TestPluginManager.

Namespace

Drupal\plugin_test\Plugin
View source
class TestPluginManager extends PluginManagerBase {
  public function __construct() {

    // Create the object that can be used to return definitions for all the
    // plugins available for this type. Most real plugin managers use a richer
    // discovery implementation, but StaticDiscovery lets us add some simple
    // mock plugins for unit testing.
    $this->discovery = new StaticDiscovery();

    // A simple plugin: a mock user login block.
    $this->discovery
      ->setDefinition('user_login', array(
      'label' => 'User login',
      'class' => 'Drupal\\plugin_test\\Plugin\\plugin_test\\mock_block\\MockUserLoginBlock',
    ));

    // In addition to finding all of the plugins available for a type, a plugin
    // type must also be able to create instances of that plugin. For example, a
    // specific instance of a "User login" block, configured with a custom
    // title. To handle plugin instantiation, plugin managers can use one of the
    // factory classes included with the plugin system, or create their own.
    // DefaultFactory is a simple, general purpose factory suitable for
    // many kinds of plugin types. Factories need access to the plugin
    // definitions (e.g., since that's where the plugin's class is specified),
    // so we provide it the discovery object.
    $this->factory = new DefaultFactory($this->discovery);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
PluginManagerBase::$defaults protected property A set of defaults to be referenced by $this->processDefinition() if additional processing of plugins is necessary or helpful for development purposes. 3
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::clearCachedDefinitions public function Clears static and persistent plugin definition caches. Overrides CachedDiscoveryInterface::clearCachedDefinitions
PluginManagerBase::createInstance public function Returns a preconfigured instance of a plugin. Overrides FactoryInterface::createInstance 6
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 Returns a preconfigured instance of a plugin. Overrides MapperInterface::getInstance 6
PluginManagerBase::processDefinition public function Performs extra processing on plugin definitions. 2
TestPluginManager::__construct public function 1