You are here

public function PurgersService::movePurgerDown in Purge 8.3

Move the purger instance down in the plugin execution order.

Parameters

string $purger_instance_id: The instance ID of the purger that should move one place down.

Throws

\Drupal\purge\Plugin\Purge\Purger\Exception\BadBehaviorException Thrown when $purger_instance_id is not enabled or does not exist.

Overrides PurgersServiceInterface::movePurgerDown

See also

\Drupal\purge\Plugin\Purge\Purger\PurgersServiceInterface::setPluginsEnabled()

File

src/Plugin/Purge/Purger/PurgersService.php, line 512

Class

PurgersService
Provides the service that distributes access to one or more purgers.

Namespace

Drupal\purge\Plugin\Purge\Purger

Code

public function movePurgerDown($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 down.
  $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);
}