function PluralVariants::getSourceElement
Same name in other branches
- 8.9.x core/modules/config_translation/src/FormElement/PluralVariants.php \Drupal\config_translation\FormElement\PluralVariants::getSourceElement()
- 10 core/modules/config_translation/src/FormElement/PluralVariants.php \Drupal\config_translation\FormElement\PluralVariants::getSourceElement()
- 11.x core/modules/config_translation/src/FormElement/PluralVariants.php \Drupal\config_translation\FormElement\PluralVariants::getSourceElement()
Overrides FormElementBase::getSourceElement
File
-
core/
modules/ config_translation/ src/ FormElement/ PluralVariants.php, line 19
Class
- PluralVariants
- Defines form elements for plurals in configuration translation.
Namespace
Drupal\config_translation\FormElementCode
protected function getSourceElement(LanguageInterface $source_language, $source_config) {
$plurals = $this->getNumberOfPlurals($source_language->getId());
$values = explode(PoItem::DELIMITER, $source_config);
$element = [
'#type' => 'fieldset',
'#title' => new FormattableMarkup('@label <span class="visually-hidden">(@source_language)</span>', [
// Labels originate from configuration schema and are translatable.
'@label' => $this->t($this->definition
->getLabel()),
'@source_language' => $source_language->getName(),
]),
'#tree' => TRUE,
];
for ($i = 0; $i < $plurals; $i++) {
$element[$i] = [
'#type' => 'item',
// @todo Should use better labels https://www.drupal.org/node/2499639
'#title' => $i == 0 ? $this->t('Singular form') : $this->formatPlural($i, 'First plural form', '@count. plural form'),
'#markup' => new FormattableMarkup('<span lang="@langcode">@value</span>', [
'@langcode' => $source_language->getId(),
'@value' => $values[$i] ?? $this->t('(Empty)'),
]),
];
}
return $element;
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.