You are here

public function SearchContentForm::submitForm in Open Social 8

Same name and namespace in other branches
  1. 8.9 modules/social_features/social_search/src/Form/SearchContentForm.php \Drupal\social_search\Form\SearchContentForm::submitForm()
  2. 8.2 modules/social_features/social_search/src/Form/SearchContentForm.php \Drupal\social_search\Form\SearchContentForm::submitForm()
  3. 8.3 modules/social_features/social_search/src/Form/SearchContentForm.php \Drupal\social_search\Form\SearchContentForm::submitForm()
  4. 8.4 modules/social_features/social_search/src/Form/SearchContentForm.php \Drupal\social_search\Form\SearchContentForm::submitForm()
  5. 8.5 modules/social_features/social_search/src/Form/SearchContentForm.php \Drupal\social_search\Form\SearchContentForm::submitForm()
  6. 8.6 modules/social_features/social_search/src/Form/SearchContentForm.php \Drupal\social_search\Form\SearchContentForm::submitForm()
  7. 8.7 modules/social_features/social_search/src/Form/SearchContentForm.php \Drupal\social_search\Form\SearchContentForm::submitForm()
  8. 8.8 modules/social_features/social_search/src/Form/SearchContentForm.php \Drupal\social_search\Form\SearchContentForm::submitForm()
  9. 10.3.x modules/social_features/social_search/src/Form/SearchContentForm.php \Drupal\social_search\Form\SearchContentForm::submitForm()
  10. 10.0.x modules/social_features/social_search/src/Form/SearchContentForm.php \Drupal\social_search\Form\SearchContentForm::submitForm()
  11. 10.1.x modules/social_features/social_search/src/Form/SearchContentForm.php \Drupal\social_search\Form\SearchContentForm::submitForm()
  12. 10.2.x modules/social_features/social_search/src/Form/SearchContentForm.php \Drupal\social_search\Form\SearchContentForm::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/SearchContentForm.php, line 75

Class

SearchContentForm
Class SearchContentForm.

Namespace

Drupal\social_search\Form

Code

public function submitForm(array &$form, FormStateInterface $form_state) {
  $search_all_view = 'search_all';
  if (empty($form_state
    ->getValue('search_input_content'))) {

    // Redirect to the search content page with empty search values.
    $search_content_page = Url::fromRoute("view.{$search_all_view}.page_no_value");
  }
  else {

    // Redirect to the search content page with filters in the GET parameters.
    $search_input = Html::escape($form_state
      ->getValue('search_input_content'));
    $search_input = preg_replace('/[\\/]+/', ' ', $search_input);
    $search_content_page = Url::fromRoute("view.{$search_all_view}.page", [
      'keys' => $search_input,
    ]);
  }
  $redirect_path = $search_content_page
    ->toString();
  $query = UrlHelper::filterQueryParameters($this->requestStack
    ->getCurrentRequest()->query
    ->all());
  $redirect = Url::fromUserInput($redirect_path, [
    'query' => $query,
  ]);
  $form_state
    ->setRedirectUrl($redirect);
}