Problem/Motivation

Currently the latest revision is loaded for the content moderation view. This is not always the revision that is loaded in entity forms during content editing, which is highly confusing. The entity converter which is responsible for deciding which revision should form the basis of the next edit doesn't actually load only the latest revision, but the latest translation affected revision:

...
      // Retrieve the latest revision ID taking translations into account.
      $langcode = $this->languageManager()
        ->getCurrentLanguage(LanguageInterface::TYPE_CONTENT)
        ->getId();
      $entity = $this->getLatestTranslationAffectedRevision($entity, $langcode);
...

Unless the views filter matches these semantics exactly, the views results are highly confusing and do not represent the revision which will actually be used as the basis for the next content edit. As far as users are concerned, when adding translations, drafts of the original language simply disappear (filtered out by the combination of the "latest" and "not published" filters in the views configuration).

Proposed resolution

Introduce a "LatestRevisionTranslationAffected" filter, ensure the content moderation view uses this.

Remaining tasks

  • Add a filter plugin for "latest translation affected revision".
  • Run an update on the content moderation view to use this plugin (with a test).
  • Write a functional test for content moderation to verify all the components working together.

User interface changes

Fixes the content moderation view when used with multilingual sites.

API changes

An additional views filter.

Data model changes

Original report

I have created a new translatable content type and associated a workflow with 3 states to it. I created a new instance of this type and also created it's translation. Also a view has been created where the filter criteria was set to the Final (published, default revision) moderation state. As I set the moderation state of the original item to this Final value, the translated one seemed to remain in it's previous state (Draft), but the view lists both of the records like both were in the Final state.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

zolt_toth created an issue. See original summary.

zolt_toth’s picture

Version: 8.5.x-dev » 8.5.5
Sam152’s picture

Would it be possible to get an export of the configuration of the view in question? It would also be helpful to see some of the relevant output from the content_moderation_state entity tables:

select * from content_moderation_state_field_revision;

Sam152’s picture

Status: Active » Postponed (maintainer needs more info)
olivier.br’s picture

Title: Problem with the moderation state filter in views » Problem with the moderation state filter in views with multilingual content
Version: 8.5.5 » 8.6.1
Status: Postponed (maintainer needs more info) » Active

Hi,
Maybe i can provide some details.
I have the same problem with this setup :
- Drupal core 8.6.1
- 2 languages enabled
- default workflow enabled for all content types.

The duplicate rows issue is solved by: https://www.drupal.org/project/drupal/issues/2977276

Remains this problem: the filter "Content revision: Is Latest Revision" filters the latest revision regardless the language.

ie :
- i have an original node in draft state, and i create a translated version in draft state -> the moderated content view only shows the translated version.
- I have an original node in draft state and a translated version in draft state, i publish the original node -> the moderated content view will display nothing because the latest revision for all multilingual versions is the published one.

I could reproduce this behavior on https://simplytest.me/ without any contrib module enable.

The filter "Content revision: Is Latest Revision" should filter the latest revision for each translated version.

Sam152’s picture

Thanks for the additional information, that's really helpful. I'm going to try reproduce this.

Sam152’s picture

Version: 8.6.1 » 8.7.x-dev
FileSize
221.21 KB

I can confirm using the steps from #5, when creating a pending revision of a translation, the latest revision of the default language seems to revert to "published". State of the CMS entity table:

mysql> select revision_id as rid, langcode as lang, moderation_state as mod_state, content_entity_revision_id as content_revid, revision_translation_affected as rev_translation_affected from content_moderation_state_field_revision order by revision_id DESC limit 4;
+-----+------+-----------+---------------+--------------------------+
| rid | lang | mod_state | content_revid | rev_translation_affected |
+-----+------+-----------+---------------+--------------------------+
|   5 | en   | published |             5 |                     NULL |
|   5 | ca   | draft     |             5 |                        1 |
|   4 | en   | draft     |             4 |                        1 |
|   4 | ca   | published |             4 |                     NULL |
+-----+------+-----------+---------------+--------------------------+
4 rows in set (0.00 sec)

And the content view:

So this this is actually working exactly as intended, the latest 'en' revision in this case was "published". So I think we actually need a filter which replicates the logic that is in our entity converter:

  if ($entity instanceof RevisionableInterface && !empty($definition['load_latest_revision']) && $entity_definition->isRevisionable()) {
      // Retrieve the latest revision ID taking translations into account.
      $langcode = $this->languageManager()
        ->getCurrentLanguage(LanguageInterface::TYPE_CONTENT)
        ->getId();
      $entity = $this->getLatestTranslationAffectedRevision($entity, $langcode);
    }

We need a filter that loads the latest translation affected revision, not the latest revision unconditionally.

Sam152’s picture

Title: Problem with the moderation state filter in views with multilingual content » Users expect the "latest translation affected revision" not the "latest revision" in the views UI when moderating content
Issue summary: View changes

Fixing issue summary.

Sam152’s picture

Issue summary: View changes
Sam152’s picture

Issue summary: View changes

Some better wording of the root cause in the IS.

Sam152’s picture

Issue summary: View changes
Sam152’s picture

Status: Active » Needs review
FileSize
1.03 KB

Here is a patch of the existing latest revision filter which works when combined with the other one. It'll need test coverage and to be moved into its own filter.

olivier.br’s picture

patch in #12 is solving the issue for me.
Thank you !

Sam152’s picture

Here is the fix as a new filter with tests. Will still need an update hook and tests to replace the 'latest_revision' filter plugin with the 'latest_translation_affected_revision' plugin on the content moderation view.

Sam152’s picture

Issue summary: View changes

Status: Needs review » Needs work

The last submitted patch, 14: 2983958-14.patch, failed testing. View results

amateescu’s picture

Are you sure this needs to be a new filter? I think letting the use choose between a 'latest_revision' and a 'latest_translation_affected_revision' can get very confusing, so maybe it's easier to use the patch from #12 with an extra check on the entity type being translatable or not. And/or maybe make it configurable as well, with the behavior of checking the latest affected revision enabled by default, since that's most likely what the user would expect.

jibran’s picture

Issue tags: +VDC

And/or maybe make it configurable as well, with the behavior of checking the latest affected revision enabled by default, since that's most likely what the user would expect.

This makes sense to me.

+++ b/core/modules/views/src/Plugin/views/filter/LatestTranslationAffectedRevisionTest.php
@@ -0,0 +1,116 @@
+class LatestTranslationAffectedRevisionTest extends FilterPluginBase implements ContainerFactoryPluginInterface {

This is not a test plugin this is an actual plugin so we should remove the suffix.

matsbla’s picture

I tested path #14 and it works great! To get such a filter could also maybe be helpful for #2999938: Replace content translation table with a view

Sam152’s picture

Thanks for the review!

I don't think it makes sense to change the behavior of the filter, given it's actually working correctly. I'm also not really a fan of making it configurable given it already feels quite complex. I'd rather they be split out so they can be documented, tested and iterated on in isolation. I think this is especially valid given the joins themselves are a candidate to be normalized into base tables in the future, having these as two seperate things may allow those to be unpicked easier down the line.

amateescu’s picture

Okay, then let's go ahead with two filters :)

Sam152’s picture

I think this is ready for a complete review. It includes:

  • An integration test of the new filter replicating the conditions of the original bug report.
  • Upgrade path and test for the moderated content view that ships with CM.
  • The latest revision translation affected filter and tests from #14.

Status: Needs review » Needs work

The last submitted patch, 22: 2983958-22.patch, failed testing. View results

Sam152’s picture

The last submitted patch, 24: 2983958-integration-test-only-24.patch, failed testing. View results

greggmarshall’s picture

Patch #24 works in my case (documented in #3007456: Content Moderation State Field Revision with 2 Languages Set to Published). Thanks for a solution.

amateescu’s picture

Status: Needs review » Reviewed & tested by the community

Reviewed the patch again and it looks great. Nice to have some manual testing as well, thanks @greggmarshall :)

Sam152’s picture

Thanks for the manual testing and following up with another review.

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 24: 2983958-24.patch, failed testing. View results

Sam152’s picture

Status: Needs work » Reviewed & tested by the community
pavlosdan’s picture

Another +1 for this patch. We just came across the same issue as described by @greggmarshall in #3007456: Content Moderation State Field Revision with 2 Languages Set to Published which led us here. The new filter works as advertised :)

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 24: 2983958-24.patch, failed testing. View results

Sam152’s picture

Status: Needs work » Reviewed & tested by the community

Fail was in HEAD, back to RTBC.

Upchuk’s picture

Referencing #3015312: The ModeratedNodeListBuilder does not show the correct revisions as it is responsible for achieving what the View is doing but via the list builder. They should go hand in hand.

catch’s picture

This looks like potentially a real test failure:

Testing Drupal\Tests\content_moderation\Kernel\ModerationStateFieldItemListTest
....................F                                             21 / 21 (100%)

Time: 17.99 seconds, Memory: 4.00MB

There was 1 failure:

1) Drupal\Tests\content_moderation\Kernel\ModerationStateFieldItemListTest::testWithExistingUnmoderatedContent
Failed asserting that null matches expected 'published'.

/var/www/html/core/tests/Drupal/KernelTests/KernelTestBase.php:1121
/var/www/html/core/modules/content_moderation/tests/src/Kernel/ModerationStateFieldItemListTest.php:390

https://www.drupal.org/pift-ci-job/1115550

Sam152’s picture

Hey @catch, thanks for reviewing. The failure in that test run was introduced in HEAD and then reverted, so I don't think we've got an intermittent fail in this issue.

catch’s picture

Status: Reviewed & tested by the community » Fixed

Committed bd72409 and pushed to 8.7.x. Thanks!

  • catch committed bd72409 on 8.7.x
    Issue #2983958 by Sam152, zolt_toth, amateescu, olivier.br, jibran,...

Status: Fixed » Closed (fixed)

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