You are here

function scheduler_api_test_scheduler_nid_list in Scheduler 8

Implements hook_scheduler_nid_list().

File

tests/modules/scheduler_api_test/scheduler_api_test.module, line 14
Hook implementations of the Scheduler API Test module.

Code

function scheduler_api_test_scheduler_nid_list($action) {
  $nids = [];

  // Check to see what test nodes exist.
  $query = \Drupal::entityQuery('node');
  $nodes = Node::loadMultiple($query
    ->execute());
  $request_time = \Drupal::time()
    ->getRequestTime();
  foreach ($nodes as $nid => $node) {

    // If publishing and this is the publish test node, set a date and add
    // the node id to the list.
    if ($action == 'publish' && $node->title->value == 'API TEST nid_list publish me') {
      $node
        ->set('publish_on', $request_time)
        ->save();
      $nids[] = $nid;
    }

    // If unpublishing and this is the unpublish test node, set a date and add
    // the node id to the list.
    if ($action == 'unpublish' && $node->title->value == 'API TEST nid_list unpublish me') {
      $node
        ->set('unpublish_on', $request_time)
        ->save();
      $nids[] = $nid;
    }
  }
  return $nids;
}