You are here

public function QuickTransitionForm::validateForm in Moderation Sidebar 8

Form validation handler.

Parameters

array $form: An associative array containing the structure of the form.

\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.

Overrides FormBase::validateForm

File

src/Form/QuickTransitionForm.php, line 207

Class

QuickTransitionForm
The QuickTransitionForm provides quick buttons for changing transitions.

Namespace

Drupal\moderation_sidebar\Form

Code

public function validateForm(array &$form, FormStateInterface $form_state) {

  /** @var \Drupal\Core\Entity\ContentEntityInterface $entity */
  $entity = $form_state
    ->get('entity');

  /** @var \Drupal\content_moderation\Entity\ContentModerationStateInterface[] $transitions */
  $transitions = $this->validation
    ->getValidTransitions($entity, $this
    ->currentUser());

  // Add custom discard draft transition handled by ::discardDraft.
  $transitions['moderation-sidebar-discard-draft'] = '';
  $element = $form_state
    ->getTriggeringElement();
  if (!isset($transitions[$element['#id']])) {
    $form_state
      ->setError($element, $this
      ->t('Invalid transition selected.'));
  }
}