function LanguageConfigCollectionNameTrait::getLangcodeFromCollectionName

Same name in other branches
  1. 9 core/modules/language/src/Config/LanguageConfigCollectionNameTrait.php \Drupal\language\Config\LanguageConfigCollectionNameTrait::getLangcodeFromCollectionName()
  2. 8.9.x core/modules/language/src/Config/LanguageConfigCollectionNameTrait.php \Drupal\language\Config\LanguageConfigCollectionNameTrait::getLangcodeFromCollectionName()
  3. 10 core/modules/language/src/Config/LanguageConfigCollectionNameTrait.php \Drupal\language\Config\LanguageConfigCollectionNameTrait::getLangcodeFromCollectionName()

Converts a configuration collection name to a language code.

Parameters

string $collection: The configuration collection name.

Return value

string The language code of the collection.

Throws

\InvalidArgumentException Exception thrown if the provided collection name is not in the format "language.LANGCODE".

See also

self::createConfigCollectionName()

2 calls to LanguageConfigCollectionNameTrait::getLangcodeFromCollectionName()
LanguageConfigFactoryOverride::createConfigObject in core/modules/language/src/Config/LanguageConfigFactoryOverride.php
LanguageConfigOverride::getLangcode in core/modules/language/src/Config/LanguageConfigOverride.php
Returns the language code of this language override.

File

core/modules/language/src/Config/LanguageConfigCollectionNameTrait.php, line 38

Class

LanguageConfigCollectionNameTrait
Provides a common trait for working with language override collection names.

Namespace

Drupal\language\Config

Code

protected function getLangcodeFromCollectionName($collection) {
    preg_match('/^language\\.(.*)$/', $collection, $matches);
    if (!isset($matches[1])) {
        throw new \InvalidArgumentException("'{$collection}' is not a valid language override collection");
    }
    return $matches[1];
}

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