function content_translation_language_configuration_element_validate

Same name and namespace in other branches
  1. 8.9.x core/modules/content_translation/content_translation.module \content_translation_language_configuration_element_validate()
  2. 10 core/modules/content_translation/content_translation.module \content_translation_language_configuration_element_validate()
  3. 11.x core/modules/content_translation/content_translation.module \content_translation_language_configuration_element_validate()

Form validation handler for element added with content_translation_language_configuration_element_process().

Checks whether translation can be enabled: if language is set to one of the special languages and language selector is not hidden, translation cannot be enabled.

See also

content_translation_language_configuration_element_submit()

1 string reference to 'content_translation_language_configuration_element_validate'
content_translation_language_configuration_element_process in core/modules/content_translation/content_translation.module
Process callback: Expands the language_configuration form element.

File

core/modules/content_translation/content_translation.module, line 617

Code

function content_translation_language_configuration_element_validate($element, FormStateInterface $form_state, array $form) {
    $key = $form_state->get([
        'content_translation',
        'key',
    ]);
    $values = $form_state->getValue($key);
    if (!$values['language_alterable'] && $values['content_translation'] && \Drupal::languageManager()->isLanguageLocked($values['langcode'])) {
        foreach (\Drupal::languageManager()->getLanguages(LanguageInterface::STATE_LOCKED) as $language) {
            $locked_languages[$language->getId()] = $language->getName();
        }
        // @todo Set the correct form element name as soon as the element parents
        //   are correctly set. We should be using NestedArray::getValue() but for
        //   now we cannot.
        $form_state->setErrorByName('', t('"Show language selector" is not compatible with translating content that has default language: %choice. Either do not hide the language selector or pick a specific language.', [
            '%choice' => $locked_languages[$values['langcode']],
        ]));
    }
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.