Views handler loading should respect configuration

Created on 30 June 2024, 2 months ago
Updated 30 August 2024, 9 days ago

Problem/Motivation

  1. A views handler (e.g.) a filter can be configured to use a particular plugin
  2. The Views Handler Manager does not respect this and takes whatever plugin is defined by views data (hook_views_data + hook_views_data_alter)
  3. See ViewsHandlerManager::getHandler($item) - the $item contains the correct plugin_id, yet that is ignored and the views data plugin ID is used instead

This is a problem for ✨ Continuation Add Views EntityReference filter to be available for all entity reference fields Needs work in particular as it means existing configuration is not respected, forcing us to duplicate the views filter rather than allow replacement to avoid a breaking change.

Steps to reproduce

  1. Create a filter, e.g. a numeric filter on a View
  2. Use hook_views_data_alter to change the default filter to something else (e.g. entity_reference)
  3. Check the configured view; the numeric configuration is not respected and the filter plugin loaded is entity_reference instead of the configured numeric filter

Proposed resolution

Ensure that ViewsHandlerManager respects existing configuration

Remaining tasks

Update ViewsHandlerManager to respect existing configuration
Add automated test case to verify this

User interface changes

None

API changes

None

Data model changes

None

Release notes snippet

Views configuration is no longer overridden by views data (hook_views_data + hook_views_data_alter)

πŸ› Bug report
Status

Needs review

Version

11.0 πŸ”₯

Component
ViewsΒ  β†’

Last updated about 11 hours ago

Created by

πŸ‡¬πŸ‡§United Kingdom scott_euser

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

Merge Requests

