Filter out non-selected roles for the remember_roles setting in views

Created on 5 September 2018, about 6 years ago
Updated 2 September 2024, 3 months ago

Problem/Motivation

Every exposed filter has a checkbox that allows it to be remembered through the session. Not only that, there's also an option to limit that functionality to certain user roles.

Even when that checkbox is off, the view still stores a list of all non-selected roles:

          expose:
            operator_id: ''
            label: Published
            description: ''
            use_operator: false
            operator: status_op
            identifier: status
            required: false
            remember: false
            multiple: false
            remember_roles:
              authenticated: authenticated
              anonymous: '0'
              ***_editor: '0'
              ***_clientadmin: '0'
              administrator: '0'

I don't think there are config dependencies for this but it does make more complicated to re-use views/put them as default config in a module because you tend to have left-over things in there from custom roles. "remember_roles:" exists almost 200x in this projects config sync folder which means 800 lines of useless yaml to parse :) And projects often have a lot more roles.

Proposed resolution

Filter out non-selected roles. Maybe even not store anything if the remember setting is off?

Remaining tasks

User interface changes

API changes

Data model changes

πŸ“Œ Task
Status

Needs work

Version

11.0 πŸ”₯

Component
ViewsΒ  β†’

Last updated 39 minutes ago

Created by

πŸ‡¨πŸ‡­Switzerland berdir Switzerland

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

Merge Requests

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • πŸ‡¬πŸ‡§United Kingdom altcom_neil

    Hi, thanks for the work so far on this.

    We have multiple sites built on the same systems but with some custom user roles. Comparing changes to views between sites has always thrown up the differences in these sections even though none have actually made any changes at all.

    The latest patch didn't apply for me (D10.3.2), so I have created just a patch for the \Drupal\views\Plugin\views\filter\FilterPluginBase::validateExposeForm method from the latest D11 code.

    This works stripping all of the redundant roles from the config.

  • πŸ‡¬πŸ‡§United Kingdom altcom_neil
  • πŸ‡¬πŸ‡§United Kingdom altcom_neil
  • πŸ‡¬πŸ‡§United Kingdom altcom_neil

    Sorry, correct patch file for 10.3+/11.x

  • First commit to issue fork.
  • Pipeline finished with Failed
    about 1 month ago
    Total: 173s
    #307932
  • Pipeline finished with Failed
    about 1 month ago
    Total: 195s
    #307936
  • Pipeline finished with Success
    about 1 month ago
    Total: 1009s
    #308112
  • Pipeline finished with Failed
    about 1 month ago
    Total: 526s
    #308123
  • Pipeline finished with Failed
    about 1 month ago
    Total: 689s
    #308129
  • Pipeline finished with Failed
    about 1 month ago
    Total: 141s
    #308133
  • Pipeline finished with Canceled
    about 1 month ago
    Total: 616s
    #308138
  • Pipeline finished with Failed
    about 1 month ago
    Total: 686s
    #308146
  • Pipeline finished with Failed
    about 1 month ago
    #308161
  • Pipeline finished with Canceled
    about 1 month ago
    Total: 92s
    #308181
  • Pipeline finished with Failed
    about 1 month ago
    Total: 972s
    #308183
  • Pipeline finished with Success
    about 1 month ago
    Total: 757s
    #308195
  • Pipeline finished with Failed
    about 1 month ago
    Total: 420s
    #308226
  • Pipeline finished with Success
    about 1 month ago
    Total: 912s
    #308237
  • Pipeline finished with Success
    about 1 month ago
    Total: 840s
    #308246
  • πŸ‡©πŸ‡ͺGermany tobiasb Berlin

    I move the patch into a MR and fixes the rejected changes + typehints.

    The post update uses now core/modules/views/src/ViewsConfigUpdater.php and moves the test into \Drupal\Tests\views\Functional\Plugin\FilterTest, because there are also other test for \Drupal\views\Plugin\views\filter\FilterPluginBase.

  • Pipeline finished with Success
    about 1 month ago
    Total: 655s
    #308253
  • πŸ‡ΊπŸ‡ΈUnited States smustgrave

    Will probably need upgrade path tests.

    Looks good!

Production build 0.71.5 2024