You are here

public function GeshiFilterLanguagesForm::validateForm in GeSHi Filter for syntax highlighting 8

Same name and namespace in other branches
  1. 8.2 src/Form/GeshiFilterLanguagesForm.php \Drupal\geshifilter\Form\GeshiFilterLanguagesForm::validateForm()

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/GeshiFilterLanguagesForm.php, line 70

Class

GeshiFilterLanguagesForm
Form used to set enable/disabled for languages.

Namespace

Drupal\geshifilter\Form

Code

public function validateForm(array &$form, FormStateInterface $form_state) {
  $config = $this
    ->config('geshifilter.settings');

  // Language tags should differ from each other.
  $languages = GeshiFilter::getAvailableLanguages();
  $values = $form_state
    ->getValue('language');
  $config = $this
    ->config('geshifilter.settings');
  $values = array_merge($config
    ->get('language'), $values);
  foreach ($languages as $language1 => $language_data1) {
    if ($values[$language1]['enabled'] == FALSE) {
      continue;
    }
    $tags1 = GeshiFilter::tagSplit($values[$language1]['tags']);

    // Check that other languages do not use these tags.
    foreach ($languages as $language2 => $language_data2) {

      // Check these tags against the tags of other enabled languages.
      if ($language1 == $language2) {
        continue;
      }

      // Get tags for $language2.
      $tags2 = GeshiFilter::tagSplit($values[$language2]['tags']);

      // Get generic tags.
      $generics = GeshiFilter::tagSplit($config
        ->get('tags'));
      $tags2 = array_merge($tags2, $generics);

      // And now we can check tags1 against tags2.
      foreach ($tags1 as $tag1) {
        foreach ($tags2 as $tag2) {
          if ($tag1 == $tag2) {
            $name = "language[{$language2}][tags]";
            $form_state
              ->setErrorByName($name, $this
              ->t('The language tags should differ between languages and from the generic tags.'));
          }
        }
      }
    }
  }
}