You are here

public function ListElement::getTranslationBuild in Drupal 10

Same name and namespace in other branches
  1. 8 core/modules/config_translation/src/FormElement/ListElement.php \Drupal\config_translation\FormElement\ListElement::getTranslationBuild()
  2. 9 core/modules/config_translation/src/FormElement/ListElement.php \Drupal\config_translation\FormElement\ListElement::getTranslationBuild()

Builds a render array containing the source and translation form elements.

Parameters

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

\Drupal\Core\Language\LanguageInterface $translation_language: The language to display the translation form for.

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

mixed $translation_config: The configuration value of the element in the language to translate to.

array $parents: Parents array for the element in the form.

string|null $base_key: (optional) Base key to be used for the elements in the form. NULL for top-level form elements.

Return value

array A render array consisting of the source and translation elements for the source value.

Overrides ElementInterface::getTranslationBuild

File

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

Class

ListElement
Defines the list element for the configuration translation interface.

Namespace

Drupal\config_translation\FormElement

Code

public function getTranslationBuild(LanguageInterface $source_language, LanguageInterface $translation_language, $source_config, $translation_config, array $parents, $base_key = NULL) {
  $build = [];
  foreach ($this->element as $key => $element) {
    $sub_build = [];
    $element_key = isset($base_key) ? "{$base_key}.{$key}" : $key;
    $definition = $element
      ->getDataDefinition();
    if ($form_element = ConfigTranslationFormBase::createFormElement($element)) {
      $element_parents = array_merge($parents, [
        $key,
      ]);
      $sub_build += $form_element
        ->getTranslationBuild($source_language, $translation_language, $source_config[$key], $translation_config[$key], $element_parents, $element_key);
      if (empty($sub_build)) {
        continue;
      }

      // Build the sub-structure and include it with a wrapper in the form if
      // there are any translatable elements there.
      $build[$key] = [];
      if ($element instanceof TraversableTypedDataInterface) {
        $build[$key] = [
          '#type' => 'details',
          '#title' => $this
            ->getGroupTitle($definition, $sub_build),
          '#open' => empty($base_key),
        ];
      }
      $build[$key] += $sub_build;
    }
  }
  return $build;
}