Content Moderation hardcodes the 'edit' and 'default' form modes β€” other form modes are not supported

Created on 11 January 2018, almost 7 years ago
Updated 8 August 2024, 5 months ago

If an entity type uses a custom form mode and wants to use content moderation in this form mode to add new revisions. It won't be able to inherit the enforce revisions behaviour.

It's related to this function \Drupal\content_moderation\EntityTypeInfo::formAlter() limiting valid operations to "edit" and "default".

// Elseif statement.
$form_object instanceof ContentEntityFormInterface && in_array($form_object->getOperation(), ['edit', 'default'])

At the moment, if you want to show your form mode from a route, you need to add a custom operation as described here: https://www.drupal.org/docs/8/api/entity-api/display-modes-view-modes-an... β†’

It probably is the source of the problem since a editing an entity through a custom form mode is not really a new operation. It's more an edit operation with a special parameter that is the form mode with which we should render the form.

There is also no way to alter those valid operations without hacking core.

So at the moment, this limitation doesn't allow a custom form mode to have a "normal" behaviour for the "revision" form field.

πŸ› Bug report
Status

Active

Version

11.0 πŸ”₯

Component
Content moderationΒ  β†’

Last updated 24 days ago

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

πŸ‡«πŸ‡·France artusamak Bzh

Live updates comments and jobs are added and updated live.
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.

  • πŸ‡¦πŸ‡ΊAustralia acbramley

    Just ran into this codepath with paragraphs_library which ends up with the add operation on the add form (rather than default). This means that quite a few things don't happen in EntityTypeInfo::formAlter(), noteably for my case it was this little bit:

          if (isset($form['footer']) && in_array($form_object->getOperation(), ['edit', 'default'], TRUE)) {
            $form['moderation_state']['#group'] = 'footer';
          }
    

    Which was causing the moderation_state dropdown to be above the revision log field on the add screen but not the edit screen.

    This is also inside an elseif which checks isModeratedEntityEditForm - that also checks the form operations but also includes layout_builder.

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

    This bug also causes issues when adding translations that should be moderated.

    Translation bug for "add" form operation:
    • Contrib module or custom code adds a node form class for "add".
    • Adding a translation: The "\Drupal\content_translation\Controller\ContentTranslationController::add()" uses the following code to to set the form operation to "add".
      $operation = $entity->getEntityType()->hasHandlerClass('form', 'add') ? 'add' : 'default';
      
    • Entity Prepare Form: \Drupal\content_moderation\EntityTypeInfo::entityPrepareForm() uses EntityTypeInfo::isModeratedEntityEditForm() to alter the form to add a redirect. The "add" form mode is not detected by "isModeratedEntityEditForm".

      RESULT: The new revision is not created correctly leaving the entity's "revision_translation_affected" set to TRUE. This causes all sort of revisioning issues such as "revision_translation_affected" set to TRUE for the source translation's revision that is linked to the new language translation.
    • Form altering: \Drupal\content_moderation\EntityTypeInfo::formAlter() uses EntityTypeInfo::isModeratedEntityEditForm() to alter the form to add a redirect. RESULT: Redirect to the latest-version is not set since "add" is not listed in "isModeratedEntityEditForm"

    Proposed Resolution

    Add "add" to the form operation list in \Drupal\content_moderation\EntityTypeInfo::isModeratedEntityEditForm().
    This is not ideal but a similar patch has been already added to "isModeratedEntityEditForm()" for "layout_builder".

  • πŸ‡¬πŸ‡§United Kingdom kimberleycgm

    I've also run into this problem and agree it should be configurable in some way, but open to suggestions on the best way. A `hook_entity_type_info_edit_form_modes_alter` perhaps, or it being defined as part of the form mode. I'm happy to get started on a solution.

Production build 0.71.5 2024