openeuropa / oe_whitelabel

European Union Public License 1.2
2 stars 4 forks source link

Preserve the query parameters when submitting the SearchForm #242

Open msnassar opened 7 months ago

msnassar commented 7 months ago

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

Steps to reproduce:

Expected result:

Actual result:

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.