Content Moderation State entity is not properly created for migrated/imported entity with translations

Created on 30 December 2020, over 3 years ago
Updated 30 March 2023, about 1 year ago

Problem/Motivation

For a website that has already enabled the content_moderation module, when migrating the entities with translations altogether, as shown in the below demo code, the content_moderation module can not properly create the content_moderation_state entity for all the translations.

$node = \Drupal::entityTypeManager()->getStorage('node')->create(['type'=>'page','title'=>'Test en','moderation_state'=>[['value'=>'published']]]);
$node->addTranslation('ja',['title'=>'Test ja','moderation_state'=>[['value'=>'published']]]);
$node->addTranslation('zh-hans',['title'=>'Test ZH','moderation_state'=>[['value'=>'published']]]);
$node->addTranslation('de',['title'=>'Test DE','moderation_state'=>[['value'=>'published']]]);
$node->save();

Steps to reproduce

Proposed resolution

Remaining tasks

User interface changes

API changes

Data model changes

Release notes snippet

πŸ› Bug report
Status

Needs work

Version

9.5

Component
Content moderationΒ  β†’

Last updated about 5 hours ago

  • Maintained by
  • πŸ‡¦πŸ‡ΊAustralia @Sam152
Created by

πŸ‡¨πŸ‡³China weynhamz Ningbo

Live updates comments and jobs are added and updated live.
  • Needs tests

    The change is currently missing an automated test that fails when run with the original code, and succeeds when the bug has been fixed.

  • Needs issue summary update

    Issue summaries save everyone time if they are kept up-to-date. See Update issue summary task instructions.

Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • πŸ‡ΊπŸ‡ΈUnited States dww

    This issue came up as a random triage target for the #bugsmash initiative.

    Definitely looks like this is a real bug. ;) As such, it would probably be eligible for a backport to 9.5.x branch, so changing the version. Happy to report that the patch in #16 still applies cleanly to 10.1.x branch, too. So probably this will be an easy backport.

    Still needs tests (as tagged), and a summary update (as tagged), so the status is still accurate here that this bug needs work before it can be fixed in core.

    But there's no further triage we can do. Someone has to roll up their sleeves and write a test that demonstrates the bug and proves that the fix works.

    Thanks/sorry,
    -Derek

Production build 0.69.0 2024