public function PurgersService::movePurgerUp in Purge 8.3
Move the purger instance up in the plugin execution order.
Parameters
string $purger_instance_id: The instance ID of the purger that should move one place up.
Throws
\Drupal\purge\Plugin\Purge\Purger\Exception\BadBehaviorException Thrown when $purger_instance_id is not enabled or does not exist.
Overrides PurgersServiceInterface::movePurgerUp
See also
\Drupal\purge\Plugin\Purge\Purger\PurgersServiceInterface::setPluginsEnabled()
File
- src/
Plugin/ Purge/ Purger/ PurgersService.php, line 544
Class
- PurgersService
- Provides the service that distributes access to one or more purgers.
Namespace
Drupal\purge\Plugin\Purge\PurgerCode
public function movePurgerUp($purger_instance_id) {
$enabled = $this
->getPluginsEnabled();
if (!isset($enabled[$purger_instance_id])) {
throw new BadBehaviorException("Instance id '{$purger_instance_id}' is not enabled!");
}
// Build a numerically ordered copy of the enabled plugins array and put
// only even numbers in. Then move $purger_instance_id in the odd spot up.
$ordered = [];
$index = 0;
foreach ($enabled as $instance_id => $plugin_id) {
$index = $index + 2;
if ($instance_id === $purger_instance_id) {
$ordered[$index - 3] = [
$instance_id,
$plugin_id,
];
}
else {
$ordered[$index] = [
$instance_id,
$plugin_id,
];
}
}
// Sort the array on key and rebuild the original array, reordered.
ksort($ordered);
$enabled = [];
foreach ($ordered as $inst) {
$enabled[$inst[0]] = $inst[1];
}
$this
->setPluginsEnabled($enabled);
}