function translation_entity_language_configuration_element_validate

Form validation handler for element added with translation_entity_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

translation_entity_language_configuration_element_submit()

1 string reference to 'translation_entity_language_configuration_element_validate'
translation_entity_language_configuration_element_process in drupal/core/modules/translation_entity/translation_entity.module
Process callback: Expands the language_configuration form element.

File

drupal/core/modules/translation_entity/translation_entity.module, line 947
Allows entities to be translated into different languages.

Code

function translation_entity_language_configuration_element_validate($element, array &$form_state, array $form) {
  $key = $form_state['translation_entity']['key'];
  $values = $form_state['values'][$key];
  if (language_is_locked($values['langcode']) && !$values['language_show'] && $values['translation_entity']) {
    foreach (language_list(Language::STATE_LOCKED) as $language) {
      $locked_languages[] = $language->name;
    }

    // @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_set_error('', 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.', array(
      '%choice' => $locked_languages[$values['langcode']],
    )));
  }
}