getTranslationBuild example

    // @see \Drupal\config_translation\FormElement\FormElementBase::getElements()     $form['config_names'] = ['#type' => 'container'];
    foreach ($this->mapper->getConfigNames() as $name) {
      $form['config_names'][$name] = ['#type' => 'container'];

      $schema = $this->typedConfigManager->get($name);
      $source_config = $this->baseConfigData[$name];
      $translation_config = $this->configFactory()->get($name)->get();

      if ($form_element = $this->createFormElement($schema)) {
        $parents = ['config_names', $name];
        $form['config_names'][$name] += $form_element->getTranslationBuild($this->sourceLanguage, $this->language, $source_config$translation_config$parents);
      }
    }

    $form['actions']['#type'] = 'actions';
    $form['actions']['submit'] = [
      '#type' => 'submit',
      '#value' => $this->t('Save translation'),
      '#button_type' => 'primary',
    ];

    // Set the configuration language back.

  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',
            
Home | Imprint | This part of the site doesn't use cookies.