Problem/Motivation

Discovered by @xjm in #2830581-26: Fix ContentModeration workflow type to calculate correct dependencies

Steps to reproduce:

  1. Install Standard.
  2. Enable content moderation.
  3. Add the default workflow to articles.
  4. Add the workflow to pages.
  5. Remove the workflow from articles.
  6. Re-add the workflow to articles.

Produced the diff

diff --git a/workflows.workflow.editorial.yml b/workflows.workflow.editorial.yml
index 8846c55..1713f6c 100644
--- a/workflows.workflow.editorial.yml
+++ b/workflows.workflow.editorial.yml
@@ -3,6 +3,7 @@ langcode: en
 status: true
 dependencies:
   config:
+    - node.type.article
     - node.type.page
   module:
     - content_moderation
@@ -67,4 +68,5 @@ type_settings:
       default_revision: true
   entity_types:
     node:
-      - page
+      1: article
+      0: page

In #11 @xjm discovered that entity types are not being sorted either.

Proposed resolution

Fix the sorts.

Remaining tasks

User interface changes

None

API changes

None

Data model changes

None

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

alexpott created an issue. See original summary.

xjm’s picture

Issue summary: View changes

Confirmed that the first two steps are not necessary, so updating the IS.

xjm’s picture

Issue summary: View changes

And making full STR from installation.

alexpott’s picture

Who knows why I added the second use of natsort() in core. The important thing is to sort the array consistently - natural sorting is unnecessary.

Also hey php why does natsort() behave like asort() and not sort()?

xjm’s picture

