You are here

function disable_language_language_select_after_build in Disable language 8

After build callback for language_select widgets.

1 string reference to 'disable_language_language_select_after_build'
disable_language_field_widget_language_select_form_alter in ./disable_language.module
Implements hook_field_widget_WIDGET_TYPE_form_alter().

File

./disable_language.module, line 201
Contains disable_language.module.

Code

function disable_language_language_select_after_build($element, $form_state) {

  // Get disabled languages and remove them from options of language select.
  $disabled_languages = \Drupal::service('disable_language.disable_language_manager')
    ->getDisabledLanguages();
  foreach (array_keys($disabled_languages) as $langcode) {
    if (isset($element['value']['#options'][$langcode])) {
      unset($element['value']['#options'][$langcode]);
    }
  }
  return $element;
}