function LanguageReference::getAllValidLangcodes

Same name in other branches
  1. 11.x core/lib/Drupal/Core/TypedData/Plugin/DataType/LanguageReference.php \Drupal\Core\TypedData\Plugin\DataType\LanguageReference::getAllValidLangcodes()

Returns all valid values for a `langcode` config value.

Return value

string[] All possible valid langcodes. This includes all langcodes in the standard list of human languages, along with special langcodes like `und`, `zxx`, and `site_default`, which Drupal uses internally. If any custom languages are defined, they will be included as well.

See also

\Drupal\Core\Language\LanguageManagerInterface::getLanguages()

\Drupal\Core\Language\LanguageManagerInterface::getStandardLanguageList()

1 call to LanguageReference::getAllValidLangcodes()
ConfigEntityValidationTestBase::testLangcode in core/tests/Drupal/KernelTests/Core/Config/ConfigEntityValidationTestBase.php
Tests that the config entity's langcode is validated.
1 string reference to 'LanguageReference::getAllValidLangcodes'
core.data_types.schema.yml in core/config/schema/core.data_types.schema.yml
core/config/schema/core.data_types.schema.yml

File

core/lib/Drupal/Core/TypedData/Plugin/DataType/LanguageReference.php, line 48

Class

LanguageReference
Defines the 'language_reference' data type.

Namespace

Drupal\Core\TypedData\Plugin\DataType

Code

public static function getAllValidLangcodes() : array {
    $language_manager = \Drupal::languageManager();
    return array_unique([
        array_keys($language_manager::getStandardLanguageList()),
        // We can't use LanguageInterface::STATE_ALL because it will exclude the
        // site default language in certain situations.
        // @see \Drupal\Core\Language\LanguageManager::filterLanguages()
array_keys($language_manager->getLanguages(LanguageInterface::STATE_LOCKED | LanguageInterface::STATE_CONFIGURABLE | LanguageInterface::STATE_SITE_DEFAULT)),
        // Include special language codes used internally.
LanguageInterface::LANGCODE_NOT_APPLICABLE,
        LanguageInterface::LANGCODE_SITE_DEFAULT,
        LanguageInterface::LANGCODE_DEFAULT,
        LanguageInterface::LANGCODE_SYSTEM,
        LanguageInterface::LANGCODE_NOT_SPECIFIED,
    ]);
}

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