You are here

function _yamlform_form_config_translate_add_form_validate in YAML Form 8

Validate callback; Validates and cleanups form elements.

1 string reference to '_yamlform_form_config_translate_add_form_validate'
yamlform_form_config_translation_add_form_alter in includes/yamlform.translation.inc
Implements hook_form_FORM_ID_alter().

File

includes/yamlform.translation.inc, line 60
YAML Form module translation hooks.

Code

function _yamlform_form_config_translate_add_form_validate(&$form, FormStateInterface $form_state) {
  $values = $form_state
    ->getValues();
  $config_name = $form_state
    ->get('yamlform_config_name');
  $source_elements = $form_state
    ->get('yamlform_source_elements');
  $submitted_translation_elements = Yaml::decode($values['translation']['config_names'][$config_name]['elements']);
  $translation_elements = $source_elements;

  // Remove all custom translation properties.
  YamlFormElementHelper::merge($translation_elements, $submitted_translation_elements);

  // Remove any translation property that has not been translated.
  _yamlform_form_config_translate_add_form_filter_elements($translation_elements, $source_elements);

  // Update form value.
  $values['translation']['config_names'][$config_name]['elements'] = $translation_elements ? Yaml::encode($translation_elements) : '';
  $form_state
    ->setValues($values);
}