PluralVariants::getSourceElement

protected PluralVariants::getSourceElement(LanguageInterface $source_language, $source_config)

Returns the source element for a given configuration definition.

This can be either a render array that actually outputs the source values directly or a read-only form element with the source values depending on what is considered to provide a more intuitive user interface for the translator.

Parameters

\Drupal\Core\Language\LanguageInterface $source_language: Thee source language of the configuration object.

mixed $source_config: The configuration value of the element in the source language.

Return value

array A render array for the source value.

Overrides FormElementBase::getSourceElement

File

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

Class

PluralVariants
Defines form elements for plurals in configuration translation.

Namespace

Drupal\config_translation\FormElement

Code

protected function getSourceElement(LanguageInterface $source_language, $source_config) {
  $plurals = $this->getNumberOfPlurals($source_language->getId());
  $values = explode(LOCALE_PLURAL_DELIMITER, $source_config);
  $element = array(
    '#type' => 'fieldset',
    '#title' => SafeMarkup::format('@label <span class="visually-hidden">(@source_language)</span>', array(
      // 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] = array(
      '#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' => SafeMarkup::format('<span lang="@langcode">@value</span>', array(
        '@langcode' => $source_language->getId(),
        '@value' => isset($values[$i]) ? $values[$i] : $this->t('(Empty)'),
      )),
    );
  }
  return $element;
}
doc_Drupal
2016-10-29 09:34:21
Comments
Leave a Comment

Please login to continue.