class WebformEntitySettingsConfirmationForm in Webform 6.x
Same name and namespace in other branches
- 8.5 src/EntitySettings/WebformEntitySettingsConfirmationForm.php \Drupal\webform\EntitySettings\WebformEntitySettingsConfirmationForm
Webform confirmation settings.
Hierarchy
- class \Drupal\Core\Form\FormBase implements ContainerInjectionInterface, FormInterface uses DependencySerializationTrait, LoggerChannelTrait, MessengerTrait, RedirectDestinationTrait, StringTranslationTrait
- class \Drupal\Core\Entity\EntityForm implements EntityFormInterface
- class \Drupal\webform\EntitySettings\WebformEntitySettingsBaseForm
- class \Drupal\webform\EntitySettings\WebformEntitySettingsConfirmationForm
- class \Drupal\webform\EntitySettings\WebformEntitySettingsBaseForm
- class \Drupal\Core\Entity\EntityForm implements EntityFormInterface
Expanded class hierarchy of WebformEntitySettingsConfirmationForm
File
- src/
EntitySettings/ WebformEntitySettingsConfirmationForm.php, line 13
Namespace
Drupal\webform\EntitySettingsView source
class WebformEntitySettingsConfirmationForm extends WebformEntitySettingsBaseForm {
/**
* The webform token manager.
*
* @var \Drupal\webform\WebformTokenManagerInterface
*/
protected $tokenManager;
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
$instance = parent::create($container);
$instance->tokenManager = $container
->get('webform.token_manager');
return $instance;
}
/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state) {
/** @var \Drupal\webform\WebformInterface $webform */
$webform = $this->entity;
$elements = $webform
->getElementsDecoded();
if (!empty($elements['#method'])) {
$this
->messenger()
->addWarning($this
->t('Form is being posted using a custom method. Confirmation page must be handled by the <a href=":href">custom form action</a>.', [
':href' => $webform
->toUrl('settings-form')
->toString(),
]));
return $form;
}
return parent::buildForm($form, $form_state);
}
/**
* {@inheritdoc}
*/
public function form(array $form, FormStateInterface $form_state) {
/** @var \Drupal\webform\WebformInterface $webform */
$webform = $this->entity;
$settings = $webform
->getSettings();
// Confirmation type.
$form['confirmation_type'] = [
'#type' => 'fieldset',
'#title' => $this
->t('Confirmation type'),
];
$form['confirmation_type']['ajax_confirmation'] = [
'#type' => 'webform_message',
'#message_type' => 'warning',
'#message_message' => $this
->t("Only 'Inline', 'Message', 'Modal', and 'None' confirmation types are fully supported by Ajax."),
'#access' => $settings['ajax'],
'#states' => [
'invisible' => [
[
':input[name="confirmation_type"]' => [
'value' => WebformInterface::CONFIRMATION_INLINE,
],
],
'or',
[
':input[name="confirmation_type"]' => [
'value' => WebformInterface::CONFIRMATION_MESSAGE,
],
],
'or',
[
':input[name="confirmation_type"]' => [
'value' => WebformInterface::CONFIRMATION_MODAL,
],
],
'or',
[
':input[name="confirmation_type"]' => [
'value' => WebformInterface::CONFIRMATION_NONE,
],
],
],
],
];
$form['confirmation_type']['confirmation_type'] = [
'#title' => $this
->t('Confirmation type'),
'#type' => 'radios',
'#options' => [
WebformInterface::CONFIRMATION_PAGE => $this
->t('Page (redirects to new page and displays the confirmation message)'),
WebformInterface::CONFIRMATION_INLINE => $this
->t('Inline (reloads the current page and replaces the webform with the confirmation message)'),
WebformInterface::CONFIRMATION_MESSAGE => $this
->t('Message (reloads the current page/form and displays the confirmation message at the top of the page)'),
WebformInterface::CONFIRMATION_MODAL => $this
->t('Modal (reloads the current page/form and displays the confirmation message in a modal dialog)'),
WebformInterface::CONFIRMATION_URL => $this
->t('URL (redirects to a custom path or URL)'),
WebformInterface::CONFIRMATION_URL_MESSAGE => $this
->t('URL with message (redirects to a custom path or URL and displays the confirmation message at the top of the page)'),
WebformInterface::CONFIRMATION_NONE => $this
->t('None (reloads the current page and does not display a confirmation message)'),
],
'#default_value' => $settings['confirmation_type'],
];
// Page.
if ($webform
->isResultsDisabled()) {
$form['confirmation_type']['page'] = [
'#type' => 'webform_message',
'#message_type' => 'warning',
'#message_close' => TRUE,
'#message_storage' => WebformMessage::STORAGE_SESSION,
'#message_message' => $this
->t("Because the saving of submissions is disabled, the <code>[webform_submission:values]</code> token will not be available to the confirmation page's message."),
'#states' => [
'visible' => [
':input[name="confirmation_type"]' => [
'value' => WebformInterface::CONFIRMATION_PAGE,
],
],
],
];
}
// None.
$form['confirmation_type']['none'] = [
'#type' => 'webform_message',
'#message_type' => 'warning',
'#message_message' => $this
->t('This setting assumes that a webform handler will manage the displaying of a confirmation message.'),
'#states' => [
'visible' => [
':input[name="confirmation_type"]' => [
'value' => WebformInterface::CONFIRMATION_NONE,
],
],
],
];
$form['confirmation_type']['confirmation_update'] = [
'#title' => $this
->t('Display confirmation when submission is updated'),
'#description' => $this
->t('If checked this select confirmation type and message will be displayed when the submission is updated. Otherwise, a status message will be displayed at the top the page when a submission is updated.'),
'#type' => 'checkbox',
'#return_type' => TRUE,
'#default_value' => $settings['confirmation_update'],
];
// Confirmation url.
$form['confirmation_url'] = [
'#type' => 'details',
'#title' => $this
->t('Confirmation URL'),
'#open' => TRUE,
'#states' => [
'visible' => [
[
':input[name="confirmation_type"]' => [
'value' => WebformInterface::CONFIRMATION_PAGE,
],
],
'or',
[
':input[name="confirmation_type"]' => [
'value' => WebformInterface::CONFIRMATION_URL,
],
],
'or',
[
':input[name="confirmation_type"]' => [
'value' => WebformInterface::CONFIRMATION_URL_MESSAGE,
],
],
],
],
];
$form['confirmation_url']['confirmation_url'] = [
'#type' => 'textfield',
'#title' => $this
->t('Confirmation URL'),
'#description' => $this
->t('The URL or path to redirect the user to upon successful submission.') . '<br/>' . t('Paths beginning with a forward slash (/) will redirect be treated as root-relative. Paths without a forward slash (/) will redirect be treated as Drupal relative path.'),
'#default_value' => $settings['confirmation_url'],
'#maxlength' => NULL,
'#states' => [
'visible' => [
[
':input[name="confirmation_type"]' => [
'value' => WebformInterface::CONFIRMATION_URL,
],
],
'or',
[
':input[name="confirmation_type"]' => [
'value' => WebformInterface::CONFIRMATION_URL_MESSAGE,
],
],
],
'required' => [
[
':input[name="confirmation_type"]' => [
'value' => WebformInterface::CONFIRMATION_URL,
],
],
'or',
[
':input[name="confirmation_type"]' => [
'value' => WebformInterface::CONFIRMATION_URL_MESSAGE,
],
],
],
],
];
$form['confirmation_url']['confirmation_exclude_query'] = [
'#type' => 'checkbox',
'#title' => $this
->t('Exclude query string from Confirmation URL'),
'#description' => $this
->t('If checked, all query string parameters will be removed from the Confirmation URL.'),
'#default_value' => $settings['confirmation_exclude_query'],
];
$form['confirmation_url']['confirmation_exclude_token'] = [
'#type' => 'checkbox',
'#title' => $this
->t('Exclude token from Confirmation URL'),
'#description' => $this
->t('If checked, to submissions token will be removed from the Confirmation URL and the [webform_submission] tokens will not be available within the confirmation message.'),
'#default_value' => $settings['confirmation_exclude_token'],
'#access' => !$webform
->isResultsDisabled(),
];
$form['confirmation_url']['token_tree_link'] = $this->tokenManager
->buildTreeElement([
'webform',
'webform_submission',
'webform_handler',
], $this
->t('You may use tokens to pass query string parameters. Make sure all tokens include the urlencode suffix. (i.e. [webform_submission:values:email:urlencode])'));
// Confirmation settings.
$form['confirmation_settings'] = [
'#type' => 'details',
'#title' => $this
->t('Confirmation settings'),
'#open' => TRUE,
'#states' => [
'invisible' => [
[
':input[name="confirmation_type"]' => [
'value' => WebformInterface::CONFIRMATION_URL,
],
],
'or',
[
':input[name="confirmation_type"]' => [
'value' => WebformInterface::CONFIRMATION_NONE,
],
],
],
],
];
$form['confirmation_settings']['confirmation_title'] = [
'#type' => 'textfield',
'#title' => $this
->t('Confirmation title'),
'#description' => $this
->t('Page title to be shown upon successful submission.'),
'#default_value' => $settings['confirmation_title'],
'#states' => [
'visible' => [
[
':input[name="confirmation_type"]' => [
'value' => WebformInterface::CONFIRMATION_PAGE,
],
],
'or',
[
':input[name="confirmation_type"]' => [
'value' => WebformInterface::CONFIRMATION_MODAL,
],
],
],
],
];
$form['confirmation_settings']['confirmation_message'] = [
'#type' => 'webform_html_editor',
'#title' => $this
->t('Confirmation message'),
'#description' => $this
->t('Message to be shown upon successful submission.'),
'#default_value' => $settings['confirmation_message'],
'#states' => [
'invisible' => [
[
':input[name="confirmation_type"]' => [
'value' => WebformInterface::CONFIRMATION_URL,
],
],
'or',
[
':input[name="confirmation_type"]' => [
'value' => WebformInterface::CONFIRMATION_NONE,
],
],
],
],
];
$form['confirmation_settings']['token_tree_link'] = $this->tokenManager
->buildTreeElement();
// Attributes.
$form['confirmation_attributes_container'] = [
'#type' => 'details',
'#title' => $this
->t('Confirmation attributes'),
'#open' => TRUE,
'#states' => [
'visible' => [
[
':input[name="confirmation_type"]' => [
'value' => WebformInterface::CONFIRMATION_PAGE,
],
],
'or',
[
':input[name="confirmation_type"]' => [
'value' => WebformInterface::CONFIRMATION_INLINE,
],
],
],
],
];
$form['confirmation_attributes_container']['confirmation_attributes'] = [
'#type' => 'webform_element_attributes',
'#title' => $this
->t('Confirmation'),
'#classes' => $this
->config('webform.settings')
->get('settings.confirmation_classes'),
'#default_value' => $settings['confirmation_attributes'],
];
// Back.
$form['back'] = [
'#type' => 'details',
'#title' => $this
->t('Confirmation back link'),
'#states' => [
'visible' => [
[
':input[name="confirmation_type"]' => [
'value' => WebformInterface::CONFIRMATION_PAGE,
],
],
'or',
[
':input[name="confirmation_type"]' => [
'value' => WebformInterface::CONFIRMATION_INLINE,
],
],
],
],
];
$form['back']['confirmation_back'] = [
'#type' => 'checkbox',
'#title' => $this
->t('Display back to webform link'),
'#return_value' => TRUE,
'#default_value' => $settings['confirmation_back'],
];
$form['back']['back_container'] = [
'#type' => 'container',
'#states' => [
'visible' => [
[
':input[name="confirmation_back"]' => [
'checked' => TRUE,
],
],
],
],
];
$form['back']['back_container']['confirmation_back_label'] = [
'#type' => 'textfield',
'#title' => $this
->t('Confirmation back link label'),
'#size' => 20,
'#default_value' => $settings['confirmation_back_label'],
];
$form['back']['back_container']['confirmation_back_attributes_container'] = [
'#type' => 'details',
'#title' => $this
->t('Confirmation back link attributes'),
];
$form['back']['back_container']['confirmation_back_attributes_container']['confirmation_back_attributes'] = [
'#type' => 'webform_element_attributes',
'#title' => $this
->t('Confirmation back link'),
'#classes' => $this
->config('webform.settings')
->get('settings.confirmation_back_classes'),
'#default_value' => $settings['confirmation_back_attributes'],
];
$form['back']['back_container']['token_tree_link'] = $this->tokenManager
->buildTreeElement();
$this->tokenManager
->elementValidate($form);
return parent::form($form, $form_state);
}
/**
* {@inheritdoc}
*/
public function save(array $form, FormStateInterface $form_state) {
$values = $form_state
->getValues();
/** @var \Drupal\webform\WebformInterface $webform */
$webform = $this
->getEntity();
// Set settings.
$webform
->setSettings($values);
parent::save($form, $form_state);
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
DependencySerializationTrait:: |
protected | property | ||
DependencySerializationTrait:: |
protected | property | ||
DependencySerializationTrait:: |
public | function | 2 | |
DependencySerializationTrait:: |
public | function | 2 | |
EntityForm:: |
protected | property | The entity being used by this form. | 11 |
EntityForm:: |
protected | property | The entity type manager. | 3 |
EntityForm:: |
protected | property | The module handler service. | |
EntityForm:: |
protected | property | The name of the current operation. | |
EntityForm:: |
protected | function | Returns the action form element for the current entity form. | |
EntityForm:: |
public | function | Form element #after_build callback: Updates the entity with submitted data. | |
EntityForm:: |
public | function |
Builds an updated entity object based upon the submitted form values. Overrides EntityFormInterface:: |
3 |
EntityForm:: |
protected | function | Copies top-level form values to entity properties. | 9 |
EntityForm:: |
public | function |
Returns a string identifying the base form. Overrides BaseFormIdInterface:: |
6 |
EntityForm:: |
public | function |
Gets the form entity. Overrides EntityFormInterface:: |
|
EntityForm:: |
public | function |
Determines which entity will be used by this form from a RouteMatch object. Overrides EntityFormInterface:: |
3 |
EntityForm:: |
public | function |
Returns a unique string identifying the form. Overrides FormInterface:: |
12 |
EntityForm:: |
public | function |
Gets the operation identifying the form. Overrides EntityFormInterface:: |
|
EntityForm:: |
protected | function | Initialize the form state and the entity before the first form build. | 3 |
EntityForm:: |
protected | function | Prepares the entity object before the form is built first. | 3 |
EntityForm:: |
protected | function | Invokes the specified prepare hook variant. | |
EntityForm:: |
public | function | Process callback: assigns weights and hides extra fields. | |
EntityForm:: |
public | function |
Sets the form entity. Overrides EntityFormInterface:: |
|
EntityForm:: |
public | function |
Sets the entity type manager for this form. Overrides EntityFormInterface:: |
|
EntityForm:: |
public | function |
Sets the module handler for this form. Overrides EntityFormInterface:: |
|
EntityForm:: |
public | function |
Sets the operation for this form. Overrides EntityFormInterface:: |
|
EntityForm:: |
public | function |
This is the default entity object builder function. It is called before any
other submit handler to build the new entity object to be used by the
following submit handlers. At this point of the form workflow the entity is
validated and the form state… Overrides FormInterface:: |
20 |
FormBase:: |
protected | property | The config factory. | 3 |
FormBase:: |
protected | property | The request stack. | 1 |
FormBase:: |
protected | property | The route match. | |
FormBase:: |
protected | function | Retrieves a configuration object. | |
FormBase:: |
protected | function | Gets the config factory for this form. | 3 |
FormBase:: |
private | function | Returns the service container. | |
FormBase:: |
protected | function | Gets the current user. | |
FormBase:: |
protected | function | Gets the request object. | |
FormBase:: |
protected | function | Gets the route match. | |
FormBase:: |
protected | function | Gets the logger for a specific channel. | |
FormBase:: |
protected | function | Returns a redirect response object for the specified route. | |
FormBase:: |
public | function | Resets the configuration factory. | |
FormBase:: |
public | function | Sets the config factory for this form. | |
FormBase:: |
public | function | Sets the request stack object to use. | |
FormBase:: |
public | function |
Form validation handler. Overrides FormInterface:: |
72 |
LoggerChannelTrait:: |
protected | property | The logger channel factory service. | |
LoggerChannelTrait:: |
protected | function | Gets the logger for a specific channel. | |
LoggerChannelTrait:: |
public | function | Injects the logger channel factory. | |
MessengerTrait:: |
protected | property | The messenger. | 27 |
MessengerTrait:: |
public | function | Gets the messenger. | 27 |
MessengerTrait:: |
public | function | Sets the messenger. | |
RedirectDestinationTrait:: |
protected | property | The redirect destination service. | 1 |
RedirectDestinationTrait:: |
protected | function | Prepares a 'destination' URL query parameter for use with \Drupal\Core\Url. | |
RedirectDestinationTrait:: |
protected | function | Returns the redirect destination service. | |
RedirectDestinationTrait:: |
public | function | Sets the redirect destination service. | |
StringTranslationTrait:: |
protected | property | The string translation service. | 4 |
StringTranslationTrait:: |
protected | function | Formats a string containing a count of items. | |
StringTranslationTrait:: |
protected | function | Returns the number of plurals supported by a given language. | |
StringTranslationTrait:: |
protected | function | Gets the string translation service. | |
StringTranslationTrait:: |
public | function | Sets the string translation service to use. | 2 |
StringTranslationTrait:: |
protected | function | Translates a string to the current language or to a given language. | |
WebformEntitySettingsBaseForm:: |
protected | function |
Returns an array of supported actions for the current entity form. Overrides EntityForm:: |
|
WebformEntitySettingsBaseForm:: |
protected | function | Append behavior checkboxes to element. | |
WebformEntitySettingsBaseForm:: |
protected | function | Append [none] message and default value to an element's description. | |
WebformEntitySettingsConfirmationForm:: |
protected | property | The webform token manager. | |
WebformEntitySettingsConfirmationForm:: |
public | function |
Form constructor. Overrides EntityForm:: |
|
WebformEntitySettingsConfirmationForm:: |
public static | function |
Instantiates a new instance of this class. Overrides FormBase:: |
|
WebformEntitySettingsConfirmationForm:: |
public | function |
Gets the actual form array to be built. Overrides WebformEntitySettingsBaseForm:: |
|
WebformEntitySettingsConfirmationForm:: |
public | function |
Form submission handler for the 'save' action. Overrides WebformEntitySettingsBaseForm:: |