You are here

protected function WebformTranslationConfigManager::buildConfigWebformFormDefaultPropertyElement in Webform 6.x

Build config webform form default property element.

Parameters

array $element: The Webform element.

array $translation_element: The Webform element's translated properties.

array $source_element: The Webform element's source properties.

array $parents: The Webform element's parents.

Return value

array A render array containing config webform form default property element.

1 call to WebformTranslationConfigManager::buildConfigWebformFormDefaultPropertyElement()
WebformTranslationConfigManager::buildConfigWebformFormElements in src/WebformTranslationConfigManager.php
Build config webform form elements.

File

src/WebformTranslationConfigManager.php, line 716

Class

WebformTranslationConfigManager
Defines a class to translate webform config.

Namespace

Drupal\webform

Code

protected function buildConfigWebformFormDefaultPropertyElement(array $element, array $translation_element, array $source_element, $property_parents) {
  $property_key = end($property_parents);
  $property_name = '#' . $property_key;
  $webform_element = $this->elementManager
    ->getElementInstance($element);
  $element_property = $this
    ->getWebformElementProperty($webform_element
    ->getPluginId(), $property_name);
  $property_value = $translation_element[$property_name];
  $property_title = isset($element_property['#title']) ? $element_property['#title'] : $property_name;
  $property_type = isset($element_property['#type']) ? $element_property['#type'] : NULL;
  $property_translation_element = [
    '#title' => $property_title,
    '#default_value' => $property_value,
    '#parents' => $property_parents,
  ];
  if (is_array($property_value)) {
    $property_translation_element += [
      '#type' => 'webform_codemirror',
      '#mode' => 'yaml',
    ];
  }
  elseif ($property_type === 'text_format') {
    $property_translation_element += [
      '#type' => 'text_format',
      '#title_display' => 'hidden',
      '#format' => $element_property['#format'],
      '#allowed_formats' => [
        $element_property['#format'],
      ],
    ];
  }
  elseif ($property_type) {
    $property_translation_element += [
      '#type' => $property_type,
    ];
  }
  else {
    $property_translation_element += [
      '#type' => 'textarea',
      '#rows' => 1,
    ];
  }

  // Property source element.
  $property_source_element = [
    '#title' => $property_title,
  ];
  if (is_array($source_element[$property_name])) {
    $property_source_element += [
      '#type' => 'webform_codemirror',
      '#mode' => 'yaml',
      '#default_value' => $source_element[$property_name],
      '#disabled' => TRUE,
      '#attributes' => [
        'readonly' => TRUE,
      ],
    ];
  }
  elseif ($property_translation_element['#type'] === 'webform_html_editor') {
    $property_source_element += [
      '#type' => 'item',
      'html' => WebformHtmlEditor::checkMarkup($source_element[$property_name]),
    ];
  }
  elseif ($property_translation_element['#type'] === 'text_format') {
    $property_source_element += [
      '#type' => 'processed_text',
      '#text' => $source_element[$property_name],
      '#format' => $element_property['#format'],
    ];
  }
  else {
    $property_source_element += [
      '#type' => 'item',
      '#plain_text' => $source_element[$property_name],
    ];
  }
  return [
    '#theme' => 'config_translation_manage_form_element',
    'source' => $property_source_element,
    'translation' => $property_translation_element,
  ];
}