function PluralVariants::getTranslationElement

Same name in other branches
  1. 8.9.x core/modules/config_translation/src/FormElement/PluralVariants.php \Drupal\config_translation\FormElement\PluralVariants::getTranslationElement()
  2. 10 core/modules/config_translation/src/FormElement/PluralVariants.php \Drupal\config_translation\FormElement\PluralVariants::getTranslationElement()
  3. 11.x core/modules/config_translation/src/FormElement/PluralVariants.php \Drupal\config_translation\FormElement\PluralVariants::getTranslationElement()

Overrides FormElementBase::getTranslationElement

File

core/modules/config_translation/src/FormElement/PluralVariants.php, line 48

Class

PluralVariants
Defines form elements for plurals in configuration translation.

Namespace

Drupal\config_translation\FormElement

Code

protected function getTranslationElement(LanguageInterface $translation_language, $source_config, $translation_config) {
    $plurals = $this->getNumberOfPlurals($translation_language->getId());
    $values = explode(PoItem::DELIMITER, $translation_config);
    $element = [
        '#type' => 'fieldset',
        '#title' => new FormattableMarkup('@label <span class="visually-hidden">(@translation_language)</span>', [
            // Labels originate from configuration schema and are translatable.
'@label' => $this->t($this->definition
                ->getLabel()),
            '@translation_language' => $translation_language->getName(),
        ]),
        '#tree' => TRUE,
    ];
    for ($i = 0; $i < $plurals; $i++) {
        $element[$i] = [
            '#type' => 'textfield',
            // @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'),
            '#default_value' => $values[$i] ?? '',
            '#attributes' => [
                'lang' => $translation_language->getId(),
            ],
        ];
    }
    return $element;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.