Commit 7fa6436f authored by Jonathan Smith's avatar Jonathan Smith
Browse files

Issue #2977887 by jonathan1055, karenann, nicrodgers, pghaemim, rondog469,...

Issue #2977887 by jonathan1055, karenann, nicrodgers, pghaemim, rondog469, achap, christiemade, ejanus: Fix conflict with Workbench Moderation and Workbench Moderation Actions for non-moderated content
parent 2791efce
Loading
Loading
Loading
Loading
+3 −1
Changes for composer.json: 3 added lines, 1 removed line.
Original line number Diff line number Diff line
@@ -7,7 +7,9 @@
    "require-dev": {
        "drupal/rules": "^3",
        "drush/drush": "^9.0 || ^10",
        "drupal/devel_generate": "^2.0 || 4.x-dev"
        "drupal/devel_generate": "^2.0 || 4.x-dev",
        "drupal/workbench_moderation": "^1.0",
        "drupal/workbench_moderation_actions": "^1.0"
    },
    "repositories": {
        "drupal": {
+5 −0
Changes for config/schema/workbench_moderation_actions_fix.schema.yml: 5 added lines, 0 removed lines.
Original line number Diff line number Diff line
# Temporary fix for workbench_moderation_actions
# See https://www.drupal.org/project/workbench_moderation_actions/issues/3281948
action.configuration.state_change:*:
  type: action_configuration_default
  label: 'State Change configuration'
+2 −0
Changes for scheduler.info.yml: 2 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -13,6 +13,8 @@ dependencies:
test_dependencies:
  - rules:rules
  - devel:devel_generate
  - workbench_moderation:workbench_moderation
  - workbench_moderation_actions:workbench_moderation_actions
libraries:
  - vertical-tabs
  - default-time
+22 −0
Changes for scheduler.module: 22 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -6,6 +6,7 @@
 */

use Drupal\Component\Utility\Xss;
use Drupal\Core\Action\Plugin\Action\UnpublishAction;
use Drupal\Core\Entity\Display\EntityViewDisplayInterface;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Entity\EntityTypeInterface;
@@ -13,6 +14,8 @@ use Drupal\Core\Field\BaseFieldDefinition;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Routing\RouteMatchInterface;
use Drupal\Core\Url;
use Drupal\workbench_moderation\Plugin\Action\ModerationOptOutPublishNode;
use Drupal\workbench_moderation\Plugin\Action\ModerationOptOutUnpublishNode;
use Drupal\node\Entity\NodeType;
use Drupal\scheduler\SchedulerEvent;
use Drupal\scheduler\SchedulerEvents;
@@ -388,6 +391,25 @@ function scheduler_entity_base_field_info(EntityTypeInterface $entity_type) {
  }
}

/**
 * Implements hook_action_info_alter().
 */
function scheduler_action_info_alter(&$definitions) {
  // Workbench Moderation has a bug where the wrong actions are assigned which
  // causes scheduled publishing of non-moderated content to fail. This fix will
  // work regardless of the relative weights of the two modules, and will
  // continue to work even if WBM is fixed before this code is removed.
  // See https://www.drupal.org/project/workbench_moderation/issues/3238576
  if (\Drupal::moduleHandler()->moduleExists('workbench_moderation')) {
    if (isset($definitions['entity:publish_action:node']['class']) && $definitions['entity:publish_action:node']['class'] == ModerationOptOutUnpublishNode::class) {
      $definitions['entity:publish_action:node']['class'] = ModerationOptOutPublishNode::class;
    }
    if (isset($definitions['entity:unpublish_action:node']['class']) && $definitions['entity:unpublish_action:node']['class'] == UnpublishAction::class) {
      $definitions['entity:unpublish_action:node']['class'] = ModerationOptOutUnpublishNode::class;
    }
  }
}

/**
 * Implements hook_views_data_alter().
 */
+14 −2
Changes for src/SchedulerManager.php: 14 added lines, 2 removed lines.
Original line number Diff line number Diff line
@@ -289,9 +289,15 @@ class SchedulerManager {
        $node = $event->getNode();
        $action_id = 'node_publish_action';
        if ($this->moduleHandler->moduleExists('workbench_moderation_actions')) {
          // workbench_moderation_actions module uses a custom action instead.
          // workbench_moderation_actions module replaces the standard action
          // with a custom one which should be used only when the content type
          // is part of a moderation workflow.
          /** @var \Drupal\workbench_moderation\ModerationInformationInterface $moderation_info */
          $moderation_info = \Drupal::service('workbench_moderation.moderation_information');
          if ($moderation_info->isModeratableEntity($node)) {
            $action_id = 'state_change__node__published';
          }
        }
        if ($loaded_action = $this->entityTypeManager->getStorage('action')->load($action_id)) {
          $loaded_action->getPlugin()->execute($node);
        }
@@ -470,9 +476,15 @@ class SchedulerManager {
        $node = $event->getNode();
        $action_id = 'node_unpublish_action';
        if ($this->moduleHandler->moduleExists('workbench_moderation_actions')) {
          // workbench_moderation_actions module uses a custom action instead.
          // workbench_moderation_actions module replaces the standard action
          // with a custom one which should be used only when the content type
          // is part of a moderation workflow.
          /** @var \Drupal\workbench_moderation\ModerationInformationInterface $moderation_info */
          $moderation_info = \Drupal::service('workbench_moderation.moderation_information');
          if ($moderation_info->isModeratableEntity($node)) {
            $action_id = 'state_change__node__archived';
          }
        }
        if ($loaded_action = $this->entityTypeManager->getStorage('action')->load($action_id)) {
          $loaded_action->getPlugin()->execute($node);
        }
Loading