PluginCommands.php in Plugin 8.2
File
src/Commands/PluginCommands.php
View source
<?php
namespace Drupal\plugin\Commands;
use Drush\Commands\DrushCommands;
use Drupal\Component\Plugin\Discovery\CachedDiscoveryInterface;
use Drupal\plugin\PluginType\PluginTypeManagerInterface;
class PluginCommands extends DrushCommands {
protected $pluginTypeManager;
public function __construct(PluginTypeManagerInterface $plugin_type_manager) {
$this->pluginTypeManager = $plugin_type_manager;
}
public function cacheClear(&$types, $include_bootstrapped_types) {
if ($include_bootstrapped_types) {
$types['plugin-types'] = [
$this,
'clearPluginTypeCaches',
];
}
}
public function clearPluginTypeCaches($args = []) {
if (empty($args)) {
$plugin_types = $this->pluginTypeManager
->getPluginTypes();
$args = array_keys($plugin_types);
}
$result = [];
foreach ($args as $plugin_type_id) {
if (!$this->pluginTypeManager
->hasPluginType($plugin_type_id)) {
throw new \Exception(dt('Plugin type "{type}" does not exist.', [
'type' => $plugin_type_id,
]));
}
$plugin_manager = $this->pluginTypeManager
->getPluginType($plugin_type_id)
->getPluginManager();
if (!$plugin_manager instanceof CachedDiscoveryInterface) {
continue;
}
$plugin_manager
->clearCachedDefinitions();
$result[] = dt('Cleared all "{type}" plugin definitions.', [
'type' => $plugin_type_id,
]);
}
if ($result) {
$this
->io()
->success($result);
}
}
}