You are here

class WebformAdminConfigAdvancedForm in Webform 8.5

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

Configure webform admin advanced settings.

Hierarchy

Expanded class hierarchy of WebformAdminConfigAdvancedForm

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

File

src/Form/AdminConfig/WebformAdminConfigAdvancedForm.php, line 17

Namespace

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

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

  /**
   * The render cache bin.
   *
   * @var \Drupal\Core\Cache\CacheBackendInterface
   */
  protected $renderCache;

  /**
   * The router builder.
   *
   * @var \Drupal\Core\Routing\RouteBuilderInterface
   */
  protected $routerBuilder;

  /**
   * The (drush) command-line service.
   *
   * @var \Drupal\webform\Commands\WebformCliService
   */
  protected $cliService;

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

  /**
   * Constructs a WebformAdminConfigAdvancedForm 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\Core\Cache\CacheBackendInterface $render_cache
   *   The render cache service.
   * @param \Drupal\Core\Routing\RouteBuilderInterface $router_builder
   *   The router builder service.
   * @param \Drupal\webform\Commands\WebformCliService $cli_service
   *   The (drush) command-line service.
   */
  public function __construct(ConfigFactoryInterface $config_factory, ModuleHandlerInterface $module_handler, CacheBackendInterface $render_cache, RouteBuilderInterface $router_builder, WebformCliService $cli_service) {
    parent::__construct($config_factory);
    $this->renderCache = $render_cache;
    $this->moduleHandler = $module_handler;
    $this->routerBuilder = $router_builder;
    $this->cliService = $cli_service;
  }

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

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

    // UI.
    $form['ui'] = [
      '#type' => 'details',
      '#title' => $this
        ->t('User interface settings'),
      '#open' => TRUE,
      '#tree' => TRUE,
    ];
    $form['ui']['video_display'] = [
      '#type' => 'select',
      '#title' => $this
        ->t('Video display'),
      '#description' => $this
        ->t('Controls how videos are displayed in inline help and within the global help section.'),
      '#options' => [
        'dialog' => $this
          ->t('Dialog'),
        'link' => $this
          ->t('External link'),
        'hidden' => $this
          ->t('Hidden'),
      ],
      '#default_value' => $config
        ->get('ui.video_display'),
    ];
    $form['ui']['toolbar_item'] = [
      '#type' => 'checkbox',
      '#title' => $this
        ->t('Display Webforms as a top-level administration menu item in the toolbar'),
      '#description' => $this
        ->t('If checked, the Webforms section will be displayed as a top-level administration menu item in the toolbar.'),
      '#return_value' => TRUE,
      '#default_value' => $config
        ->get('ui.toolbar_item'),
      '#access' => $this->moduleHandler
        ->moduleExists('toolbar'),
    ];
    $form['ui']['description_help'] = [
      '#type' => 'checkbox',
      '#title' => $this
        ->t('Display element description as help text (tooltip)'),
      '#description' => $this
        ->t("If checked, all element descriptions will be moved to help text (tooltip)."),
      '#return_value' => TRUE,
      '#default_value' => $config
        ->get('ui.description_help'),
    ];
    $form['ui']['details_save'] = [
      '#type' => 'checkbox',
      '#title' => $this
        ->t('Save details open/close state'),
      '#description' => $this
        ->t('If checked, all <a href=":details_href">Details</a> element\'s open/close state will be saved using <a href=":local_storage_href">Local Storage</a>.', [
        ':details_href' => 'https://developer.mozilla.org/en-US/docs/Web/HTML/Element/details',
        ':local_storage_href' => 'https://developer.mozilla.org/en-US/docs/Web/API/Web_Storage_API',
      ]),
      '#return_value' => TRUE,
      '#default_value' => $config
        ->get('ui.details_save'),
    ];
    $form['ui']['help_disabled'] = [
      '#type' => 'checkbox',
      '#title' => $this
        ->t('Disable help'),
      '#description' => $this
        ->t('If checked, help text will be removed from every webform page and form.'),
      '#return_value' => TRUE,
      '#default_value' => $config
        ->get('ui.help_disabled'),
    ];
    $form['ui']['dialog_disabled'] = [
      '#type' => 'checkbox',
      '#title' => $this
        ->t('Disable dialogs'),
      '#description' => $this
        ->t('If checked, all modal/off-canvas dialogs (i.e. popups) will be disabled.'),
      '#return_value' => TRUE,
      '#default_value' => $config
        ->get('ui.dialog_disabled'),
    ];
    $form['ui']['offcanvas_disabled'] = [
      '#type' => 'checkbox',
      '#title' => $this
        ->t('Disable off-canvas system tray'),
      '#description' => $this
        ->t('If checked, all off-canvas system trays will be disabled.'),
      '#return_value' => TRUE,
      '#default_value' => $config
        ->get('ui.offcanvas_disabled'),
      '#states' => [
        'visible' => [
          ':input[name="ui[dialog_disabled]"]' => [
            'checked' => FALSE,
          ],
        ],
      ],
    ];
    $form['ui']['promotions_disabled'] = [
      '#type' => 'checkbox',
      '#title' => $this
        ->t('Disable promotions'),
      '#description' => $this
        ->t('If checked, dismissible promotion messages that appear when the Webform module is updated will be disabled.') . ' ' . $this
        ->t('Promotions on the <a href=":href">Webform: Add-ons</a> page will still be displayed.', [
        ':href' => Url::fromRoute('webform.addons')
          ->toString(),
      ]) . '<br/>' . $this
        ->t('Note: Promotions are only visible to users who can <em>administer modules</em>.'),
      '#return_value' => TRUE,
      '#default_value' => $config
        ->get('ui.promotions_disabled'),
    ];
    $form['ui']['support_disabled'] = [
      '#type' => 'checkbox',
      '#title' => $this
        ->t('Disable support options'),
      '#description' => $this
        ->t('If checked, support option, displayed on the <a href=":href_addons">Add-ons</a> and <a href=":help_href">Help</a> pages will be disabled.', [
        ':href_addons' => Url::fromRoute('webform.addons')
          ->toString(),
        ':href_help' => Url::fromRoute('webform.help')
          ->toString(),
      ]),
      '#return_value' => TRUE,
      '#default_value' => $config
        ->get('ui.support_disabled'),
    ];

    // Requirements.
    $form['requirements'] = [
      '#type' => 'details',
      '#title' => $this
        ->t('Requirement settings'),
      '#description' => $this
        ->t('The below requirements are checked by the <a href=":href">Status report</a>.', [
        ':href' => Url::fromRoute('system.status')
          ->toString(),
      ]),
      '#open' => TRUE,
      '#tree' => TRUE,
    ];
    $form['requirements']['cdn'] = [
      '#type' => 'checkbox',
      '#title' => $this
        ->t('Check if CDN is being used for external libraries'),
      '#description' => $this
        ->t('If unchecked, all warnings about missing libraries will be disabled.') . '<br/><br/>' . $this
        ->t('Relying on a CDN for external libraries can cause unexpected issues with Ajax and BigPipe support. For more information see: <a href=":href">Issue #1988968</a>', [
        ':href' => 'https://www.drupal.org/project/drupal/issues/1988968',
      ]),
      '#return_value' => TRUE,
      '#default_value' => $config
        ->get('requirements.cdn'),
    ];
    $form['requirements']['clientside_validation'] = [
      '#type' => 'checkbox',
      '#title' => $this
        ->t('Check if Webform Clientside Validation module is installed when using the Clientside Validation module'),
      '#description' => $this
        ->t('If unchecked, all warnings about the Webform Clientside Validation will be disabled.'),
      '#return_value' => TRUE,
      '#default_value' => $config
        ->get('requirements.clientside_validation'),
    ];
    $form['requirements']['bootstrap'] = [
      '#type' => 'checkbox',
      '#title' => $this
        ->t('Check if the Webform Bootstrap Integration module is installed when using the Bootstrap theme'),
      '#description' => $this
        ->t('If unchecked, all warnings about the Webform Bootstrap Integration module will be disabled.'),
      '#return_value' => TRUE,
      '#default_value' => $config
        ->get('requirements.bootstrap'),
    ];
    $form['requirements']['spam'] = [
      '#type' => 'checkbox',
      '#title' => $this
        ->t('Check if SPAM protection module is installed'),
      '#description' => $this
        ->t('If unchecked, all warnings about Webform SPAM protection will be disabled.'),
      '#return_value' => TRUE,
      '#default_value' => $config
        ->get('requirements.spam'),
    ];

    // Test.
    $form['test'] = [
      '#type' => 'details',
      '#title' => $this
        ->t('Test settings'),
      '#open' => TRUE,
      '#tree' => TRUE,
    ];
    $form['test']['types'] = [
      '#type' => 'webform_codemirror',
      '#mode' => 'yaml',
      '#title' => $this
        ->t('Test data by element type'),
      '#description' => $this
        ->t("Above test data is keyed by element #type."),
      '#default_value' => $config
        ->get('test.types'),
    ];
    $form['test']['names'] = [
      '#type' => 'webform_codemirror',
      '#mode' => 'yaml',
      '#title' => $this
        ->t('Test data by element key'),
      '#description' => $this
        ->t("Above test data is keyed by full or partial element keys. For example, using 'zip' will populate element keys that are 'zip' and 'zip_code' but not 'zipcode' or 'zipline'."),
      '#default_value' => $config
        ->get('test.names'),
    ];

    // Batch.
    $form['batch'] = [
      '#type' => 'details',
      '#title' => $this
        ->t('Batch settings'),
      '#open' => TRUE,
      '#tree' => TRUE,
    ];
    $form['batch']['default_batch_export_size'] = [
      '#type' => 'number',
      '#title' => $this
        ->t('Batch export size'),
      '#min' => 1,
      '#required' => TRUE,
      '#default_value' => $config
        ->get('batch.default_batch_export_size'),
      '#description' => $this
        ->t('Batch export size is used when submissions are being exported/downloaded.'),
    ];
    $form['batch']['default_batch_import_size'] = [
      '#type' => 'number',
      '#title' => $this
        ->t('Batch import size'),
      '#min' => 1,
      '#required' => TRUE,
      '#default_value' => $config
        ->get('batch.default_batch_import_size'),
      '#description' => $this
        ->t('Batch import size is used when submissions are being imported/uploaded.'),
    ];
    $form['batch']['default_batch_update_size'] = [
      '#type' => 'number',
      '#title' => $this
        ->t('Batch update size'),
      '#min' => 1,
      '#required' => TRUE,
      '#default_value' => $config
        ->get('batch.default_batch_update_size'),
      '#description' => $this
        ->t('Batch update size is used when submissions are being bulk updated.'),
    ];
    $form['batch']['default_batch_delete_size'] = [
      '#type' => 'number',
      '#title' => $this
        ->t('Batch delete size'),
      '#description' => $this
        ->t('Batch delete size is used when submissions are being cleared.'),
      '#min' => 1,
      '#required' => TRUE,
      '#default_value' => $config
        ->get('batch.default_batch_delete_size'),
    ];
    $form['batch']['default_batch_email_size'] = [
      '#type' => 'number',
      '#title' => $this
        ->t('Batch email size'),
      '#description' => $this
        ->t('Batch email size is used by any handler that sends out bulk emails. This include the scheduled email handler.'),
      '#min' => 1,
      '#required' => TRUE,
      '#default_value' => $config
        ->get('batch.default_batch_email_size'),
    ];

    // Repair.
    $form['repair'] = [
      '#type' => 'details',
      '#title' => $this
        ->t('Repair webform configuration'),
      '#open' => TRUE,
      '#help' => FALSE,
      '#weight' => 100,
    ];
    $form['repair']['warning'] = [
      '#type' => 'webform_message',
      '#message_type' => 'warning',
      '#message_message' => $this
        ->t('Repair and remove older Webform configuration files.') . '<br/>' . '<strong>' . $this
        ->t('This action cannot be undone.') . '</strong>',
    ];
    $form['repair'] += [
      'title' => [
        '#markup' => $this
          ->t('This action will…'),
      ],
      'list' => [
        '#theme' => 'item_list',
        '#items' => [
          $this
            ->t('Repair webform submission storage schema'),
          $this
            ->t('Repair admin configuration'),
          $this
            ->t('Repair webform settings'),
          $this
            ->t('Repair webform handlers'),
          $this
            ->t('Repair webform field storage definitions'),
          $this
            ->t('Repair webform submission storage schema'),
          $this
            ->t('Remove webform submission translation settings'),
        ],
      ],
    ];
    $form['repair']['action'] = [
      '#type' => 'actions',
    ];
    $form['repair']['action']['repair_configuration'] = [
      '#type' => 'submit',
      '#value' => $this
        ->t('Repair configuration'),
      '#attributes' => [
        'onclick' => 'return confirm("' . $this
          ->t('Are you sure you want to repair and remove older webform configuration?') . PHP_EOL . $this
          ->t('This cannot be undone!!!') . '");',
      ],
    ];
    return parent::buildForm($form, $form_state);
  }

  /**
   * {@inheritdoc}
   */
  public function submitForm(array &$form, FormStateInterface $form_state) {
    $op = (string) $form_state
      ->getValue('op');
    if ($op === (string) $this
      ->t('Repair configuration')) {

      // Copied from:
      // @see \Drupal\webform\Commands\WebformCliService::drush_webform_repair
      module_load_include('install', 'webform');
      $this
        ->messenger()
        ->addMessage($this
        ->t('Repairing webform submission storage schema…'));
      _webform_update_webform_submission_storage_schema();
      $this
        ->messenger()
        ->addMessage($this
        ->t('Repairing admin configuration…'));
      _webform_update_admin_settings(TRUE);
      $this
        ->messenger()
        ->addMessage($this
        ->t('Repairing webform settings…'));
      _webform_update_webform_settings();
      $this
        ->messenger()
        ->addMessage($this
        ->t('Repairing webform handlers…'));
      _webform_update_webform_handler_settings();
      $this
        ->messenger()
        ->addMessage($this
        ->t('Repairing webform field storage definitions…'));
      _webform_update_field_storage_definitions();
      $this
        ->messenger()
        ->addMessage($this
        ->t('Repairing webform submission storage schema…'));
      _webform_update_webform_submission_storage_schema();
      if ($this->moduleHandler
        ->moduleExists('webform_entity_print')) {
        $this
          ->messenger()
          ->addMessage($this
          ->t('Repairing webform entity print settings…'));
        module_load_include('install', 'webform_entity_print');
        webform_entity_print_install();
      }
      $this
        ->messenger()
        ->addMessage($this
        ->t('Removing (unneeded) webform submission translation settings…'));
      _webform_update_webform_submission_translation();
      drupal_flush_all_caches();
      $this
        ->messenger()
        ->addStatus($this
        ->t('Webform configuration has been repaired.'));
    }
    else {

      // Update config and submit form.
      $config = $this
        ->config('webform.settings');
      $config
        ->set('ui', $form_state
        ->getValue('ui'));
      $config
        ->set('requirements', $form_state
        ->getValue('requirements'));
      $config
        ->set('test', $form_state
        ->getValue('test'));
      $config
        ->set('batch', $form_state
        ->getValue('batch'));

      // Track if help is disabled.
      // @todo Figure out how to clear cached help block.
      $is_help_disabled = $config
        ->getOriginal('ui.help_disabled') !== $config
        ->get('ui.help_disabled');
      $is_toolbar_item = $config
        ->getOriginal('ui.toolbar_item') !== $config
        ->get('ui.toolbar_item');
      parent::submitForm($form, $form_state);

      // Clear cached data.
      if ($is_help_disabled || $is_toolbar_item) {

        // Flush cache when help is being enabled.
        // @see webform_help()
        drupal_flush_all_caches();
      }
      else {

        // Clear render cache so that local tasks can be updated to hide/show
        // the 'Contribute' tab.
        // @see webform_local_tasks_alter()
        $this->renderCache
          ->deleteAll();
        $this->routerBuilder
          ->rebuild();
      }

      // Redirect to the update advanced admin configuration form.
      if ($is_toolbar_item) {
        $path = $config
          ->get('ui.toolbar_item') ? '/admin/webform/config/advanced' : '/admin/structure/webform/config/advanced';
        $form_state
          ->setRedirectUrl(Url::fromUserInput($path));
      }
    }
  }

}

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.
WebformAdminConfigAdvancedForm::$cliService protected property The (drush) command-line service.
WebformAdminConfigAdvancedForm::$moduleHandler protected property The module handler.
WebformAdminConfigAdvancedForm::$renderCache protected property The render cache bin.
WebformAdminConfigAdvancedForm::$routerBuilder protected property The router builder.
WebformAdminConfigAdvancedForm::buildForm public function Form constructor. Overrides ConfigFormBase::buildForm
WebformAdminConfigAdvancedForm::create public static function Instantiates a new instance of this class. Overrides ConfigFormBase::create
WebformAdminConfigAdvancedForm::getFormId public function Returns a unique string identifying the form. Overrides FormInterface::getFormId
WebformAdminConfigAdvancedForm::submitForm public function Form submission handler. Overrides WebformAdminConfigBaseForm::submitForm
WebformAdminConfigAdvancedForm::__construct public function Constructs a WebformAdminConfigAdvancedForm object. Overrides ConfigFormBase::__construct
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.