Mercurial > hg > isophonics-drupal-site
annotate core/modules/language/src/Config/LanguageConfigCollectionNameTrait.php @ 19:fa3358dc1485 tip
Add ndrum files
author | Chris Cannam |
---|---|
date | Wed, 28 Aug 2019 13:14:47 +0100 |
parents | 4c8ae668cc8c |
children |
rev | line source |
---|---|
Chris@0 | 1 <?php |
Chris@0 | 2 |
Chris@0 | 3 namespace Drupal\language\Config; |
Chris@0 | 4 |
Chris@0 | 5 /** |
Chris@0 | 6 * Provides a common trait for working with language override collection names. |
Chris@0 | 7 */ |
Chris@0 | 8 trait LanguageConfigCollectionNameTrait { |
Chris@0 | 9 |
Chris@0 | 10 /** |
Chris@0 | 11 * Creates a configuration collection name based on a language code. |
Chris@0 | 12 * |
Chris@0 | 13 * @param string $langcode |
Chris@0 | 14 * The language code. |
Chris@0 | 15 * |
Chris@0 | 16 * @return string |
Chris@0 | 17 * The configuration collection name for a language code. |
Chris@0 | 18 */ |
Chris@0 | 19 protected function createConfigCollectionName($langcode) { |
Chris@0 | 20 return 'language.' . $langcode; |
Chris@0 | 21 } |
Chris@0 | 22 |
Chris@0 | 23 /** |
Chris@0 | 24 * Converts a configuration collection name to a language code. |
Chris@0 | 25 * |
Chris@0 | 26 * @param string $collection |
Chris@0 | 27 * The configuration collection name. |
Chris@0 | 28 * |
Chris@0 | 29 * @return string |
Chris@0 | 30 * The language code of the collection. |
Chris@0 | 31 * |
Chris@0 | 32 * @throws \InvalidArgumentException |
Chris@0 | 33 * Exception thrown if the provided collection name is not in the format |
Chris@0 | 34 * "language.LANGCODE". |
Chris@0 | 35 * |
Chris@0 | 36 * @see self::createConfigCollectionName() |
Chris@0 | 37 */ |
Chris@0 | 38 protected function getLangcodeFromCollectionName($collection) { |
Chris@0 | 39 preg_match('/^language\.(.*)$/', $collection, $matches); |
Chris@0 | 40 if (!isset($matches[1])) { |
Chris@0 | 41 throw new \InvalidArgumentException("'$collection' is not a valid language override collection"); |
Chris@0 | 42 } |
Chris@0 | 43 return $matches[1]; |
Chris@0 | 44 } |
Chris@0 | 45 |
Chris@0 | 46 } |