2

I would like to redirect the user to a view with some contextual filters on the submit of a custom form.

For now I use this :

$form_state->setRedirect('view.search.page_1', ['myvalue' => $value]);

But it add "myvalue" like this : /search?myvalue=$value

and what I want is : /search/$value

Thanks

2 Answers 2

7

You have to use the route parameter names defined in the route.

You can check the route definition of this view display with help of the Devel module by visiting:

www.example.com/devel/routes

When you define contextual filters the route parameter names are usually {arg_0}, {arg_1} ...

So this could work:

$form_state->setRedirect('view.search.page_1', ['arg_0' => $value]);
0

I guess it is not directly possible, you could however solve it with a small workaround:

$uri = \Drupal\Core\Url::fromUri('base:/your-views-path/' . $value, ['absolute' => TRUE]);
$form_state->setRedirectUrl($uri);

Edit: @4k4 has the better solution.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.