trait LanguageConfigCollectionNameTrait
Same name in other branches
- 8.9.x core/modules/language/src/Config/LanguageConfigCollectionNameTrait.php \Drupal\language\Config\LanguageConfigCollectionNameTrait
- 10 core/modules/language/src/Config/LanguageConfigCollectionNameTrait.php \Drupal\language\Config\LanguageConfigCollectionNameTrait
- 11.x core/modules/language/src/Config/LanguageConfigCollectionNameTrait.php \Drupal\language\Config\LanguageConfigCollectionNameTrait
Provides a common trait for working with language override collection names.
Hierarchy
- trait \Drupal\language\Config\LanguageConfigCollectionNameTrait
File
-
core/
modules/ language/ src/ Config/ LanguageConfigCollectionNameTrait.php, line 8
Namespace
Drupal\language\ConfigView source
trait LanguageConfigCollectionNameTrait {
/**
* Creates a configuration collection name based on a language code.
*
* @param string $langcode
* The language code.
*
* @return string
* The configuration collection name for a language code.
*/
protected function createConfigCollectionName($langcode) {
return 'language.' . $langcode;
}
/**
* Converts a configuration collection name to a language code.
*
* @param string $collection
* The configuration collection name.
*
* @return string
* The language code of the collection.
*
* @throws \InvalidArgumentException
* Exception thrown if the provided collection name is not in the format
* "language.LANGCODE".
*
* @see self::createConfigCollectionName()
*/
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];
}
}
Members
Title Sort descending | Modifiers | Object type | Summary |
---|---|---|---|
LanguageConfigCollectionNameTrait::createConfigCollectionName | protected | function | Creates a configuration collection name based on a language code. |
LanguageConfigCollectionNameTrait::getLangcodeFromCollectionName | protected | function | Converts a configuration collection name to a language code. |
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.