function scheduler_api_test_scheduler_publish_action in Scheduler 8
Implements hook_scheduler_publish_action().
File
- tests/
modules/ scheduler_api_test/ scheduler_api_test.module, line 155 - Hook implementations of the Scheduler API Test module.
Code
function scheduler_api_test_scheduler_publish_action($node) {
if (stristr($node->title->value, 'red')) {
// Nodes with red in the title are simulated to cause a failure and should
// then be skipped by Scheduler.
$node
->set('title', $node->title->value . ' - publishing failed in API test module');
\Drupal::messenger()
->addMessage(t('Scheduler_Api_Test: Red nodes should cause Scheduler to abandon publishing.'), 'status', FALSE);
return -1;
}
elseif (stristr($node->title->value, 'yellow')) {
// Nodes with yellow in the title are simulated to be processed by this
// hook, and will not be published by Scheduler.
$node
->set('title', $node->title->value . ' - publishing processed by API test module');
$node
->setPublished();
\Drupal::messenger()
->addMessage(t('Scheduler_Api_Test: Yellow nodes should not have publishing processed by Scheduler.'), 'status', FALSE);
return 1;
}
return 0;
}