You are here

protected function WebformTranslationConfigManager::alterConfigWebformFormElements in Webform 6.x

Alter the webform configuration form elements.

Parameters

string $config_name: The webform configuration name.

array $config_element: The webform configuration element.

$form: Nested array of form elements that comprise the form.

$form_state: The current state of the form.

1 call to WebformTranslationConfigManager::alterConfigWebformFormElements()
WebformTranslationConfigManager::alterConfigWebformForm in src/WebformTranslationConfigManager.php
Alter the webform configuration form.

File

src/WebformTranslationConfigManager.php, line 371

Class

WebformTranslationConfigManager
Defines a class to translate webform config.

Namespace

Drupal\webform

Code

protected function alterConfigWebformFormElements($config_name, &$config_element, &$form, $form_state) {
  $webform = $this
    ->loadWebform($config_name);
  $translation_langcode = $form_state
    ->get('config_translation_language')
    ->getId();
  $source_elements = $this->translationManager
    ->getSourceElements($webform);
  $translation_elements = $this->translationManager
    ->getTranslationElements($webform, $translation_langcode);
  $elements =& $config_element['elements'];

  // Remove the #theme and source properties so that just the
  // translation details element is rendered.
  unset($elements['#theme'], $elements['source']);

  // Get translation element parents.
  $translation_parents = $elements['translation']['#parents'];

  // Replace the translation element with a details element.
  $elements['translation'] = [
    '#type' => 'details',
    '#title' => $this
      ->t('Webform elements'),
    '#open' => TRUE,
    '#parents' => $translation_parents,
  ];
  foreach ($translation_elements as $element_key => $translation_element) {
    $source_element = $source_elements[$element_key];
    $element = $webform
      ->getElement($element_key);
    $translation_element_parents = array_merge($translation_parents, [
      $element_key,
    ]);
    $elements['translation'][$element_key] = $this
      ->buildConfigWebformFormElements($element, $translation_element, $source_element, $translation_element_parents);
  }
}