/** * {@inheritdoc} */ 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'); 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, t('The language tags should differ between languages and from the generic tags.')); } } } } } }
/** * Helper function for gettings the tags. * * Old: _geshifilter_get_tags. * * @todo: recreate a cache for this function. */ protected function getTags() { $generic_code_tags = GeshiFilter::tagSplit($this->tags()); $language_tags = array(); $tag_to_lang = array(); $enabled_languages = GeshiFilter::getEnabledLanguages(); foreach ($enabled_languages as $language => $fullname) { $lang_tags = GeshiFilter::tagSplit($this->languageTags($language)); foreach ($lang_tags as $lang_tag) { $language_tags[] = $lang_tag; $tag_to_lang[$lang_tag] = $language; } } return array($generic_code_tags, $language_tags, $tag_to_lang); }