Problem/Motivation

These two tickets:

change the name for moderation state fields from new_state to moderation state. Thank's to this, we can simplify our logic inside ModerationStateChangeConfirmDialog::formAlter(). Now it looks like:

public function formAlter(array &$form, FormStateInterface $form_state, $form_id) {
    if ($this->isApplicable($form_state)) {
      $ajax = [
        'callback' => [$this, 'modalDialogAjax'],
        'event' => 'change',
        'progress' => [
          'type' => 'throbber',
          'message' => $this->t('Checking references'),
        ],
      ];

      if ($this->isContentEntityForm($form_state)) {
        // Moderation info block alter.
        if ($form_state->getFormObject()->getOperation() === 'moderate') {
          $form['new_state']['widget'][0]['state']['#ajax'] = $ajax;
        }
        // Entity edit form alter.
        else {
          $form['moderation_state']['widget'][0]['state']['#ajax'] = $ajax;
        }
      }
      elseif ($this->isContentModerationForm($form_state)) {
        $form['new_state']['#ajax'] = $ajax;
      }
    }
  }

Proposed resolution

Let's do something like this:

public function formAlter(array &$form, FormStateInterface $form_state, $form_id) {
    if ($this->isApplicable($form_state)) {
      $form['moderation_state']['widget'][0]['state']['#ajax'] = [
        'callback' => [$this, 'modalDialogAjax'],
        'event' => 'change',
        'progress' => [
          'type' => 'throbber',
          'message' => $this->t('Checking references'),
        ],
      ];
    }
  }

Second thing is that now \Drupal\content_moderation\Form\EntityModerationForm extends \Drupal\Core\Entity\ContentEntityForm and logic inside ModerationStateChangeConfirmDialog can be simplified.

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

gugalamaciek created an issue. See original summary.

gugalamaciek’s picture

Issue summary: View changes

gugalamaciek’s picture

Status: Active » Needs review
gugalamaciek’s picture

Assigned: gugalamaciek » Unassigned