public function ProcessorsService::setPluginsEnabled in Purge 8.3
Set the plugins used by the service and reload it.
Parameters
string[] $plugin_ids: Unassociative array with plugin IDs to be enabled.
Overrides ModifiableServiceInterface::setPluginsEnabled
See also
\Drupal\purge\ModifiableServiceInterface::getPluginsAvailable()
File
- src/
Plugin/ Purge/ Processor/ ProcessorsService.php, line 114
Class
- ProcessorsService
- Provides a service that provides access to loaded processors.
Namespace
Drupal\purge\Plugin\Purge\ProcessorCode
public function setPluginsEnabled(array $plugin_ids) {
$definitions = $this->pluginManager
->getDefinitions();
// Gather all plugins mentioned in CMI and those available right now, set
// them disabled first. Then flip the switch for given plugin_ids.
$setting_assoc = [];
$instances = $this->configFactory
->get('purge.plugins')
->get('processors');
if (!is_null($instances)) {
foreach ($instances as $inst) {
$setting_assoc[$inst['plugin_id']] = FALSE;
}
}
foreach ($definitions as $definition) {
$setting_assoc[$definition['id']] = FALSE;
}
foreach ($plugin_ids as $plugin_id) {
if (!isset($definitions[$plugin_id])) {
throw new \LogicException('Invalid plugin_id.');
}
$setting_assoc[$plugin_id] = TRUE;
}
// Convert the array to the CMI storage format and commit.
$setting = [];
foreach ($setting_assoc as $plugin_id => $status) {
$setting[] = [
'plugin_id' => $plugin_id,
'status' => $status,
];
}
$this->configFactory
->getEditable('purge.plugins')
->set('processors', $setting)
->save();
$this
->reload();
}