function FormElementBase::getSourceElement

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

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.

1 call to FormElementBase::getSourceElement()
FormElementBase::getTranslationBuild in core/modules/config_translation/src/FormElement/FormElementBase.php
Builds a render array containing the source and translation form elements.
2 methods override FormElementBase::getSourceElement()
PluralVariants::getSourceElement in core/modules/config_translation/src/FormElement/PluralVariants.php
Returns the source element for a given configuration definition.
TextFormat::getSourceElement in core/modules/config_translation/src/FormElement/TextFormat.php
Returns the source element for a given configuration definition.

File

core/modules/config_translation/src/FormElement/FormElementBase.php, line 88

Class

FormElementBase
Provides a common base class for form elements.

Namespace

Drupal\config_translation\FormElement

Code

protected function getSourceElement(LanguageInterface $source_language, $source_config) {
    if ($source_config) {
        $value = '<span lang="' . $source_language->getId() . '">' . nl2br($source_config) . '</span>';
    }
    else {
        $value = $this->t('(Empty)');
    }
    return [
        '#type' => 'item',
        '#title' => $this->t('@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(),
        ]),
        '#markup' => $value,
    ];
}

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