I have a view with a pulldown menu within an exposed form. I want to set that URL parameter to a default value based on the currentLanguage() of the session. Is there a way to edit the URL parameters that a View can see within a custom module or the theme's template_ functions?

2 Answers 2


Within a custom module, it is possible to use the hook_views_pre_view hook. You can alter the $args array passed as parameter, in order to add or remove arguments.

  • Thanks. Strangely my new function MYMODULE_views_pre_view(ViewExecutable $view, $display_id, array &$args) in MYMODULE.module is ignored even after a full cache reset.
    – Nic
    Commented Jan 23, 2017 at 10:57
  • @Nic, yes it is strange. I just made some testing on a vanilla D8 site, and MYMODULE_views_pre_view(...) is called. Maybe a caching issue...
    – dinopmi
    Commented Jan 23, 2017 at 16:10

I ended up doing this to get it working:

function MYMODULE_form_alter(&$form, $form_state, $form_id) {
  if($form['#id'] == 'views-exposed-form-BLAH-page-1e' && 
        $form_id ="views_exposed_form") {
    $request = \Drupal::request();
     // check that no URL param is already set
      if (!$request->get('MYEXPOSEDFIELDID', NULL)) { 
        // reference to user input object (for editing)
        $input = &$form_state->getUserInput();

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.