I have used Scheduler module with content moderation integration to publish a content automatically. It is perfectly working using the module. Now I want to add a functionality that once the content is published via cron, an email will be sent to the author of that particular content.
I have used hook_scheduler_publish_action
to perform this action, but unfortunately I am facing some different scenario.
- If I remove node publish code and keep only the mail sending code, the mail is fired.
- If I remove the mail sending code and keep only node publish code, the node is published.
- If I keep both, only mail is sent, content is not published.
Ref: https://git.drupalcode.org/project/scheduler/blob/8.x-1.x/scheduler.api.php
Below code is only publishing content, not sending email.
function MYMODULE_scheduler_publish_action(NodeInterface $node) {
// node moderation state will be 'published'
$node->set('moderation_state', 'published');
$node->save();
// email send to author
$mail_params = array(
'mail_subject' => 'run cron',
'mail_body' => '<p>node published using scheduler</p>',
'mail_to' => '[email protected]'
);
\Drupal::service('MYMODULE.common_service')->FunctionToSendEmail($mail_params);
}
Below code is only sending email, not publishing content.
function MYMODULE_scheduler_publish_action(NodeInterface $node) {
// email send to author
$mail_params = array(
'mail_subject' => 'run cron',
'mail_body' => '<p>node published using scheduler</p>',
'mail_to' => '[email protected]'
);
\Drupal::service('MYMODULE.common_service')->FunctionToSendEmail($mail_params);
// node moderation state will be 'published'
$node->set('moderation_state', 'published');
$node->save();
}
That means this hook only perform the first action and ignores others.
Now my question is how will I perform multiple actions using this hook or is there any other procedure to do this?
Please help me. Thanks in advance.