Comments & Activities

  • Issue created by @scott_euser
  • First commit to issue fork.
  • Merge request !8588Resolve #3458099 "Views handler loading" β†’ (Open) created by catch
  • Pipeline finished with Failed
    2 months ago
    Total: 171s
    #212382
  • Pipeline finished with Canceled
    2 months ago
    Total: 56s
    #212395
  • Pipeline finished with Failed
    2 months ago
    Total: 583s
    #212396
  • Pipeline finished with Failed
    2 months ago
    Total: 564s
    #212427
  • πŸ‡¬πŸ‡§United Kingdom scott_euser

    Okay a bit of progress, but that's all from me for today. I think there are some tests where its hard to tell if the test is a fail because we are truly breaking something, or because the test is trying to avoid having to fully reproduce a real-world scenario in order to keep the test small.

    An example is core/modules/views/tests/src/Kernel/Handler/FieldTimeIntervalTest.php. It appears to attempt to override the views data (rather than using the $override or changing the config) and calls some sort of advancedRender() method. I think what we should do for these type of failures is override the config rather than views data within the test method. There are probably quite a few tests that would need to be fixed in order to do that.

    So it seems the fix is probably the tip of the iceberg and the tests relying on this are going to be where the real work is here. The question is, is there a real risk we break things in contrib here that do something similar to what the tests are doing? Ie, enough to e.g. only be able to push this in D12 for example.

  • Status changed to Needs work 2 months ago
  • πŸ‡¬πŸ‡§United Kingdom scott_euser
  • πŸ‡¦πŸ‡ΊAustralia acbramley

    The question is, is there a real risk we break things in contrib here that do something similar to what the tests are doing

    I think that's definitely a concern, as well as custom sites overriding plugins in data_alter hooks without updating their config... How would we deal with that?

  • Pipeline finished with Failed
    2 months ago
    Total: 498s
    #212637
  • πŸ‡¬πŸ‡§United Kingdom scott_euser

    Okay a more realistic example is BlockExposedFilterAJAXTest::testExposedFilteringAndReset as that's a functional JS test. In that case the config used by that test is at views.view.test_block_exposed_ajax.yml which has the plugin_id for content type set to 'in_operator' and that causes the select to have Yes No instead of the list of content types. Again it could be that this is because we have created the config manually, and a real-world scenario editing the View would have saved the correct plugin ID.

    I did run our Views Reference Field test suite against this without issues and we do make a lot of modifications there.

    @catch I think we might need to defer to you whether to pursue this route further vs go back to have the two options in ✨ Continuation Add Views EntityReference filter to be available for all entity reference fields Needs work rather than trying to replace in place.

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

    In that case the config used by that test is at views.view.test_block_exposed_ajax.yml which has the plugin_id for content type set to 'in_operator' and that causes the select to have Yes No instead of the list of content types. Again it could be that this is because we have created the config manually, and a real-world scenario editing the View would have saved the correct plugin ID.

    That seems very likely to me, seems like a result of hand-editing.

    It is possible that a contrib or custom module has updated filter plugin IDs without a corresponding update to update config, but it would have to do that without the views ever having been resaved. A bit hard to tell without some real-world testing on long-established sites probably.

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

    Okay I created πŸ“Œ Make the comments in Views handler Manager around overrides clearer Needs review for the '@ this is cra...' comment (which probably we anyways should not use this specific wording). Hopefully that's a simple/quick fix.

    For the automated tests, its going to be a big job as there are tons of cases. I will try to slowly plow through them but please do expect a quite large change to views tests directory. So please do flag if you feel they need to be broken into separate issues. I think it probably makes sense to keep them here as they are best revealed by this code change in ViewsHandlerManager.

  • Pipeline finished with Failed
    2 months ago
    Total: 328s
    #213035
  • πŸ‡¬πŸ‡§United Kingdom catch

    Also opened πŸ“Œ Try to remove the override functionality from views handlers Active to try to find out how bad it is.

  • Pipeline finished with Failed
    2 months ago
    Total: 472s
    #214215
  • Pipeline finished with Failed
    2 months ago
    Total: 511s
    #214241
  • Pipeline finished with Failed
    2 months ago
    Total: 544s
    #214260
  • Pipeline finished with Failed
    2 months ago
    Total: 172s
    #214453
  • Pipeline finished with Failed
    2 months ago
    Total: 565s
    #214456
  • Pipeline finished with Failed
    2 months ago
    #214473
  • Pipeline finished with Failed
    2 months ago
    Total: 603s
    #215352
  • Pipeline finished with Canceled
    2 months ago
    Total: 373s
    #215361
  • Pipeline finished with Failed
    2 months ago
    Total: 473s
    #215364
  • Pipeline finished with Failed
    2 months ago
    Total: 170s
    #216320
  • πŸ‡¬πŸ‡§United Kingdom scott_euser

    Thanks for the feedback on the progress so far! Replied to comments, will continue to work on this

    I also added the related issues that will block this issue.

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

    See MR discussion. Uploading a modified views.view.test_serializer_display_field.yml from rest_test module and also the diff vs. 11.x

    I had to call a couple of methods from ViewTestData, install views_test_data module, edit the view, save it, export it, run the test, get config validation errors, hack out the extra keys, import it again, and that fixes the initial test failure for StyleSerializerEntityTest.php (while introducing another one which I haven't looked into yet).

    This confirms that these views exports are incredibly old and have not been maintained over time, so we are testing invalid views exports everywhere. Not really surprising but a shame this issue that's already been split from a 500+ comment two part issue is the one dealing with it.

    I think we should open another spin-off issue to discuss how we could maintain these properly over time. Config validation might help, but it doesn't solve the problem of having to manually import, save, export the views.

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

    Spun off issue here 🌱 [meta] Decide how to manage test view configuration so it remains up to date Active . Will try to get my head back into this for sorting out this particular issue.

    I guess continuing is probably better than waiting to figure out a way to automatically solve it as it is probably going to be complicated as the Views config will change depending on which other modules are enabled at the time. We could look at module/view dependencies, but as your diff shows, we cannot trust that the view config dependencies were correctly set up in the first place either.

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

    Yeah I have no idea how to solve automating this, especially with views_test_data because you can't even just install the module to get it usable, have to create state entries first, but good to have an issue open in case someone else has ideas.

  • Pipeline finished with Failed
    about 2 months ago
    Total: 153s
    #221096
  • Pipeline finished with Failed
    about 2 months ago
    Total: 162s
    #221105
  • πŸ‡³πŸ‡ΏNew Zealand quietone New Zealand

    Fixes are made on on 11.x (our main development branch) first, and are then back ported as needed according to our policies.

  • Pipeline finished with Failed
    about 2 months ago
    Total: 159s
    #228441
  • πŸ‡¬πŸ‡§United Kingdom scott_euser

    Started work on this again. As an FYI this will get blocked by πŸ› Views content language field default configuration should use field_language plugin Needs review as we will need that to get the tests here to pass I think.

  • Pipeline finished with Failed
    about 2 months ago
    Total: 573s
    #228447
  • Pipeline finished with Failed
    about 2 months ago
    Total: 160s
    #228474
  • Pipeline finished with Failed
    about 2 months ago
    Total: 532s
    #228477
  • Pipeline finished with Failed
    about 2 months ago
    Total: 456s
    #228596
  • Pipeline finished with Failed
    about 2 months ago
    Total: 469s
    #228626
  • Pipeline finished with Canceled
    about 2 months ago
    Total: 320s
    #230033
  • Pipeline finished with Failed
    about 2 months ago
    Total: 506s
    #230036
  • Pipeline finished with Canceled
    about 2 months ago
    Total: 513s
    #230046
  • Pipeline finished with Failed
    about 2 months ago
    Total: 478s
    #230048
  • Pipeline finished with Failed
    about 2 months ago
    #230065
  • Pipeline finished with Failed
    about 2 months ago
    Total: 200s
    #230760
  • Pipeline finished with Failed
    about 2 months ago
    Total: 497s
    #230852
  • Pipeline finished with Failed
    17 days ago
    Total: 617s
    #260963
  • Pipeline finished with Canceled
    17 days ago
    Total: 322s
    #260968
  • Pipeline finished with Success
    17 days ago
    Total: 512s
    #260978
  • Status changed to Needs review 17 days ago
  • πŸ‡¬πŸ‡§United Kingdom scott_euser

    Okay tests all passing now. Finally got around to fixing the views config for those two failing functional JS tests, both outdated views config.

    I wonder whether we can add a deprecation that detects when a views data/views data alter is attempting to change the plugin ID used.

    If there is a contrib module relying on views data/views data alter to provide an alternative filter plugin ID already, anyone who has exported their config should be fine as the plugin_id saved should be the altered one. They would however need to change their approach for future installs which could be for example:

    So this puts pressure on getting the latter in. If anyone has an examples of contrib modules that rely on views data/views data alter to provide a custom handler plugin would be helpful to be able to test.

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

    Note that we still have πŸ› Views content language field default configuration should use field_language plugin Needs review to get in which was flagged to do as a separate issue in the MR comments which could use a nudge back to RTBC (if agreed its ready for that)

  • πŸ‡ΊπŸ‡ΈUnited States smustgrave
  • πŸ‡¬πŸ‡§United Kingdom scott_euser

    Hmmm I can imagine there is going to be a lot more back and forth in review here. Technically yes it needs to wait but I expect this particular issue to need a fair bit longer so ideally it gets reviewed first to get the back and forth ball rolling.

Production build 0.71.5 2024