You are here

function hook_scheduler_list_alter in Scheduler 2.x

Hook function to manipulate the list of entity ids being processed.

This hook allows modules to add or remove entity ids from the list being processed in the current cron run. It is invoked during cron runs only.

Parameters

array $ids: The array of entity ids being processed.

string $process: The process being done - 'publish' or 'unpublish'.

string $entityTypeId: The type of the entity being processed, for example 'node' or 'media'.

1 function implements hook_scheduler_list_alter()

Note: this list is generated by pattern matching, so it may include some functions that are not actually implementations of this hook.

scheduler_api_test_scheduler_list_alter in tests/modules/scheduler_api_test/scheduler_api_test.module
Implements hook_scheduler_list_alter().

File

./scheduler.api.php, line 65
API documentation for the Scheduler module.

Code

function hook_scheduler_list_alter(array &$ids, $process, $entityTypeId) {
  if ($process == 'publish' && $some_condition) {

    // Set a publish_on date and add the id.
    $entity
      ->set('publish_on', \Drupal::time()
      ->getRequestTime())
      ->save();
    $ids[] = $id;
  }
  if ($process == 'unpublish' && $some_other_condition) {

    // Remove the id.
    $ids = array_diff($ids, [
      $id,
    ]);
  }

  // No return is necessary because $ids is passed by reference. Duplicates are
  // removed when all hooks have been invoked.
}