You are here

function allowed_languages_get_language_options in Allowed Languages 8

Same name and namespace in other branches
  1. 2.x allowed_languages.module \allowed_languages_get_language_options()

Get an array of languages to use with the allowed language checkboxes.

Return value

array An array of languages keyed by id => name.

2 calls to allowed_languages_get_language_options()
AllowedLanguagesUserFieldTest::testAllowedLanguagesGetLanguageOptions in tests/src/Kernel/AllowedLanguagesUserFieldTest.php
Test the function to get allowed language options.
allowed_languages_form_user_form_alter in ./allowed_languages.module
Add the allowed languages checkboxes to the user form.

File

./allowed_languages.module, line 239
Contains allowed_languages.module.

Code

function allowed_languages_get_language_options() {
  $language_options = [];

  /** @var \Drupal\language\Entity\ConfigurableLanguage[] $languages */
  $languages = \Drupal::entityTypeManager()
    ->getStorage('configurable_language')
    ->loadMultiple();

  // Get only languages that are not locked.
  foreach ($languages as $language) {
    if ($language
      ->isLocked()) {
      continue;
    }
    $language_options[$language
      ->id()] = $language
      ->getName();
  }
  asort($language_options);
  return $language_options;
}