You are here

class WebformAdminConfigSubmissionsForm in Webform 8.5

Same name and namespace in other branches
  1. 6.x src/Form/AdminConfig/WebformAdminConfigSubmissionsForm.php \Drupal\webform\Form\AdminConfig\WebformAdminConfigSubmissionsForm

Configure webform admin settings for submissions.

Hierarchy

Expanded class hierarchy of WebformAdminConfigSubmissionsForm

1 string reference to 'WebformAdminConfigSubmissionsForm'
webform.routing.yml in ./webform.routing.yml
webform.routing.yml

File

src/Form/AdminConfig/WebformAdminConfigSubmissionsForm.php, line 15

Namespace

Drupal\webform\Form\AdminConfig
View source
class WebformAdminConfigSubmissionsForm extends WebformAdminConfigBaseForm {

  /**
   * The module handler.
   *
   * @var \Drupal\Core\Extension\ModuleHandlerInterface
   */
  protected $moduleHandler;

  /**
   * The webform token manager.
   *
   * @var \Drupal\webform\WebformTokenManagerInterface
   */
  protected $tokenManager;

  /**
   * {@inheritdoc}
   */
  public function getFormId() {
    return 'webform_admin_config_submissions_form';
  }

  /**
   * Constructs a WebformAdminConfigSubmissionsForm object.
   *
   * @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory
   *   The factory for configuration objects.
   * @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler
   *   The module handler.
   * @param \Drupal\webform\WebformTokenManagerInterface $token_manager
   *   The webform token manager.
   */
  public function __construct(ConfigFactoryInterface $config_factory, ModuleHandlerInterface $module_handler, WebformTokenManagerInterface $token_manager) {
    parent::__construct($config_factory);
    $this->moduleHandler = $module_handler;
    $this->tokenManager = $token_manager;
  }

  /**
   * {@inheritdoc}
   */
  public static function create(ContainerInterface $container) {
    return new static($container
      ->get('config.factory'), $container
      ->get('module_handler'), $container
      ->get('webform.token_manager'));
  }

