public function WidgetForm::submitForm in Search API Sorts Widget 1.x
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
- src/
Form/ WidgetForm.php, line 131
Class
- WidgetForm
- Provides a Search API Sorts Widget form.
Namespace
Drupal\search_api_sorts_widget\FormCode
public function submitForm(array &$form, FormStateInterface $form_state) {
$links = $form_state
->get('links');
[
$key,
$order,
] = explode('|', $form_state
->getValue('sort_by'));
foreach ($links['#items'] as $link) {
$name = $link['#sort_field'];
if ($name == $key) {
$url = $link['#url'];
$url_info = parse_url($url);
parse_str($url_info['query'], $query);
$query['order'] = $order;
$url_info['query'] = UrlHelper::buildQuery($query);
$url = $url_info['path'] . '?' . $url_info['query'];
$form_state
->setRedirectUrl(Url::fromUserInput($url));
}
}
}