diff --git a/src/Plugin/facets/widget/CheckboxWidget.php b/src/Plugin/facets/widget/CheckboxWidget.php index bb71fed..27382ab 100644 --- a/src/Plugin/facets/widget/CheckboxWidget.php +++ b/src/Plugin/facets/widget/CheckboxWidget.php @@ -90,6 +90,8 @@ class CheckboxWidget implements WidgetInterface, FormInterface { public function buildForm(array $form, FormStateInterface $form_state) { /** @var \Drupal\facets\FacetInterface $facet */ + // Get the facet form the build info, see the remark in ::build to know + // where this comes from. $build_info = $form_state->getBuildInfo(); $facet = $build_info['args'][0]; @@ -157,15 +159,20 @@ class CheckboxWidget implements WidgetInterface, FormInterface { } } - // We have an active item, so redirecting to that page. + // We have an active item, so we redirect to the page that has that facet + // selected. This should be an absolute link because RedirectResponse is a + // symfony class that requires a full URL. if ($result_link instanceof Url) { $result_link->setAbsolute(); $form_state->setResponse(new RedirectResponse($result_link->toString())); return; } - // Form was submitted, but nothing was selected, so we should submit to the - // facet. - $form_state->setResponse(new RedirectResponse('/' . $facet->getFacetSource()->getPath())); + // The form was submitted but nothing was active in the form, we should + // still redirect, but the url for the new page can't come from a result. + // So we're redirecting to the facet source's page. + $link = Url::fromUri($facet->getFacetSource()->getPath()); + $link->setAbsolute(); + $form_state->setResponse(new RedirectResponse($link->toString())); } }