  /**
   * {@inheritdoc}
   */
  public function buildForm(array $form, FormStateInterface $form_state) {
    $config = $this
      ->config('webform.settings');
    $settings = $config
      ->get('settings');

    // Submission settings.
    $form['submission_settings'] = [
      '#type' => 'details',
      '#title' => $this
        ->t('Submission general settings'),
      '#open' => TRUE,
      '#tree' => TRUE,
    ];
    $form['submission_settings']['default_submission_access_denied_message'] = [
      '#type' => 'webform_html_editor',
      '#title' => $this
        ->t('Default access denied message'),
      '#required' => TRUE,
      '#default_value' => $settings['default_submission_access_denied_message'],
    ];
    $form['submission_settings']['default_submission_exception_message'] = [
      '#type' => 'webform_html_editor',
      '#title' => $this
        ->t('Default exception message'),
      '#required' => TRUE,
      '#default_value' => $settings['default_submission_exception_message'],
    ];
    $form['submission_settings']['default_submission_locked_message'] = [
      '#type' => 'webform_html_editor',
      '#title' => $this
        ->t('Default locked message'),
      '#required' => TRUE,
      '#default_value' => $settings['default_submission_locked_message'],
    ];
    $form['submission_settings']['default_previous_submission_message'] = [
      '#type' => 'webform_html_editor',
      '#title' => $this
        ->t('Default previous submission message'),
      '#required' => TRUE,
      '#default_value' => $settings['default_previous_submission_message'],
    ];
    $form['submission_settings']['default_previous_submissions_message'] = [
      '#type' => 'webform_html_editor',
      '#title' => $this
        ->t('Default previous submissions message'),
      '#required' => TRUE,
      '#default_value' => $settings['default_previous_submissions_message'],
    ];
    $form['submission_settings']['default_autofill_message'] = [
      '#type' => 'webform_html_editor',
      '#title' => $this
        ->t('Default autofill message'),
      '#description' => $this
        ->t('Leave blank to not display a message when a form is autofilled.'),
      '#default_value' => $settings['default_autofill_message'],
    ];
    $form['submission_settings']['default_submission_label'] = [
      '#type' => 'textfield',
      '#title' => $this
        ->t('Default submission label'),
      '#required' => TRUE,
      '#default_value' => $settings['default_submission_label'],
    ];
    $form['submission_settings']['token_tree_link'] = $this->tokenManager
      ->buildTreeElement();

    // Submission Behaviors.
    $form['submission_behaviors'] = [
      '#type' => 'details',
      '#title' => $this
        ->t('Submission behaviors'),
      '#open' => TRUE,
      '#tree' => TRUE,
    ];
    $behavior_elements = [
      'default_submission_log' => [
        'title' => $this
          ->t('Log all submission events for all webforms'),
        'description' => $this
          ->t('If checked, all submission events will be logged to dedicated submission log available to all webforms and submissions.') . '<br/><br/>' . '<em>' . t('The webform submission log will track more detailed user information including email addresses and subjects.') . '</em>',
      ],
      'default_results_customize' => [
        'title' => $this
          ->t('Allow users to customize the submission results table'),
        'description' => $this
          ->t('If checked, users can individually customize the submission results table for all webforms.'),
      ],
    ];
    foreach ($behavior_elements as $behavior_key => $behavior_element) {
      $form['submission_behaviors'][$behavior_key] = [
        '#type' => 'checkbox',
        '#title' => $behavior_element['title'],
        '#description' => $behavior_element['description'],
        '#return_value' => TRUE,
        '#default_value' => $settings[$behavior_key],
      ];
    }
    if (!$this->moduleHandler
      ->moduleExists('webform_submission_log')) {
      $form['submission_behaviors']['webform_submission_log_message'] = [
        '#type' => 'webform_message',
        '#message_type' => 'info',
        '#message_message' => $this
          ->t("Enable the 'Webform Submission Log' module to better track and permanently store submission logs."),
        '#message_close' => TRUE,
        '#message_storage' => WebformMessage::STORAGE_SESSION,
        '#states' => [
          'visible' => [
            ':input[name="submission_behaviors[default_submission_log]"]' => [
              'checked' => TRUE,
            ],
          ],
        ],
      ];
    }

    // Submission limits.
    $form['submission_limits'] = [
      '#type' => 'details',
      '#title' => $this
        ->t('Submission limit settings'),
      '#open' => TRUE,
      '#tree' => TRUE,
    ];
    $form['submission_limits']['default_limit_total_message'] = [
      '#type' => 'webform_html_editor',
      '#title' => $this
        ->t('Default total submissions limit message'),
      '#default_value' => $config
        ->get('settings.default_limit_total_message'),
    ];
    $form['submission_limits']['default_limit_user_message'] = [
      '#type' => 'webform_html_editor',
      '#title' => $this
        ->t('Default per user submission limit message'),
      '#default_value' => $config
        ->get('settings.default_limit_user_message'),
    ];
    $form['submission_limits']['token_tree_link'] = $this->tokenManager
      ->buildTreeElement();

    // Draft settings.
    $form['draft_settings'] = [
      '#type' => 'details',
      '#title' => $this
        ->t('Submission draft settings'),
      '#open' => TRUE,
      '#tree' => TRUE,
    ];
    $form['draft_settings']['default_draft_button_label'] = [
      '#type' => 'textfield',
      '#title' => $this
        ->t('Default draft button label'),
      '#required' => TRUE,
      '#size' => 20,
      '#default_value' => $settings['default_draft_button_label'],
    ];
    $form['draft_settings']['default_draft_pending_single_message'] = [
      '#type' => 'webform_html_editor',
      '#title' => $this
        ->t('Default draft pending single draft message'),
      '#default_value' => $settings['default_draft_pending_single_message'],
    ];
    $form['draft_settings']['default_draft_pending_multiple_message'] = [
      '#type' => 'webform_html_editor',
      '#title' => $this
        ->t('Default draft pending multiple drafts message'),
      '#default_value' => $settings['default_draft_pending_multiple_message'],
    ];
    $form['draft_settings']['default_draft_saved_message'] = [
      '#type' => 'webform_html_editor',
      '#title' => $this
        ->t('Default draft save message'),
      '#default_value' => $settings['default_draft_saved_message'],
    ];
    $form['draft_settings']['default_draft_loaded_message'] = [
      '#type' => 'webform_html_editor',
      '#title' => $this
        ->t('Default draft load message'),
      '#default_value' => $settings['default_draft_loaded_message'],
    ];
    $form['draft_settings']['token_tree_link'] = $this->tokenManager
      ->buildTreeElement();

    // Submission purging.
    $form['purge'] = [
      '#type' => 'details',
      '#title' => $this
        ->t('Submission purge settings'),
      '#open' => TRUE,
      '#tree' => TRUE,
    ];
    $form['purge']['cron_size'] = [
      '#type' => 'number',
      '#title' => $this
        ->t('Amount of submissions to process'),
      '#min' => 1,
      '#default_value' => $config
        ->get('purge.cron_size'),
      '#description' => $this
        ->t('Enter the amount of submissions to be purged during single cron run. You may want to lower this number if you are facing memory or timeout issues when purging via cron.'),
    ];

    // Bulk operation settings.
    $form['bulk_form_settings'] = $this
      ->buildBulkOperations($settings, 'webform_submission');

    // Submission views.
    $form['views_settings'] = [
      '#type' => 'details',
      '#title' => $this
        ->t('Submission views settings'),
      '#open' => TRUE,
      '#tree' => TRUE,
    ];
    $form['views_settings']['default_submission_views'] = [
      '#type' => 'webform_submission_views',
      '#title' => $this
        ->t('Submission views'),
      '#title_display' => 'invisible',
      '#global' => TRUE,
      '#default_value' => $settings['default_submission_views'],
    ];
    $form['views_settings']['message'] = [
      '#type' => 'webform_message',
      '#message_type' => 'info',
      '#message_message' => $this
        ->t('Uncheck the below settings to allow webform administrators to choose which results should be replaced with submission views.'),
      '#message_close' => TRUE,
      '#message_storage' => WebformMessage::STORAGE_SESSION,
    ];
    $form['views_settings']['default_submission_views_replace'] = [
      '#type' => 'webform_submission_views_replace',
      '#global' => TRUE,
      '#default_value' => $settings['default_submission_views_replace'],
    ];
    $this->tokenManager
      ->elementValidate($form);
    return parent::buildForm($form, $form_state);
  }

