function hook_scheduler_allow_unpublishing in Scheduler 7
Same name and namespace in other branches
- 8 scheduler.api.php \hook_scheduler_allow_unpublishing()
Allows modules to prevent unpublication of a scheduled node.
Modules can implement hook_scheduler_allow_unpublishing() to prevent unpublishing of a scheduled node. The node can be scheduled for unpublishing as usual, and an attempt to unpublish it will be made during the first cron run after the unpublishing time. If this hook returns FALSE the node will not be unpublished. Attempts at unpublishing will continue on each subsequent cron run until this hook returns TRUE.
Parameters
object $node: The scheduled node that is about to be unpublished.
Return value
bool TRUE if the node can be unpublished, FALSE if it should not be unpublished.
File
- ./
scheduler.api.php, line 141 - API documentation for the Scheduler module.
Code
function hook_scheduler_allow_unpublishing($node) {
$allowed = TRUE;
// Prevent unpublication of competition entries if not all prizes have been
// claimed.
if ($node->type == 'competition' && ($items = field_get_items('node', $node, 'field_competition_prizes'))) {
$allowed = (bool) count($items);
// If unpublication is denied then inform the user why. This message will be
// displayed during node edit and save.
if (!$allowed) {
drupal_set_message(t('The competition will only be unpublished after all prizes have been claimed by the winners.'));
}
}
return $allowed;
}