function hook_scheduler_unpublish_process in Scheduler 2.x
Hook function to process the unpublish action for an entity.
This hook is called from schedulerManger::unpublish() and allows other modules to process the unpublish action on the entity during a cron run. That module may require different functionality to be executed instead of the default unpublish action. If all of the invoked hook functions return 0 then Scheduler will process the entity using the default unpublish 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 unpublished.
Return value
int 1 if this function has unpublished the entity or performed other actions meaning that Scheduler should NOT process the default unpublish action. 0 if nothing has been done and Scheduler should process the default unpublish 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_unpublish_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_unpublish_process in tests/
modules/ scheduler_api_test/ scheduler_api_test.module - Implements hook_scheduler_unpublish_process().
File
- ./
scheduler.api.php, line 316 - API documentation for the Scheduler module.
Code
function hook_scheduler_unpublish_process(EntityInterface $entity) {
if ($big_problem) {
// Throw an exception here.
return -1;
}
if ($some_condition) {
// Do the unpublish processing here on the $entity.
$entity
->setSomeValue();
return 1;
}
return 0;
}