  /**
   * {@inheritdoc}
   */
  public function submitForm(array &$form, FormStateInterface $form_state) {
    $settings = $form_state
      ->getValue('submission_settings') + $form_state
      ->getValue('submission_behaviors') + $form_state
      ->getValue('submission_limits') + $form_state
      ->getValue('draft_settings') + $form_state
      ->getValue('bulk_form_settings') + $form_state
      ->getValue('views_settings');

    // Update config and submit form.
    $config = $this
      ->config('webform.settings');
    $config
      ->set('settings', $settings + $config
      ->get('settings'));
    $config
      ->set('purge', $form_state
      ->getValue('purge'));
    parent::submitForm($form, $form_state);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
ConfigFormBaseTrait::config protected function Retrieves a configuration object.
DependencySerializationTrait::$_entityStorages protected property An array of entity type IDs keyed by the property name of their storages.
DependencySerializationTrait::$_serviceIds protected property An array of service IDs keyed by property name used for serialization.
DependencySerializationTrait::__sleep public function 1
DependencySerializationTrait::__wakeup public function 2
FormBase::$configFactory protected property The config factory. 1
FormBase::$requestStack protected property The request stack. 1
FormBase::$routeMatch protected property The route match.
FormBase::configFactory protected function Gets the config factory for this form. 1
FormBase::container private function Returns the service container.
FormBase::currentUser protected function Gets the current user.
FormBase::getRequest protected function Gets the request object.
FormBase::getRouteMatch protected function Gets the route match.
FormBase::logger protected function Gets the logger for a specific channel.
FormBase::redirect protected function Returns a redirect response object for the specified route. Overrides UrlGeneratorTrait::redirect
FormBase::resetConfigFactory public function Resets the configuration factory.
FormBase::setConfigFactory public function Sets the config factory for this form.
FormBase::setRequestStack public function Sets the request stack object to use.
FormBase::validateForm public function Form validation handler. Overrides FormInterface::validateForm 62
LinkGeneratorTrait::$linkGenerator protected property The link generator. 1
LinkGeneratorTrait::getLinkGenerator Deprecated protected function Returns the link generator.
LinkGeneratorTrait::l Deprecated protected function Renders a link to a route given a route name and its parameters.
LinkGeneratorTrait::setLinkGenerator Deprecated public function Sets the link generator service.
LoggerChannelTrait::$loggerFactory protected property The logger channel factory service.
LoggerChannelTrait::getLogger protected function Gets the logger for a specific channel.
LoggerChannelTrait::setLoggerFactory public function Injects the logger channel factory.
MessengerTrait::$messenger protected property The messenger. 29
MessengerTrait::messenger public function Gets the messenger. 29
MessengerTrait::setMessenger public function Sets the messenger.
RedirectDestinationTrait::$redirectDestination protected property The redirect destination service. 1
RedirectDestinationTrait::getDestinationArray protected function Prepares a 'destination' URL query parameter for use with \Drupal\Core\Url.
RedirectDestinationTrait::getRedirectDestination protected function Returns the redirect destination service.
RedirectDestinationTrait::setRedirectDestination public function Sets the redirect destination service.
StringTranslationTrait::$stringTranslation protected property The string translation service. 1
StringTranslationTrait::formatPlural protected function Formats a string containing a count of items.
StringTranslationTrait::getNumberOfPlurals protected function Returns the number of plurals supported by a given language.
StringTranslationTrait::getStringTranslation protected function Gets the string translation service.
StringTranslationTrait::setStringTranslation public function Sets the string translation service to use. 2
StringTranslationTrait::t protected function Translates a string to the current language or to a given language.
UrlGeneratorTrait::$urlGenerator protected property The url generator.
UrlGeneratorTrait::getUrlGenerator Deprecated protected function Returns the URL generator service.
UrlGeneratorTrait::setUrlGenerator Deprecated public function Sets the URL generator service.
UrlGeneratorTrait::url Deprecated protected function Generates a URL or path for a specific route based on the given parameters.
WebformAdminConfigBaseForm::buildBulkOperations protected function Build bulk operation settings for webforms and submissions.
WebformAdminConfigBaseForm::buildExcludedPlugins protected function Build excluded plugins element.
WebformAdminConfigBaseForm::convertIncludedToExcludedPluginIds protected function Convert included ids returned from table select element to excluded ids.
WebformAdminConfigBaseForm::getEditableConfigNames protected function Gets the configuration names that will be editable. Overrides ConfigFormBaseTrait::getEditableConfigNames
WebformAdminConfigBaseForm::getPluginDefinitions protected function Get plugin definitions.
WebformAdminConfigBaseForm::validateBulkFormActions public static function Form API callback. Validate bulk form actions.
WebformAdminConfigSubmissionsForm::$moduleHandler protected property The module handler.
WebformAdminConfigSubmissionsForm::$tokenManager protected property The webform token manager.
WebformAdminConfigSubmissionsForm::buildForm public function Form constructor. Overrides ConfigFormBase::buildForm
WebformAdminConfigSubmissionsForm::create public static function Instantiates a new instance of this class. Overrides ConfigFormBase::create
WebformAdminConfigSubmissionsForm::getFormId public function Returns a unique string identifying the form. Overrides FormInterface::getFormId
WebformAdminConfigSubmissionsForm::submitForm public function Form submission handler. Overrides WebformAdminConfigBaseForm::submitForm
WebformAdminConfigSubmissionsForm::__construct public function Constructs a WebformAdminConfigSubmissionsForm object. Overrides ConfigFormBase::__construct