Correct views hook to alter contextual filter I am trying to find the correct views hook to alter/add a contextual filter to a views block that's being rendered in a template. (Using drupal_view and the twig tweaks module).
The view is setup to accept a contextual filter that is provided in the URL by default. It works great on that page, however it's been requested that the view also display on a sub-page of this main page, in where the URL does not contain the contextual filter. Therefore, I am trying to find a views hook that I can reliably attach the contextual filter to and have it work every page load.
I have tried using hook_views_pre_view(), however this appears to only work once between cache clears, as if I clear cache it works, then as soon as I refresh the page it stops working again until another cache clear.
Is there a way I can do this from a hook? The way the child-page is structured, I can't easily get it from the template to pass it into drupal_view() as an argument.
The current code I am using is:
function item_types_views_pre_view(&amp;$view, &amp;$display_id, &amp;$args) {
    if ($view-&gt;id() == 'existing_copies') {

        $parameters = \Drupal::routeMatch()-&gt;getParameters();
        $imcid = \Drupal::routeMatch()-&gt;getParameter('imcid');

        $entity = \Drupal::entityTypeManager()-&gt;getStorage('item_type')-&gt;load($imcid);

        if ($entity-&gt;bundle() == 'book_copy') {
            $main_record = $entity-&gt;field_book_main_record-&gt;getString();
        }
        elseif ($entity-&gt;bundle() == 'book_master_copy') {
            $main_record = $entity-&gt;field_master_copy_book_mr-&gt;getString();
        }

        $args = [$main_record];
    }
}

Which like I said, works great immediately after a cache clear, but no longer works after the page is refreshed.
I was able to use achieved what I wanted by using hook_views_pre_build() as below
hook_views_pre_build(ViewExecutable $view) {
  $args[0] = '1234';

  $view-&gt;addArguments($args);
}