+++ b/core/modules/content_moderation/tests/src/Kernel/ContentModertaionWorkflowTypeApiTest.php
@@ -78,4 +78,20 @@ public function testAppliesToEntityTypeAndBundle() {
+    // The content moderation plugin does not valid the existence of the entity
+    // type or bundle.
+    $workflow_plugin->addEntityTypeAndBundle('fake_node', 'fake_page');
+    $workflow_plugin->addEntityTypeAndBundle('fake_node', 'fake_article');

Probably this bug and coverage relies on P coming before A in the alphabet, so let's mention that somehow?

xjm’s picture

Also I think the inline comment is a copypaste from the empty array test from the other issue.

alexpott’s picture

@xjm gonna wait for #2850592: Typos in ContentModertaionWorkflowTypeApiTest to reroll on top of fixing all my other spelling mistakes.

xjm’s picture

I'd prefer not to postpone a borderline-major sorting bug that causes diffs in config (and that causes diffs even by being fixed) on spelling fixes in a test.

xjm’s picture

Re: the diffs, we don't need an upgrade path because the module is alpha, but we might have considered it if it were stable to avoid unpredictable fixes at random the next time every affected workflow is resaved. Upgrade paths tend to get more annoying with time.

The last submitted patch, 4: 2850601-2.test-only.patch, failed testing.

xjm’s picture

It looks like the sorting for the entity type itself has the opposite bug (they are not sorted). Following the STR but replacing articles with basic content blocks:

diff --git a/workflows.workflow.editorial.yml b/workflows.workflow.editorial.yml
index ec86e27..01e1a5d 100644
--- a/workflows.workflow.editorial.yml
+++ b/workflows.workflow.editorial.yml
@@ -64,7 +64,5 @@ type_settings:
       published: true
       default_revision: true
   entity_types:
-    block_content:
-      - basic
     node:
       - page

then

diff --git a/workflows.workflow.editorial.yml b/workflows.workflow.editorial.yml
index 01e1a5d..b9550c2 100644
--- a/workflows.workflow.editorial.yml
+++ b/workflows.workflow.editorial.yml
@@ -66,3 +66,5 @@ type_settings:
   entity_types:
     node:
       - page
+    block_content:
+      - basic

Not sure about the scope but seems related.

xjm’s picture

xjm’s picture

Status: Needs review » Needs work

NW for #5, #6, and possibly #11.

alexpott’s picture

Title: ContentModeration workflow type plugin preserves numeric keys on sorting » ContentModeration workflow type plugin preserves numeric keys on sorting and not sorting entity types
Issue summary: View changes
Status: Needs work » Needs review
FileSize
2.5 KB
2.53 KB

@xjm nice spot on the entity type ordering. I think that it makes sense to fix that here. This issue reminds me that I really what to build sorting of config into schema so the implementations don't have to think so hard about it and when and when not to do it.

timmillwood’s picture

+++ b/core/modules/content_moderation/tests/src/Kernel/ContentModerationWorkflowTypeApiTest.php
@@ -78,4 +78,26 @@ public function testAppliesToEntityTypeAndBundle() {
+   * @covers ::removeEntityTypeAndBundle

How does this cover removeEntityTypeAndBundle? Maybe it'd be worth adding a few more bundles in the test, then removing one or two and checking the order again?

alexpott’s picture

@timmillwood nice spot with @covers. I don't think we need to add testing for that method here because the remove method doesn't touch the sorting at all. So we'd be testing for code that's not there and using the remove method is not necessary to reproduce the bug.

timmillwood’s picture

Status: Needs review » Reviewed & tested by the community

ok, sounds good.

xjm’s picture

xjm’s picture

Status: Reviewed & tested by the community » Needs work
  1. +++ b/core/modules/content_moderation/tests/src/Kernel/ContentModerationWorkflowTypeApiTest.php
    @@ -78,4 +78,25 @@ public function testAppliesToEntityTypeAndBundle() {
    +    // The content moderation plugin does not validate the existence of the
    +    // entity type or bundle. The entity types and bundles are intentionally
    +    // added in reverse alphabetical order.
    +    $workflow_plugin->addEntityTypeAndBundle('fake_node', 'fake_page');
    +    $workflow_plugin->addEntityTypeAndBundle('fake_block', 'fake_custom');
    +    $workflow_plugin->addEntityTypeAndBundle('fake_node', 'fake_article');
    ...
    +    $this->assertSame(
    +      ['fake_block' => ['fake_custom'], 'fake_node' => ['fake_article', 'fake_page']],
    +      $workflow_plugin->getConfiguration()['entity_types']
    +    );
    

    Does this provide the coverage it says for the entity types? Had to read it twice. I was going to suggest testing the two levels separately, but maybe that's not necessary. At least though let's have a test-only patch that's this test + the original fix only for the bundle keys to prove the coverage for the other bug as well.

  2. +++ b/core/modules/content_moderation/tests/src/Kernel/ContentModerationWorkflowTypeApiTest.php
    @@ -78,4 +78,25 @@ public function testAppliesToEntityTypeAndBundle() {
    +    // The entity type keys and bundle values should be sorted
    +    // sorted alphabetically. The bundle array index should not reflect the
    

    sorted sorted. Also looks like it can be rewrapped.

alexpott’s picture

Status: Needs work » Reviewed & tested by the community
FileSize
950 bytes
2.39 KB
2.44 KB

I've dropped the bit about entity type validation from this test - it is just noise here. And improved the other comments. Back to rtbc as these are comment improvements asked by a committer.

timmillwood’s picture

The interdiff doesn't seem right, but the patch look like it resolves the concerns in #19.

+1 to the RTBC in #20.

The last submitted patch, 20: 2850601-test-only-20.patch, failed testing.

alexpott’s picture

FileSize
1.84 KB

Here's the correct interdiff - thanks for reviewing the patch again @timmillwood

  • xjm committed eb8b64d on 8.4.x
    Issue #2850601 by alexpott, xjm, timmillwood: ContentModeration workflow...

  • xjm committed a93653c on 8.3.x
    Issue #2850601 by alexpott, xjm, timmillwood: ContentModeration workflow...
xjm’s picture

Version: 8.4.x-dev » 8.3.x-dev
Status: Reviewed & tested by the community » Fixed

Back to rtbc as these are comment improvements asked by a committer.

Hmm, meh to that. It's still a change that should undergo review. But @timmillwood has +1ed it so it is RTBC in any case.

Also the removal of the bit about validation was what I asked for in #6, so that looks good to me too. Thanks for the test-only patch; I double-checked for the "correct" fail on https://www.drupal.org/pift-ci-job/593625.

Committed to 8.4.x and cherry-picked to 8.3.x, since this is eliminating noisy/confusing config diffs (so improving the data model), and also since it's for an experimental module. Thanks!

xjm’s picture

Issue tags: +8.3.0 release notes
xjm’s picture

Title: ContentModeration workflow type plugin preserves numeric keys on sorting and not sorting entity types » ContentModeration workflow type plugin incorrectly preserves bundle keys on sorting and does not sort entity types
xjm’s picture

Issue tags: -8.3.0 release notes

@alexpott and I agreed that this does not need to go in the 8.3.0 release notes/changelog, since it is just a followup to the workflow conversion that happened in 8.3.x only and so was a regression since 8.2.x, but I am mentioning it in the beta release notes since the bug affected the alpha.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.