You are here

protected function ScriptForm::validateVisibility in Script Manager 8

Helper function to independently validate the visibility UI.

Parameters

array $form: A nested array form elements comprising the form.

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

1 call to ScriptForm::validateVisibility()
ScriptForm::validateForm in src/Form/ScriptForm.php
Form validation handler.

File

src/Form/ScriptForm.php, line 185

Class

ScriptForm
The script entity add form.

Namespace

Drupal\script_manager\Form

Code

protected function validateVisibility(array $form, FormStateInterface $form_state) {
  foreach ($form_state
    ->getValue('visibility', []) as $condition_id => $values) {
    if (array_key_exists('negate', $values)) {
      $values['negate'] = (bool) $values['negate'];
    }
    $condition = $form_state
      ->get([
      'conditions',
      $condition_id,
    ]);
    $condition_values = (new FormState())
      ->setValues($values);
    $condition
      ->validateConfigurationForm($form, $condition_values);
    $form_state
      ->setValue([
      'visibility',
      $condition_id,
    ], $condition_values
      ->getValues());
  }
}