public function SearchHeroForm::submitForm in Open Social 8
Same name and namespace in other branches
- 8.9 modules/social_features/social_search/src/Form/SearchHeroForm.php \Drupal\social_search\Form\SearchHeroForm::submitForm()
- 8.2 modules/social_features/social_search/src/Form/SearchHeroForm.php \Drupal\social_search\Form\SearchHeroForm::submitForm()
- 8.3 modules/social_features/social_search/src/Form/SearchHeroForm.php \Drupal\social_search\Form\SearchHeroForm::submitForm()
- 8.4 modules/social_features/social_search/src/Form/SearchHeroForm.php \Drupal\social_search\Form\SearchHeroForm::submitForm()
- 8.5 modules/social_features/social_search/src/Form/SearchHeroForm.php \Drupal\social_search\Form\SearchHeroForm::submitForm()
- 8.6 modules/social_features/social_search/src/Form/SearchHeroForm.php \Drupal\social_search\Form\SearchHeroForm::submitForm()
- 8.7 modules/social_features/social_search/src/Form/SearchHeroForm.php \Drupal\social_search\Form\SearchHeroForm::submitForm()
- 8.8 modules/social_features/social_search/src/Form/SearchHeroForm.php \Drupal\social_search\Form\SearchHeroForm::submitForm()
- 10.3.x modules/social_features/social_search/src/Form/SearchHeroForm.php \Drupal\social_search\Form\SearchHeroForm::submitForm()
- 10.0.x modules/social_features/social_search/src/Form/SearchHeroForm.php \Drupal\social_search\Form\SearchHeroForm::submitForm()
- 10.1.x modules/social_features/social_search/src/Form/SearchHeroForm.php \Drupal\social_search\Form\SearchHeroForm::submitForm()
- 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 92
Class
- SearchHeroForm
- Class SearchHeroForm.
Namespace
Drupal\social_search\FormCode
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 = Html::escape($form_state
->getValue('search_input'));
$search_input = preg_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());
$redirect = Url::fromUserInput($redirect_path, [
'query' => $query,
]);
$form_state
->setRedirectUrl($redirect);
}