From adeb796cc9ae2a9b62bc374309e4cbdce269a911 Mon Sep 17 00:00:00 2001
From: anuar <anuar.alfetahe@adm.ee>
Date: Wed, 11 Aug 2021 12:55:40 +0300
Subject: [PATCH] Scheduler node publish/unpublish change

---
 src/SchedulerManager.php | 10 ++++++++++
 1 files changed, 10 insertions(+), 0 deletion(-)

diff --git a/src/SchedulerManager.php b/src/SchedulerManager.php
index f84b455..4173ed0 100644
--- a/src/SchedulerManager.php
+++ b/src/SchedulerManager.php
@@ -253,6 +253,11 @@ public function publish() {

         // Use the standard actions system to publish and save the node.
         $node = $event->getNode();
+
+        // The only way to change the node status directly is by changing the
+        // moderation state. Scheduler conflicts with the workbench moderation.
+        $node->moderation_state->target_id = \Drupal\fin_admin\Service\EntityStatusService::ENTITY_PUBLISH;
+
         $action_id = 'node_publish_action';
         if ($this->moduleHandler->moduleExists('workbench_moderation_actions')) {
           // workbench_moderation_actions module uses a custom action instead.
@@ -429,6 +434,11 @@ public function unpublish() {
         // Use the standard actions system to unpublish and save the node.
         $node = $event->getNode();
         $action_id = 'node_unpublish_action';
+
+        // The only way to change the node status directly is by changing the
+        // moderation state. Scheduler conflicts with the workbench moderation.
+        $node->moderation_state->target_id = \Drupal\fin_admin\Service\EntityStatusService::ENTITY_UNPUBLISH;
+
         if ($this->moduleHandler->moduleExists('workbench_moderation_actions')) {
           // workbench_moderation_actions module uses a custom action instead.
           $action_id = 'state_change__node__archived';

--
2.25.1

