You are here

function _webform_form_config_translate_add_form_alter_yaml_element in Webform 8.5

Alter translated config entity property.

Parameters

array $element: A webform element containing 'source' and 'translation'.

string $source_value: (optional) The custom config source value.

string $translation_value: (optional) The custom config translation value.

2 calls to _webform_form_config_translate_add_form_alter_yaml_element()
webform_form_config_translation_add_form_alter in includes/webform.translation.inc
Implements hook_form_FORM_ID_alter() for config translation add form.
webform_image_select_form_config_translation_add_form_alter in modules/webform_image_select/webform_image_select.module
Implements hook_form_FORM_ID_alter() for config translate add form.

File

includes/webform.translation.inc, line 221
Webform module translation hooks.

Code

function _webform_form_config_translate_add_form_alter_yaml_element(array &$element, $source_value = NULL, $translation_value = NULL) {

  // Source.
  $source_value = $source_value ?: trim(strip_tags($element['source']['#markup']));
  if ($source_value === (string) t('(Empty)')) {
    $source_value = '';
  }
  $element['source']['#wrapper_attributes']['class'][] = 'webform-translation-source';
  $element['source']['value'] = [
    '#type' => 'webform_codemirror',
    '#mode' => 'yaml',
    '#value' => $source_value ? WebformYaml::tidy($source_value) : '',
    '#disabled' => TRUE,
    '#attributes' => [
      'readonly' => TRUE,
    ],
  ];
  unset($element['source']['#markup']);

  // Translation.
  $element['translation']['#type'] = 'webform_codemirror';
  $element['translation']['#mode'] = 'yaml';
  if ($translation_value) {
    $element['translation']['#default_value'] = WebformYaml::tidy($translation_value);
  }
  $element['translation']['#default_value'] = trim($element['translation']['#default_value']);
  $element['#attached']['library'][] = 'webform/webform.admin.translation';
}