Get NULL in contextual default argument

Created on 2 April 2024, 9 months ago

Problem/Motivation

I'll try to describe here something I'm encountering in views with contextual filters, and exposed filters.
I have an existing view that uses the string filter plugins defined in the Views Autocomplete Filters module; practically in the formValue() method the values of any contextual filters are also retrieved to create the URL for auto-completion. My contextual filter is "Provide default value: Store ID from current store". The problem is that the autocomplete string filter plugin is executed before the commerce_store's default contextual plugin and I end up with $this->view->args === [NULL] which obviously fails the view with

The "view_args" parameter for the "views_filters.autocomplete" route must match "[^/]++" ("" provided) to generate a matching URL.

Steps to reproduce

  • Install commerce and views_autocomplete_filters
  • Create some dummies commerce orders
  • Create a view with a contextual filter "Provide default value: Store ID from current store".
  • Add an exposed filter on order title field enabling the Autocomplete option

Proposed resolution

Execute the contextual filter plugins before the exposed ones.

Remaining tasks

TBD

🐛 Bug report
Status

Active

Version

2.0

Component

Code

Created by

🇮🇹Italy robertoperuzzo 🇮🇹 Tezze sul Brenta, VI

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @robertoperuzzo
  • 🇮🇹Italy robertoperuzzo 🇮🇹 Tezze sul Brenta, VI

    I temporarily fixed in my project defining my custom plugin class

    class AutocompleteFiltersString extends ViewsAutocompleteFiltersString {
    
      /**
       * {@inheritdoc}
       */
      public function valueForm(&$form, FormStateInterface $form_state): void {
        if (
          empty(array_filter($this->view->args))
          && isset($this->view->argument['store_id'])
        ) {
          $this->view->args = [(int) $this->view->argument['store_id']->getValue()];
        }
    
        parent::valueForm($form, $form_state);
      }
    
    }
    
Production build 0.71.5 2024