protected function TawkToExtraSettingsForm::validateVisibility in Tawk.to - Live chat application (Drupal 8) 8
Same name and namespace in other branches
- 8.2 src/Form/TawkToExtraSettingsForm.php \Drupal\tawk_to\Form\TawkToExtraSettingsForm::validateVisibility()
 
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 TawkToExtraSettingsForm::validateVisibility()
- TawkToExtraSettingsForm::validateForm in src/
Form/ TawkToExtraSettingsForm.php  - Form validation handler.
 
File
- src/
Form/ TawkToExtraSettingsForm.php, line 296  
Class
- TawkToExtraSettingsForm
 - Provides form for block instance forms.
 
Namespace
Drupal\tawk_to\FormCode
protected function validateVisibility(array $form, FormStateInterface $form_state) {
  // Validate visibility condition settings.
  foreach ($form_state
    ->getValue('visibility') as $conditionId => $values) {
    // All condition plugins use 'negate' as a Boolean in their schema.
    // However, certain form elements may return it as 0/1. Cast here to
    // ensure the data is in the expected type.
    if (array_key_exists('negate', $values)) {
      $form_state
        ->setValue([
        'visibility',
        $conditionId,
        'negate',
      ], (bool) $values['negate']);
    }
    // Allow the condition to validate the form.
    $condition = $form_state
      ->get([
      'conditions',
      $conditionId,
    ]);
    $condition
      ->validateConfigurationForm($form['visibility'][$conditionId], SubformState::createForSubform($form['visibility'][$conditionId], $form, $form_state));
  }
}