From 8c3acb7cc2a59fc64274fca51f6897bcfe1aef15 Mon Sep 17 00:00:00 2001 From: Steve Wirt Date: Thu, 24 Aug 2023 15:09:14 -0400 Subject: [PATCH] VACMS-14529 Move moderaton state filter to core patch. --- composer.json | 3 + composer.lock | 4 +- .../ModerationStateMultipleWorkflowFilter.php | 87 ------------------- .../va_gov_workflow/va_gov_workflow.module | 34 -------- 4 files changed, 5 insertions(+), 123 deletions(-) delete mode 100644 docroot/modules/custom/va_gov_workflow/src/Plugin/views/filter/ModerationStateMultipleWorkflowFilter.php diff --git a/composer.json b/composer.json index b39d635a885..ce986aa936a 100644 --- a/composer.json +++ b/composer.json @@ -354,6 +354,9 @@ "2951652 - Content lock causes redirect response preventing migration rollback.": "https://www.drupal.org/files/issues/2018-08-28/2951652-4.patch", "3307402 - Content Lock should typehint ModuleHandler interface rather than a specific implementation": "https://www.drupal.org/files/issues/2023-02-03/3307402-typehint-module-handler-interface.patch" }, + "drupal/content_moderation": { + "3382759 - Add multiple workflow content moderation filter to Views.": "https://www.drupal.org/files/issues/2023-08-24/3382759-8.patch" + }, "drupal/core": { "2807629 - Allow menu items which link to unpublished nodes to be selected in the parent item selector": "https://www.drupal.org/files/issues/2022-12-16/2807629-75.patch", "2894449 - Indirect modification of overloaded element with Views responsive table": "https://www.drupal.org/files/issues/2018-10-05/core-indirect-modification-of-overloaded-element-2894449-18.patch", diff --git a/composer.lock b/composer.lock index 03cb1b8283e..07cf427135b 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "0cc8a4fb5a30f402a25cfd5f9bce4029", + "content-hash": "29fec26c44e4a54fbd581049cafe99a8", "packages": [ { "name": "alchemy/zippy", @@ -208,7 +208,7 @@ "version": "v4.1.0", "source": { "type": "git", - "url": "https://github.com/fengyuanchen/cropper.git", + "url": "git@github.com:fengyuanchen/cropper.git", "reference": "617d9bdb8688cc4edb3b03bc49a04b83c7facbe7" }, "dist": { diff --git a/docroot/modules/custom/va_gov_workflow/src/Plugin/views/filter/ModerationStateMultipleWorkflowFilter.php b/docroot/modules/custom/va_gov_workflow/src/Plugin/views/filter/ModerationStateMultipleWorkflowFilter.php deleted file mode 100644 index 70cf9d9c2cc..00000000000 --- a/docroot/modules/custom/va_gov_workflow/src/Plugin/views/filter/ModerationStateMultipleWorkflowFilter.php +++ /dev/null @@ -1,87 +0,0 @@ -valueTitle = $this->t('Filter by workflow state'); - $this->definition['options callback'] = [$this, 'generateOptions']; - $this->currentDisplay = $view->current_display; - } - - /** - * Helper function that generates the options. - * - * @return array - * An array of states and their ids. - */ - public function generateOptions() { - $workflows = Workflow::loadMultipleByType('content_moderation'); - $filter_items = []; - foreach ($workflows as $workflow) { - $states = $workflow->getTypePlugin()->getStates(); - foreach ($states as $state_id => $state) { - // Merge labels if they diverge from the machine name. - // Otherwise, two states with the same machine name but different label - // will cause the last one listed to win. - if (empty($filter_items[$state_id])) { - // It is the first entry, so add it as is. - $filter_items[$state_id] = $state->label(); - } - elseif (!empty($filter_items[$state_id]) && ($filter_items[$state_id] !== $state->label())) { - // This machine name exists with a different label, so combine them. - $filter_items[$state_id] = "{$filter_items[$state_id]} | {$state->label()}"; - } - } - } - return $filter_items; - } - - /** - * Helper function that builds the query. - */ - public function query() { - if (!empty($this->value)) { - $configuration = [ - 'table' => 'content_moderation_state_field_data', - 'field' => 'content_entity_revision_id', - 'left_table' => 'node_field_data', - 'left_field' => 'vid', - 'operator' => '=', - ]; - $join = Views::pluginManager('join')->createInstance('standard', $configuration); - $this->query->addRelationship('content_moderation_state_field_data', $join, 'node_field_data'); - $this->query->addWhere('AND', 'content_moderation_state_field_data.moderation_state', $this->value, '='); - $this->query->addWhere('AND', 'content_moderation_state_field_data.content_entity_type_id', 'node', '='); - } - } - -} diff --git a/docroot/modules/custom/va_gov_workflow/va_gov_workflow.module b/docroot/modules/custom/va_gov_workflow/va_gov_workflow.module index 22b282ff9aa..65ba0c93d2a 100644 --- a/docroot/modules/custom/va_gov_workflow/va_gov_workflow.module +++ b/docroot/modules/custom/va_gov_workflow/va_gov_workflow.module @@ -7,7 +7,6 @@ use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Routing\RouteMatchInterface; -use Drupal\Core\Entity\ContentEntityTypeInterface; /** * Implements hook_help(). @@ -39,36 +38,3 @@ function _va_gov_workflow_validate_required_revision_message(array $form, FormSt $form_state->setErrorByName('revision_log][0][value', t('Revision log message is required')); } } - -/** - * Implements hook_entity_base_field_info_alter(). - * - * {@inheritdoc} - */ -function va_gov_workflow_entity_base_field_info_alter(&$fields, ContentEntityTypeInterface $entity_type) { - // Display the revision_log_message field. - if ($entity_type->id() == 'taxonomy_term' && isset($fields['revision_log_message'])) { - // Grab the existing options so we don't stomp them without intent. - $form_options = $fields['revision_log_message']->getDisplayOptions('form'); - // For some reason the field defaults to region = hidden. - $form_options['region'] = 'content'; - $fields['revision_log_message'] - ->setRequired(TRUE) - ->setDisplayOptions('form', $form_options); - } -} - -/** - * Implements hook_views_data_alter(). - */ -function va_gov_workflow_views_data_alter(array &$data) { - $data['node']['moderation_state_multiple_workflow_filter'] = [ - 'title' => t('Moderation state across workflows'), - 'filter' => [ - 'title' => t('Moderation state'), - 'help' => t('Provides a filter for nodes by their moderation state across multiple workflows.'), - 'field' => 'nid', - 'id' => 'moderation_state_multiple_workflow_filter', - ], - ]; -}