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.
Comments
Comment #2
gugalamaciek commentedComment #4
gugalamaciek commentedComment #5
gugalamaciek commented