Commit 6268ce9f 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 5f1de1c0
Loading
Loading
Loading
Loading
+3 −1
Changes for composer.json: 3 added lines, 1 removed line.
Original line number Diff line number Diff line
@@ -8,7 +8,9 @@
        "drupal/rules": "^3",
        "drush/drush": "^9.0 || ^10",
        "drupal/devel_generate": "^4.0",
        "drupal/commerce": "^2.0"
        "drupal/commerce": "^2.0",
        "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
@@ -16,6 +16,8 @@ test_dependencies:
  - drupal:media
  - commerce:commerce
  - drupal:taxonomy
  - workbench_moderation:workbench_moderation
  - workbench_moderation_actions:workbench_moderation_actions
libraries:
  - admin-css
  - vertical-tabs
+23 −0
Changes for scheduler.module: 23 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;
@@ -16,6 +17,8 @@ use Drupal\Core\Url;
use Drupal\migrate\Plugin\MigrateSourceInterface;
use Drupal\migrate\Plugin\MigrationInterface;
use Drupal\migrate\Row;
use Drupal\workbench_moderation\Plugin\Action\ModerationOptOutPublishNode;
use Drupal\workbench_moderation\Plugin\Action\ModerationOptOutUnpublishNode;

/**
 * Implements hook_help().
@@ -718,6 +721,26 @@ 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 −6
Changes for src/SchedulerManager.php: 14 added lines, 6 removed lines.
Original line number Diff line number Diff line
@@ -396,12 +396,16 @@ class SchedulerManager {
            $this->logger->notice('@type: scheduled publishing of %title.', $logger_variables);

            // Use the actions system to publish and save the entity.
            $action_id = $plugin->publishAction();
            if ($this->moduleHandler->moduleExists('workbench_moderation_actions')) {
              // workbench_moderation_actions uses a custom action.
              // workbench_moderation_actions module replaces the standard
              // action with a custom one which should be used only when the
              // entity 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($entity)) {
                $action_id = 'state_change__' . $entityTypeId . '__published';
              }
            else {
              $action_id = $plugin->publishAction();
            }
            if ($loaded_action = $this->entityTypeManager->getStorage('action')->load($action_id)) {
              $loaded_action->getPlugin()->execute($entity);
@@ -599,12 +603,16 @@ class SchedulerManager {
            $this->logger->notice('@type: scheduled unpublishing of %title.', $logger_variables);

            // Use the actions system to unpublish and save the entity.
            $action_id = $plugin->unpublishAction();
            if ($this->moduleHandler->moduleExists('workbench_moderation_actions')) {
              // workbench_moderation_actions uses a custom action.
              // workbench_moderation_actions module replaces the standard
              // action with a custom one which should be used only when the
              // entity 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($entity)) {
                $action_id = 'state_change__' . $entityTypeId . '__archived';
              }
            else {
              $action_id = $plugin->unpublishAction();
            }
            if ($loaded_action = $this->entityTypeManager->getStorage('action')->load($action_id)) {
              $loaded_action->getPlugin()->execute($entity);
Loading