Content Moderation incompatible with Form Mode

Created on 2 May 2018, about 6 years ago
Updated 20 January 2023, over 1 year ago

If I add content moderation to an entity that has a form mode enabled, clear cache will show the following error:
Notice: Undefined index: type in Drupal\content_moderation\Routing\ContentModerationRouteSubscriber->setLatestRevisionFlag() (line 74 of core/modules/content_moderation/src/Routing/ContentModerationRouteSubscriber.php).

The function setLatestRevisionFlag() in Drupal\content_moderation\Routing\ContentModerationRouteSubscriber assumes that the default entity form will always have the entity type in$parameter['type'].
However the form mode of an entity has the entity type in $parameter['targetEntityType'] instead.

More specifically, if I replace

if ($parameter['type'] === 'entity:' . $entity_type && !isset($parameter['load_latest_revision'])) {
  $parameter['load_latest_revision'] = TRUE;
 }

with

if (isset($parameter['type']) && $parameter['type'] === 'entity:' . $entity_type && !isset($parameter['load_latest_revision'])) {
  $parameter['load_latest_revision'] = TRUE;
}
elseif (isset($parameter['targetEntityType']) && $parameter['targetEntityType'] === $entity_type) {
  $parameter['type'] = 'entity:' . $entity_type;
  $parameter['load_latest_revision'] = TRUE;
}

apparently all will work fine, but I'm not sure if this is a robust solution.

πŸ› Bug report
Status

Postponed: needs info

Version

9.5

Component
Content moderationΒ  β†’

Last updated 3 days ago

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

πŸ‡ΊπŸ‡ΈUnited States helioha Philadelphia, PA

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.

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.

No activities found.

Production build 0.69.0 2024