BundleModerationConfigurationForm::validateForm

public BundleModerationConfigurationForm::validateForm(array &$form, FormStateInterface $form_state)

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

core/modules/content_moderation/src/Form/BundleModerationConfigurationForm.php, line 167

Class

BundleModerationConfigurationForm
Form for configuring moderation usage on a given entity bundle.

Namespace

Drupal\content_moderation\Form

Code

1
2
3
4
5
6
7
8
9
public function validateForm(array &$form, FormStateInterface $form_state) {
  if ($form_state->getValue('enable_moderation_state')) {
    $allowed = array_keys(array_filter($form_state->getValue('allowed_moderation_states_published') + $form_state->getValue('allowed_moderation_states_unpublished')));
 
    if (($default = $form_state->getValue('default_moderation_state')) && !in_array($default, $allowed, TRUE)) {
      $form_state->setErrorByName('default_moderation_state', $this->t('The default moderation state must be one of the allowed states.'));
    }
  }
}
doc_Drupal
2025-01-10 15:47:30
Comments
Leave a Comment

Please login to continue.