ScannerPluginManager.php in Search and Replace Scanner 8
File
src/Plugin/ScannerPluginManager.php
View source
<?php
namespace Drupal\scanner\Plugin;
use Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException;
use Drupal\Core\Plugin\DefaultPluginManager;
use Drupal\Core\Cache\CacheBackendInterface;
use Drupal\Core\Extension\ModuleHandlerInterface;
class ScannerPluginManager extends DefaultPluginManager {
protected $defaults = [
'id' => '',
'type' => '',
];
public function __construct(\Traversable $namespaces, CacheBackendInterface $cache_backend, ModuleHandlerInterface $module_handler) {
parent::__construct('Plugin/Scanner', $namespaces, $module_handler, 'Drupal\\scanner\\Plugin\\ScannerPluginInterface', 'Drupal\\scanner\\Annotation\\Scanner');
$this
->alterInfo('scanner_info');
$this
->setCacheBackend($cache_backend, 'scanner');
}
public function processDefinition(&$definition, $plugin_id) {
parent::processDefinition($definition, $plugin_id);
foreach ([
'id',
'type',
] as $required_property) {
if (empty($definition[$required_property])) {
throw new InvalidPluginDefinitionException($plugin_id, sprintf('The scanner %s must define the %s property.', $plugin_id, $required_property));
}
}
}
}