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
None.
API changes
None.
Data model changes
| Comment | File | Size | Author |
|---|---|---|---|
| #17 | 2997393-17-fail.patch | 2.7 KB | vakulrai |
Issue fork drupal-2997393
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
- 2997393-filter-out-non-selected
changes, plain diff MR !9830
Comments
Comment #2
andypostGood idea to store much less! surely it needs update hook to clean-up a lot of core views at least
Comment #3
longwave+1, I have been annoyed by this since D7 and Features exports.
Comment #4
andypostThat works for me
Comment #5
jibranComment #7
phthlaap commentedHi,
I have tested this issue manually. It worked for me.
Comment #12
alexpottThis would be a lovely thing to land. We need a test and an update function in order to land this!
Comment #13
renatog commentedThis line has more than 80 chats. Please could you break this array in a second line? E.g.:
From:
$form_state->setValue(['options', 'expose', 'remember_roles'], array_filter($roles));
To:
Comment #14
nikitagupta commentedRerolled the patch #4.
Comment #15
renatog commentedThat's great. Thank you so much
Comment #16
longwaveStill needs a test and update hook as per #12.
Comment #17
vakulrai commentedAdding a test and update hook for the issue , the update hook finds all view yml files and set the updated configurations. couldn't find anything more effective to update the files , even
Yml::dump()dumper has some indentation issues so , I didn't try that.Hope this works.
Kindly review.
Comment #20
andypost@vakulrai great job! needs a bit of work
it should be post update hook and requires test
Comment #21
longwaveThere is a helper class in Views called ViewsConfigUpdater than can be used to modify Views config entities in update hooks, instead of parsing/rewriting the YAML directly.
Comment #22
vakulrai commented@andypost, @longwave I worked on the inputs given by you and have made the changes accordingly to the patch. The patch has following updates,
- .install code has been moved to hook_post_update_name() with some modifications.
- in post_update I have used the ViewsConfigUpdater class to modify the view
- added a test for post_update.
Kindly review.
Comment #23
vakulrai commentedI missed the tests for hook_post_update in previous patch, re uploading the patch with interdiff. Consider this for review.
Thanks.
Comment #24
kapilv commentedFixed Custom Commands Failed.
Comment #25
gauravvvv commentedRe-rolled the patch, Attached interdiff for same.
Comment #26
andypostIt could use to extend
\Drupal\views\ViewsConfigUpdater::processOperatorDefaultsHandler()via\Drupal\views\ViewsConfigUpdater::updateAll()but it looks more straight to not extend itComment #27
longwaveCouple of little nits but this looks almost ready to go.
I think the setValue call should all be on one line if the getValue call is.
re4member -> remember
Nice! Today I learned you can search with array_keys() alone.
Comment #28
ankithashettyUpdated patch in #26 addressing #27, also made a following small change(attached an interdiff):
Thanks!
Comment #29
meenakshi_j commentedFixed the #28 custom commands.
Comment #30
renatog commentedInterdiff between #28 and #29
Comment #31
renatog commentedOn this part
We should apply some early return to avoid many level of if and foreach
Comment #32
renatog commentedNew patch applied early return on this method
Comment #33
renatog commentedPlease discard #32
New patch #33 applied early return on this method
Comment #34
longwaveThanks, no issues remaining, this all looks good now.
Comment #35
andypostI think the update name and displayable title needs review
Comment #37
andypostRandom failure
Comment #38
berdirI see the latest patch added a variable for this, seems like an edge case of whether or not that's actually needed. If we do have one, then I would propose a different variable name, actually confused me for a second. Those aren't the roles, just the form key to access them. Maybe add _keys?
Personally, I think that writing update functions like this is adding a lot of complexity for very little gain. Their config schema is still fine and nothing is broken, we just have those bogus keys in there.
What I think we should do however is clean up all existing default views in core. Search for remember_roles:, you'll have a bunch that have non-selected entries in there. Or "anonymous: '0'" that alone finds 72 examples. Mostly test views, but also in comment, files and people views.
Comment #39
vakulrai commented@berdir , I have updated the point #38.1, and for #38.2 I have already tried updating the yml files using the yml parser and dumping the updated data for all the files inside /core, but the dumper has some yml alignment issues, so we went for the hook_post_update approach to update only the view content entities.
Thanks
Comment #40
berdirHm, you changed the lines below that as well now, I'd avoid making coding standard improvements on otherwise unchanged lines.
On the second point, where I put that comment was maybe a bit misleading. I'm not talking about writing an update function to change those files. Update functions must never change files, you have to expect that they might be read-only.
But that's not needed. Instead, make the change (more or less) manually, and then put it in the patch. It's going to be a much bigger patch, but that's fine.
PS: There is no such thing as view content entities. They are always config entities, whether they are in files or in the database.
Comment #41
andypostHere's a fix for all core's view, also updated upgrade path test to use copy of affected
views.view.who_s_online.ymlLooks ready to go, probably backportable to next 9.2.x
Sorry for interdiff bigger then patch
reverted it as out of scope
Comment #42
berdirhm, considering that we updated several default views like comment and admin people, I would expect that we can just use those to assert this and don't need to create a test?
We did that before with the files view, nothing wrong with that? The update test is based on a database dump, that still has the old definition with : '0'?
Comment #43
andypostRemoved test view as "files" comes from dump also fixed test
Comment #45
lendudeConfusing variable name in this context, copy/paste left over, lets find a better name
No need to check that here we have the test that this was copied from for this
We don't explicitly add a third role in this test, so if these are the only two available roles in this set up (no idea if that is the case or not...), this would be the same as selecting all the roles. I would add a new role and make sure at the end that this isn't added to the config.
Comment #46
lendudeAlso, not sure this is the best place to add this test, not really related to the Wizard at all
Comment #50
altcom_neil commentedHi, 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.
Comment #51
altcom_neil commentedSorry - ignore this one - wrong patch file!
Comment #52
altcom_neil commentedComment #53
altcom_neil commentedSorry, correct patch file for 10.3+/11.x
Comment #56
tobiasbI 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.
Comment #57
smustgrave commentedWill probably need upgrade path tests.
Looks good!
Comment #58
tobiasbComment #59
tobiasbThe update test is in core/modules/views/tests/src/Functional/Update/UserRememberRolesFilterSettingTest.php.
Comment #60
andypostThank you, looks ready
Comment #61
oily commentedRan the 'test-only' test. It fails as it should. Pipeline otherwise all green.
Comment #62
oily commentedCorrected one typo then remembered the etiquette so added two threads: code comment nits.
Comment #63
catchOne comment on the post update, overall this looks good though.
Comment #64
tobiasbRebased && add missing call to setDeprecationsEnabled.
Comment #66
catchLooks great now, really nice to see this one ready.
Committed/pushed to 11.x, thanks!
Comment #69
dadderley commentedHello,
I have just upgraded a site to 11.2.2.
When running the DB update script I get this:
Pardon my ignorance, but is this related at all to this issue?
Just added...
I had a misbehaving unused view that caused this error. I deleted the view and I was able to complete the update. Interestingly enough, I could not disable or duplicate the view in the views overview page. When I tried to edit the view I got a WSOD and this error:
Drupal\Component\Plugin\Exception\PluginNotFoundException: The "taxonomy_term_name_into_id" plugin does not exist. Valid plugin IDs for Drupal\views\Plugin\ViewsPluginManager are: taxonomy_term_name, user_name, entity:block, entity:block_content_type, entity:block_content, entity:captcha_point, entity:comment_type, entity:comment, entity:editor, entity:entity_subqueue, entity:entity_queue, entity:field_config, entity:field_storage_config, entity:file, entity:filter_format, entity:image_style, entity:imce_profile, entity:linkit_profile, entity:media_type, entity:media, entity:menu_link_content, entity:menu_position_rule, entity:metatag_defaults, entity:node, entity:node_type, entity:paragraphs_library_item, entity:path_alias, entity:redirect, entity:responsive_image_style, entity:search_page, entity:shortcut, entity:shortcut_set, entity:slick, entity:smart_date_format, entity:smart_date_rule, entity:smart_date_override, entity:menu, entity:action, entity:taxonomy_vocabulary, entity:taxonomy_term, entity:user, entity:user_role, entity:webform_options, entity:webform_submission, entity:webform, entity:pathauto_pattern, entity:xmlsitemap, entity:view, entity:paragraph, entity:paragraphs_type, entity:entity_view_display, entity:entity_form_mode, entity:entity_view_mode, entity:entity_form_display, entity:base_field_override, entity:date_format, none, numeric in Drupal\Core\Plugin\DefaultPluginManager->doGetDefinition() (line 53 of /home/customer/www/ferniefix.com/public_html/core/lib/Drupal/Component/Plugin/Discovery/DiscoveryTrait.php).Comment #70
tobiasb@dadderley You have something in your view which is broken.
The plugin ID comes from https://www.drupal.org/project/views_taxonomy_term_name_into_id
Comment #71
dadderley commented@tobiasb
Thanks, I found the error in the view.
Comment #72
tregonia commentedDoing updates today and found this in my logs. Searching for
views_post_update_update_remember_role_emptyleads me to this issue.Listed as an update to execute
views update_remember_role_empty post-update Clean-up empty remember_roles display settings for views filters.I cannot speak to the issues that cause or come from this; I am only reporting the message.