public static function WebformTranslationConfigManager::validateWebformForm in Webform 6.x
Validate the webform config translation form.
Parameters
$form: Nested array of form elements that comprise the form.
$form_state: The current state of the form.
Overrides WebformTranslationConfigManagerInterface::validateWebformForm
File
- src/
WebformTranslationConfigManager.php, line 267
Class
- WebformTranslationConfigManager
- Defines a class to translate webform config.
Namespace
Drupal\webformCode
public static function validateWebformForm(&$form, FormStateInterface $form_state) {
$source_elements = $form_state
->get('webform_source_elements');
if ($form_state::hasAnyErrors() || empty($source_elements)) {
return;
}
$values = $form_state
->getValues();
$config_name = $form_state
->get('webform_config_name');
$translation_elements = $values['translation']['config_names'][$config_name]['elements'];
foreach ($translation_elements as $key => $element) {
$translation_elements[$key] = WebformArrayHelper::addPrefix($element);
// Handle composite elements.
if (isset($translation_elements[$key]['#element'])) {
foreach ($translation_elements[$key]['#element'] as $composite_key => $composite_element) {
$translation_elements[$key]['#element'][$composite_key] = WebformArrayHelper::addPrefix($composite_element);
}
}
elseif (isset($translation_elements[$key]['#text']) && isset($translation_elements[$key]['#text']['value']) && isset($translation_elements[$key]['#text']['format'])) {
$translation_elements[$key]['#text'] = $translation_elements[$key]['#text']['value'];
}
}
/** @var \Drupal\webform\WebformTranslationConfigManagerInterface $translation_config_manager */
$translation_config_manager = \Drupal::service('webform.translation_config_manager');
// Remove any translation property that has not been translated.
$translation_config_manager
->mergeTranslationAndSourceElementsProperties($translation_elements, $source_elements);
// Update webform value.
$values['translation']['config_names'][$config_name]['elements'] = $translation_elements ? Yaml::encode($translation_elements) : '';
$form_state
->setValues($values);
}