class Language in Drupal 10
Same name in this branch
- 10 core/lib/Drupal/Core/Language/Language.php \Drupal\Core\Language\Language
- 10 core/modules/ckeditor/src/Plugin/CKEditorPlugin/Language.php \Drupal\ckeditor\Plugin\CKEditorPlugin\Language
- 10 core/modules/language/src/Plugin/Condition/Language.php \Drupal\language\Plugin\Condition\Language
- 10 core/modules/ckeditor5/src/Plugin/CKEditor5Plugin/Language.php \Drupal\ckeditor5\Plugin\CKEditor5Plugin\Language
- 10 core/lib/Drupal/Core/TypedData/Plugin/DataType/Language.php \Drupal\Core\TypedData\Plugin\DataType\Language
- 10 core/modules/language/src/Plugin/migrate/source/Language.php \Drupal\language\Plugin\migrate\source\Language
Same name and namespace in other branches
- 8 core/lib/Drupal/Core/TypedData/Plugin/DataType/Language.php \Drupal\Core\TypedData\Plugin\DataType\Language
- 9 core/lib/Drupal/Core/TypedData/Plugin/DataType/Language.php \Drupal\Core\TypedData\Plugin\DataType\Language
Defines the 'language' data type.
The plain value of a language is the language object, i.e. an instance of \Drupal\Core\Language\Language. For setting the value the language object or the language code as string may be passed.
Plugin annotation
@DataType(
id = "language",
label = @Translation("Language"),
description = @Translation("A language object.")
)
Hierarchy
- class \Drupal\Core\TypedData\Plugin\DataType\Language extends \Drupal\Core\TypedData\TypedData
Expanded class hierarchy of Language
46 string references to 'Language'
- ckeditor.schema.yml in core/
modules/ ckeditor/ config/ schema/ ckeditor.schema.yml - core/modules/ckeditor/config/schema/ckeditor.schema.yml
- ckeditor5.ckeditor5.yml in core/
modules/ ckeditor5/ ckeditor5.ckeditor5.yml - core/modules/ckeditor5/ckeditor5.ckeditor5.yml
- ckeditor5.schema.yml in core/
modules/ ckeditor5/ config/ schema/ ckeditor5.schema.yml - core/modules/ckeditor5/config/schema/ckeditor5.schema.yml
- ConfigTestForm::form in core/
modules/ config/ tests/ config_test/ src/ ConfigTestForm.php - ConfigTranslationController::itemPage in core/
modules/ config_translation/ src/ Controller/ ConfigTranslationController.php - Language translations overview page for a configuration name.
File
- core/
lib/ Drupal/ Core/ TypedData/ Plugin/ DataType/ Language.php, line 20
Namespace
Drupal\Core\TypedData\Plugin\DataTypeView source
class Language extends TypedData {
/**
* The id of the language.
*
* @var string
*/
protected $id;
/**
* @var \Drupal\Core\Language
*/
protected $language;
/**
* Overrides TypedData::getValue().
*
* @return \Drupal\Core\Language\LanguageInterface|null
*/
public function getValue() {
if (!isset($this->language) && $this->id) {
$this->language = \Drupal::languageManager()
->getLanguage($this->id);
}
return $this->language;
}
/**
* Overrides TypedData::setValue().
*
* Both the langcode and the language object may be passed as value.
*/
public function setValue($value, $notify = TRUE) {
// Support passing language objects.
if (is_object($value)) {
$this->id = $value
->getId();
$this->language = $value;
}
elseif (isset($value) && !is_scalar($value)) {
throw new \InvalidArgumentException('Value is no valid langcode or language object.');
}
else {
$this->id = $value;
$this->language = NULL;
}
// Notify the parent of any changes.
if ($notify && isset($this->parent)) {
$this->parent
->onChange($this->name);
}
}
/**
* {@inheritdoc}
*/
public function getString() {
$language = $this
->getValue();
return $language ? $language
->getName() : '';
}
/**
* {@inheritdoc}
*/
public function id() {
if (isset($this->id)) {
return $this->id;
}
elseif (isset($this->language)) {
return $this->language
->getId();
}
}
}