You are here

function scheduler_api_test_scheduler_publish_process in Scheduler 2.x

Implements hook_scheduler_publish_process().

File

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

Code

function scheduler_api_test_scheduler_publish_process(EntityInterface $entity) {

  // Any entity with 'red {type}' in the title is simulated to cause a failure
  // and should then be skipped by Scheduler.
  if (stristr($entity
    ->label(), "red {$entity->getEntityTypeId()}")) {
    $label_field = $entity
      ->getEntityType()
      ->get('entity_keys')['label'];
    $entity
      ->set($label_field, $entity
      ->label() . ' - publishing failed in API test module')
      ->save();
    \Drupal::messenger()
      ->addMessage(t('Scheduler_Api_Test: Red should cause Scheduler to abandon publishing.'), 'status', FALSE);
    return -1;
  }
  return 0;
}