public function WebformUiElementFormBase::submitForm in Webform 6.x
Same name and namespace in other branches
- 8.5 modules/webform_ui/src/Form/WebformUiElementFormBase.php \Drupal\webform_ui\Form\WebformUiElementFormBase::submitForm()
Form submission handler.
Parameters
array $form: An associative array containing the structure of the form.
\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.
Overrides FormInterface::submitForm
1 method overrides WebformUiElementFormBase::submitForm()
- WebformUiElementTestForm::submitForm in modules/
webform_ui/ src/ Form/ WebformUiElementTestForm.php - Form submission handler.
File
- modules/
webform_ui/ src/ Form/ WebformUiElementFormBase.php, line 398
Class
- WebformUiElementFormBase
- Provides a base class for webform element webforms.
Namespace
Drupal\webform_ui\FormCode
public function submitForm(array &$form, FormStateInterface $form_state) {
$op = $form_state
->getValue('op');
$parent_key = $form_state
->getValue('parent_key');
$key = $form_state
->getValue('key');
$element_plugin = $this
->getWebformElementPlugin();
// Submit element configuration.
// Generally, elements will not be processing any submitted properties.
// It is possible that a custom element might need to call a third-party API
// to 'register' the element.
$subform_state = SubformState::createForSubform($form['properties'], $form, $form_state);
$element_plugin
->submitConfigurationForm($form, $subform_state);
// Add/update the element to the webform.
$properties = $element_plugin
->getConfigurationFormProperties($form, $subform_state);
$this->webform
->setElementProperties($key, $properties, $parent_key);
// Save the webform.
$this->webform
->save();
// Display status message.
$properties = $form_state
->getValue('properties');
$t_args = [
'%title' => !empty($properties['title']) ? $properties['title'] : $key,
'@action' => $this->action,
];
$this
->messenger()
->addStatus($this
->t('%title has been @action.', $t_args));
// Determine add element parent key.
$save_and_add_element = (string) $op === (string) $this
->t('Save + Add element') ? TRUE : FALSE;
$add_element = $element_plugin
->isContainer($this
->getElement()) ? $key : $parent_key;
$add_element = $add_element ? Html::getClass($add_element) : '_root_';
// Append ?update= to (redirect) destination.
if ($this->requestStack
->getCurrentRequest()->query
->get('destination')) {
$redirect_destination = $this
->getRedirectDestination();
$destination = $redirect_destination
->get();
$destination .= (strpos($destination, '?') !== FALSE ? '&' : '?') . 'update=' . $key;
$destination .= $save_and_add_element ? '&add_element=' . $add_element : '';
$redirect_destination
->set($destination);
}
// Still set the redirect URL just to be safe.
// Variants require the entire page to be reloaded so that Variants tab
// is made visible.
if ($this
->getWebformElementPlugin() instanceof WebformElementVariantInterface) {
$query = [
'reload' => 'true',
];
}
else {
$query = [
'update' => $key,
];
if ($save_and_add_element) {
$query['add_element'] = $add_element;
}
}
$form_state
->setRedirectUrl($this->webform
->toUrl('edit-form', [
'query' => $query,
]));
}