DefaultsTestPluginManager.php in Drupal 8
File
core/modules/system/tests/modules/plugin_test/src/Plugin/DefaultsTestPluginManager.php
View source
<?php
namespace Drupal\plugin_test\Plugin;
use Drupal\Component\Plugin\Discovery\StaticDiscovery;
use Drupal\Component\Plugin\Factory\DefaultFactory;
use Drupal\Core\Extension\ModuleHandlerInterface;
use Drupal\Core\Plugin\DefaultPluginManager;
class DefaultsTestPluginManager extends DefaultPluginManager {
public function __construct(ModuleHandlerInterface $module_handler) {
$this->discovery = new StaticDiscovery();
$this->factory = new DefaultFactory($this, 'Drupal\\Component\\Plugin\\PluginInspectionInterface');
$this->moduleHandler = $module_handler;
$this->defaults = [
'metadata' => [
'default' => TRUE,
],
];
$this->discovery
->setDefinition('test_block1', [
'class' => 'Drupal\\plugin_test\\Plugin\\plugin_test\\mock_block\\MockTestBlock',
'metadata' => [
'custom' => TRUE,
],
]);
$this->discovery
->setDefinition('test_block2', [
'class' => 'Drupal\\plugin_test\\Plugin\\plugin_test\\mock_block\\MockTestBlock',
'metadata' => [
'custom' => TRUE,
'default' => FALSE,
],
]);
}
}