trait LangcodeTrait in Coder 8.3
Same name and namespace in other branches
- 8.2 coder_sniffer/DrupalPractice/Test/good/good.php \LangcodeTrait
- 8.3.x tests/DrupalPractice/good/good.php \LangcodeTrait
A trait containing helper methods for language handling.
Hierarchy
- trait \LangcodeTrait
File
- tests/
DrupalPractice/ good/ good.php, line 78
View source
trait LangcodeTrait {
/**
* Name of language.
*
* @var string
*/
protected $langcode;
/**
* A fully-populated language object.
*
* @var \Drupal\core\Language\LanguageInterface|null
*/
protected $lang;
/**
* Select language.
*
* @param string $langcode
* Language code.
*
* @return $this
* Current instance.
*/
public function setLangcode($langcode) {
$this->langcode = $langcode;
$this->lang = \Drupal::languageManager()
->getLanguage($this->langcode);
return $this;
}
/**
* Get code of currently active language.
*
* @return string
* Language code.
*/
public function getLangcode() {
if (!isset($this->langcode)) {
$lang = \Drupal::languageManager()
->getCurrentLanguage();
$this
->setLangcode($lang
->getId());
}
return $this->langcode;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
LangcodeTrait:: |
protected | property | A fully-populated language object. | |
LangcodeTrait:: |
protected | property | Name of language. | |
LangcodeTrait:: |
public | function | Get code of currently active language. | |
LangcodeTrait:: |
public | function | Select language. |