Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Preserve the query parameters when submitting the SearchForm #242

Open
msnassar opened this issue Dec 5, 2023 · 0 comments
Open

Preserve the query parameters when submitting the SearchForm #242

msnassar opened this issue Dec 5, 2023 · 0 comments

Comments

@msnassar
Copy link

msnassar commented Dec 5, 2023

In search pages, when submitting the SearchForm, other query parameters (e.g. facets filters and sorting) are getting lost.

Steps to reproduce:

Expected result:

  • I expect that the category and sorting criteria are preserved and applied.

Actual result:

  • I lose the previously applied filters and sorting criteria

Proposed solution:
Preserve all query parameters when submitting the SearchForm.

  /**
   * {@inheritdoc}
   */
  public function submitForm(array &$form, FormStateInterface $form_state): void {
    $config = $form_state->get('oe_whitelabel_search_config');
    $url = Url::fromUri('base:' . $config['form']['action'], [
      'language' => $this->languageManager->getCurrentLanguage(),
      'absolute' => TRUE,
      'query' => $this->requestStack->getCurrentRequest()->query->all(),
    ]);
    $url->mergeOptions([
      'query' => [
        $config['input']['name'] => $form_state->getValue('search_input'),
      ],
    ]);
    $form_state->setRedirectUrl($url);
  }

Lets discuss it if you agree with the approach.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant