How render view with programmatically passed parameters of contextual filter


Use hook_views_pre_view

function mymodule_views_pre_view(\Drupal\views\ViewExecutable $view, $display_id, array &$args) {
  // Modify contextual filters for view_name.
  $paragraph_id = 22;
  if ($view->id() == 'view_name') {
    $args = [$paragraph_id]; // args must be an array.
Tags: Drupal 8 / Hooks

Similar questions

How can I filter child terms in an exposed filter by parent term from contextual filter?
I have a vocabulary of Districts with nested taxonomy terms like below. I have a view of taxonomy terms in Drupal 8 which has an exposed filter of all terms with parent and child. What I want is that when I add a contextual filter of term parent the exposed filter should only show child terms matching the parent term in the contextual filter. For e...
How to use value passed to views_embed_view as a filter?
I want to embed a View in a node template. I understand that I can use views_embed view to do that, and pass values to it. How can I use that value as a filter ? I want that view to list nodes that have a field with the same value as the passed to the function
How to prevent the page contextual filter to be appended to the page url when using contextual filters in drupal?
I have a page that has both a contextual filter and an exposed filter. My Problem lies in the fact that If I access the page through myview/12 (where 12 is my contextual filter) and then use the on-page exposed filter to filter out the result , the value 12 would still be appended to the page and it would limit my results within the contextual filt...
Views, Taxonomy, multiple parameters using contextual filters
A view has been created to display related content types via their taxonomy terms, using contextual filters. Currently the view is able to display content based on the first param eg. about The goal is to abe to display content based on the second param, being the child term and hide the parent eg. about/meet-the-team. Here is a break down Url : pa...
Pass view contextual filter arguments programmatically
I want to pass contextual filter arguments programmatically to a view. I know it can be done through views_get_view and views_embed_view, but I want to pass it to a view's page display. Also I want to pass multiple arguments to the view, so it won't be good to pass all the arguments in the url. I tried to pass the arguments using $view->args = i...
Programmatically Place View With Defined Fixed Contextual Filter
I'm currently using the starter module which adds the Twig function place_view(). This works well in most cases, however I'd like to be able to pass another parameter to populate the fixed value given in a contextual filter. This would be my contextual filter settings: Here's the place_view() Twig function: Preferably I'd like to be able to use pla...

Also ask

We use cookies to deliver the best possible experience on our website. By continuing to use this site, accepting or closing this box, you consent to our use of cookies. To learn more, visit our privacy policy.