3 namespace Drupal\language\Config;
6 * Provides a common trait for working with language override collection names.
8 trait LanguageConfigCollectionNameTrait {
11 * Creates a configuration collection name based on a language code.
13 * @param string $langcode
17 * The configuration collection name for a language code.
19 protected function createConfigCollectionName($langcode) {
20 return 'language.' . $langcode;
24 * Converts a configuration collection name to a language code.
26 * @param string $collection
27 * The configuration collection name.
30 * The language code of the collection.
32 * @throws \InvalidArgumentException
33 * Exception thrown if the provided collection name is not in the format
34 * "language.LANGCODE".
36 * @see self::createConfigCollectionName()
38 protected function getLangcodeFromCollectionName($collection) {
39 preg_match('/^language\.(.*)$/', $collection, $matches);
40 if (!isset($matches[1])) {
41 throw new \InvalidArgumentException("'$collection' is not a valid language override collection");