You are here

public function SearchHeroForm::submitForm in Open Social 8.9

Same name and namespace in other branches
  1. 8 modules/social_features/social_search/src/Form/SearchHeroForm.php \Drupal\social_search\Form\SearchHeroForm::submitForm()
  2. 8.2 modules/social_features/social_search/src/Form/SearchHeroForm.php \Drupal\social_search\Form\SearchHeroForm::submitForm()
  3. 8.3 modules/social_features/social_search/src/Form/SearchHeroForm.php \Drupal\social_search\Form\SearchHeroForm::submitForm()
  4. 8.4 modules/social_features/social_search/src/Form/SearchHeroForm.php \Drupal\social_search\Form\SearchHeroForm::submitForm()
  5. 8.5 modules/social_features/social_search/src/Form/SearchHeroForm.php \Drupal\social_search\Form\SearchHeroForm::submitForm()
  6. 8.6 modules/social_features/social_search/src/Form/SearchHeroForm.php \Drupal\social_search\Form\SearchHeroForm::submitForm()
  7. 8.7 modules/social_features/social_search/src/Form/SearchHeroForm.php \Drupal\social_search\Form\SearchHeroForm::submitForm()
  8. 8.8 modules/social_features/social_search/src/Form/SearchHeroForm.php \Drupal\social_search\Form\SearchHeroForm::submitForm()
  9. 10.3.x modules/social_features/social_search/src/Form/SearchHeroForm.php \Drupal\social_search\Form\SearchHeroForm::submitForm()
  10. 10.0.x modules/social_features/social_search/src/Form/SearchHeroForm.php \Drupal\social_search\Form\SearchHeroForm::submitForm()
  11. 10.1.x modules/social_features/social_search/src/Form/SearchHeroForm.php \Drupal\social_search\Form\SearchHeroForm::submitForm()
  12. 10.2.x modules/social_features/social_search/src/Form/SearchHeroForm.php \Drupal\social_search\Form\SearchHeroForm::submitForm()

Form submission handler.

Parameters

array $form: An associative array containing the structure of the form.

\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.

Overrides FormInterface::submitForm

File

modules/social_features/social_search/src/Form/SearchHeroForm.php, line 94

Class

SearchHeroForm
Class SearchHeroForm.

Namespace

Drupal\social_search\Form

Code

public function submitForm(array &$form, FormStateInterface $form_state) {
  $current_route = $this->routeMatch
    ->getRouteName();
  $route_parts = explode('.', $current_route);
  if (empty($form_state
    ->getValue('search_input'))) {

    // Redirect to the search page with empty search values.
    $new_route = "view.{$route_parts[1]}.page_no_value";
    $search_group_page = Url::fromRoute($new_route);
  }
  else {

    // Redirect to the search page with filters in the GET parameters.
    $search_input = Xss::filter($form_state
      ->getValue('search_input'));
    $search_input = preg_replace('/[\\/]+/', ' ', $search_input);
    $search_input = str_replace('&', '&', $search_input);
    $new_route = "view.{$route_parts[1]}.page";
    $search_group_page = Url::fromRoute($new_route, [
      'keys' => $search_input,
    ]);
  }
  $redirect_path = $search_group_page
    ->toString();
  $query = UrlHelper::filterQueryParameters($this->requestStack
    ->getCurrentRequest()->query
    ->all(), [
    'page',
  ]);
  $redirect = Url::fromUserInput($redirect_path, [
    'query' => $query,
  ]);
  $form_state
    ->setRedirectUrl($redirect);
}