Commit 0d64b6a2 authored by Bert Jansen's avatar Bert Jansen
Browse files

Issue #3283177: Reload on success setting

parent 315c5c7b
Loading
Loading
Loading
Loading
+8 −0
Original line number Diff line number Diff line
@@ -58,6 +58,13 @@ class RouteInModalSettingsForm extends ConfigFormBase {
      '#default_value' => $config->get('confirmation_messages_modal'),
    ];

    $form['reload_on_success'] = [
      '#type' => 'checkbox',
      '#title' => $this->t('Reload on success'),
      '#description' => $this->t('Reload the page (instead of redirecting) upon completion.'),
      '#default_value' => $config->get('reload_on_success'),
    ];

    return parent::buildForm($form, $form_state);
  }

@@ -70,6 +77,7 @@ class RouteInModalSettingsForm extends ConfigFormBase {
      ->set('dialog_width', $form_state->getValue('dialog_width'))
      ->set('dialog_height', $form_state->getValue('dialog_height'))
      ->set('confirmation_messages_modal', $form_state->getValue('confirmation_messages_modal'))
      ->set('reload_on_success', $form_state->getValue('reload_on_success'))
      ->save();

    parent::submitForm($form, $form_state);
+12 −7
Original line number Diff line number Diff line
@@ -10,6 +10,7 @@ use Drupal\Core\Ajax\PrependCommand;
use Drupal\Core\Ajax\RedirectCommand;
use Drupal\Core\Ajax\RemoveCommand;
use Drupal\Core\Form\FormStateInterface;
use Drupal\route_in_modal\AjaxCommand\RefreshPageCommand;

/**
 * A helper class for creating Ajax responses for Route In Modal.
@@ -72,8 +73,7 @@ class RouteInModalAjaxHelper {
      $moduleHandler = \Drupal::service('module_handler');
      if ($moduleHandler->moduleExists('inline_form_errors')) {
        // Refresh form with inline errors.
        $renderedForm = $renderer->renderRoot($form);
        $response->addCommand(new HtmlCommand('#route_in_modal_wrapper', $renderedForm));
        $response->addCommand(new HtmlCommand('#route_in_modal_wrapper', $form));

        // Delete default messages.
        \Drupal::messenger()->deleteAll();
@@ -105,12 +105,17 @@ class RouteInModalAjaxHelper {
   * @param \Drupal\Core\Form\FormStateInterface $formState
   *   The form state.
   *
   * @return \Drupal\Core\Ajax\RedirectCommand
   *   The redirect command.
   * @return \Drupal\Core\Ajax\RedirectCommand|\Drupal\route_in_modal\AjaxCommand\RefreshPageCommand
   *   The AJAX response.
   */
  public static function redirectCommand(FormStateInterface $formState): RedirectCommand {
    return new RedirectCommand(\Drupal::request()->headers->get('referer') . $formState->getRedirect());
  }
  public static function redirectCommand(FormStateInterface $formState) {
    global $base_url;

    $config = \Drupal::config('route_in_modal.settings');

    return $config->get('reload_on_success')
      ? new RefreshPageCommand()
      : new RedirectCommand($base_url . $formState->getRedirect());
  }

}