You are here

function hook_scheduler_publish_process in Scheduler 2.x

Hook function to process the publish action for an entity.

This hook is called from schedulerManger::publish() and allows other modules to process the publish action on the entity during a cron run. That module may require different functionality to be executed instead of the default publish action. If all of the invoked hook functions return 0 then Scheduler will process the entity using the default publish action, just as if no hook functions had been called.

This hook was introduced for scheduler_content_moderation_integration. See https://www.drupal.org/project/scheduler/issues/2798689

Parameters

\Drupal\Core\Entity\EntityInterface $entity: The scheduled entity that is about to be published.

Return value

int 1 if this function has published the entity or performed other such action meaning that Scheduler should NOT process the default publish action. 0 if nothing has been done and Scheduler should process the default publish action just as if this hook function did not exist. -1 if an error has occurred and Scheduler should abandon processing this entity with no further action and move on to the next one.

1 function implements hook_scheduler_publish_process()

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_publish_process in tests/modules/scheduler_api_test/scheduler_api_test.module
Implements hook_scheduler_publish_process().

File

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

Code

function hook_scheduler_publish_process(EntityInterface $entity) {
  if ($big_problem) {

    // Throw an exception here.
    return -1;
  }
  if ($some_condition) {

    // Do the publish processing here on the $entity.
    $entity
      ->setSomeValue();
    return 1;
  }
  return 0;
}