class TestPluginManager

Same name in this branch
  1. 8.9.x core/tests/Drupal/Tests/Core/Plugin/TestPluginManager.php \Drupal\Tests\Core\Plugin\TestPluginManager
Same name and namespace in other branches
  1. 9 core/modules/system/tests/modules/plugin_test/src/Plugin/TestPluginManager.php \Drupal\plugin_test\Plugin\TestPluginManager
  2. 9 core/tests/Drupal/Tests/Core/Plugin/TestPluginManager.php \Drupal\Tests\Core\Plugin\TestPluginManager
  3. 10 core/modules/system/tests/modules/plugin_test/src/Plugin/TestPluginManager.php \Drupal\plugin_test\Plugin\TestPluginManager
  4. 10 core/tests/Drupal/Tests/Core/Plugin/TestPluginManager.php \Drupal\Tests\Core\Plugin\TestPluginManager
  5. 11.x core/modules/system/tests/modules/plugin_test/src/Plugin/TestPluginManager.php \Drupal\plugin_test\Plugin\TestPluginManager
  6. 11.x core/tests/Drupal/Tests/Core/Plugin/TestPluginManager.php \Drupal\Tests\Core\Plugin\TestPluginManager

Defines a plugin manager used by Plugin API unit tests.

Hierarchy

Expanded class hierarchy of TestPluginManager

1 file declares its use of TestPluginManager
PluginTestBase.php in core/tests/Drupal/KernelTests/Core/Plugin/PluginTestBase.php

File

core/modules/system/tests/modules/plugin_test/src/Plugin/TestPluginManager.php, line 12

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', [
            '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

Title Sort descending Modifiers Object type Summary Overriden Title 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 12
PluginManagerBase::getDefinition public function Overrides DiscoveryTrait::getDefinition
PluginManagerBase::getDefinitions public function 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 7
PluginManagerBase::handlePluginNotFound protected function Allows plugin managers to specify custom behavior if a plugin is not found. 1
TestPluginManager::__construct public function

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.