Problem/Motivation

In the process of triaging issue #2823541: Table clicksort is lost when using views exposed filter & Pager exposed '#items' @xjm and I encountered another problem relating to the views exposed block form where the options and/or widgets displayed on the exposed block were not immediately visible on the view page after changing the configuration of the view itself.

Steps to reproduce

  1. Add some content into a default new standard profile 8.4.x HEAD D8 site
  2. Create a page view (with URL /sortmissing), add exposed filters for sorting criteria (eg. content type for filter and authored on, authored by, for sort criteria)
  3. Add a full pager with exposed option "Allow user to control the number of items displayed in this view"
  4. Under Advanced config of the view, select Yes for Exposed Form, choosing Basic form type
  5. Under Structure - Block Layout - Place Block choose the newly created exposed form and place it in a region (eg. Sidebar)
  6. Go the view page (/sortmissing), notice which options and widgets are shown
  7. Change the view and add another option into an existing filter (eg. add Title to the Sort Criteria so that you have three options: authored on, authored by and title as options there)
  8. Switch back to view page and just refresh the page or click Apply on the exposed block form to refresh the display - the resulting page does not show the newly added option

Based on how unpredictable the display of the exposed block options happens as it eventually refreshes after a few attempts clicking on the page and the various options (usually after 3-4 refreshes of changing the chosen filtering options things seem to update), this would possibly be related to caching and how the cache is being invalidated on the exposed filters block for the view.

Attached with the issue is the export of the view I've used to arrive at the issue.

- - - - - - - - - - - - - -

This issue emerged from #2823541: Table clicksort is lost when using views exposed filter & Pager exposed '#items' and the following folks deserve credit:
@anneeasterling = #2823541-9: Table clicksort is lost when using views exposed filter & Pager exposed '#items'
@krknth = #2823541-10: Table clicksort is lost when using views exposed filter & Pager exposed '#items'

Proposed resolution

Override getCacheTags method and pass relevant cache tags.

  public function getCacheTags(): array {
    $tags = parent::getCacheTags();
    // Add the tag for the View this block belongs to.
    return Cache::mergeTags($tags, ['config:views.view.' . $this->view->id()]);
  }

Remaining tasks

Needs review

User interface changes

N/A

API changes

N/A

Data model changes

N/A

Issue fork drupal-2887144

Command icon 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:

Comments

samirjusic created an issue. See original summary.

samirjusic’s picture

I searched through the existing views issues list for 8.4.x, but could not find an existing bug reported so I'm raising the new one here.

stpaultim’s picture

Working on Major Issues Triage at Twin Cities Drupal Camp with @mathuaerknedam (mentored by @YesCT)

This issue appears to have emerged from #2823541: Table clicksort is lost when using views exposed filter & Pager exposed '#items' and the following folks deserve credit:
@anneeasterling = #2823541-9: Table clicksort is lost when using views exposed filter & Pager exposed '#items'
@krknth = #2823541-10: Table clicksort is lost when using views exposed filter & Pager exposed '#items'

stpaultim’s picture

Issue summary: View changes
Issue tags: +TCDrupal 2017
stpaultim’s picture

Issue summary: View changes
Anonymous’s picture

xjm’s picture

Added credit for anneeasterling who originally identified this issue. krknth reproduced the other issue but did not identify this one, so they'll receive credit for the other. Thanks @StPaulTim!

micbar’s picture

I have an exposed filters form on a block which contains a list of taxonomy terms. If I add a new term to the vocabulary, the exposed filters form does not get updated. Digging into the block object shows only one cache context "languages:language_interface" and no cache tags. Is that use case (taxonomy terms in exposed filters form) not working by default and needs some tweaking or is it a bug in the views module?

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.0-alpha1 will be released the week of July 31, 2017, which means new developments and disruptive changes should now be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

lendude’s picture

Issue summary: View changes
Status: Active » Needs review
Issue tags: +Needs tests
StatusFileSize
new782 bytes

@micbar that sounds like #2900248: Exposed term filter is not updated when terms are added, deleted, or rearranged (caching issue?), not sort criteria which this issue is talking about.

I can reproduce this issue, but took me a while to see that the essential point here is that it is about the 'Exposed form in block:Yes' block.

Fix in the patch fixes it for me when manually testing, but this obviously still needs tests.

And is there any way to get the tag 'config:views.view.' . $this->view->id() from the View and not have to build it yourself? Couldn't find anything.

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.0-alpha1 will be released the week of January 17, 2018, which means new developments and disruptive changes should now be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

borisson_’s picture

Status: Needs review » Needs work

And is there any way to get the tag 'config:views.view.' . $this->view->id() from the View and not have to build it yourself? Couldn't find anything.

I don't see a better way to do this.

Setting to needs work to add the needed tests.

Version: 8.6.x-dev » 8.7.x-dev

Drupal 8.6.0-alpha1 will be released the week of July 16, 2018, which means new developments and disruptive changes should now be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.7.x-dev » 8.8.x-dev

Drupal 8.7.0-alpha1 will be released the week of March 11, 2019, which means new developments and disruptive changes should now be targeted against the 8.8.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.0-alpha1 will be released the week of October 14th, 2019, which means new developments and disruptive changes should now be targeted against the 8.9.x-dev branch. (Any changes to 8.9.x will also be committed to 9.0.x in preparation for Drupal 9’s release, but some changes like significant feature additions will be deferred to 9.1.x.). For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.9.x-dev » 9.1.x-dev

Drupal 8.9.0-beta1 was released on March 20, 2020. 8.9.x is the final, long-term support (LTS) minor release of Drupal 8, which means new developments and disruptive changes should now be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 9.1.x-dev » 9.2.x-dev

Drupal 9.1.0-alpha1 will be released the week of October 19, 2020, which means new developments and disruptive changes should now be targeted for the 9.2.x-dev branch. For more information see the Drupal 9 minor version schedule and the Allowed changes during the Drupal 9 release cycle.

Version: 9.2.x-dev » 9.3.x-dev

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

larowlan’s picture

karishmaamin’s picture

Status: Needs work » Needs review
StatusFileSize
new706 bytes

Re-rolled patch against 9.4.x. Please review

yogeshmpawar’s picture

Issue tags: -Needs reroll
kumudb’s picture

StatusFileSize
new658 bytes

Adding against 9.4.x

kumudb’s picture

StatusFileSize
new3.67 KB

Patch against failed previous path.

kumudb’s picture

StatusFileSize
new838 bytes

Comments against #23

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.5.x-dev » 10.1.x-dev

Drupal 9.5.0-beta2 and Drupal 10.0.0-beta2 were released on September 29, 2022, which means new developments and disruptive changes should now be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

smustgrave’s picture

This issue is being reviewed by the kind folks in Slack, #needs-review-queue-initiative. We are working to keep the size of Needs Review queue [2700+ issues] to around 400 (1 month or less), following Review a patch or merge request as a guide.

For the tests requested in #10.

Also the issue summary could use an update as it references D10 a lot.

smustgrave’s picture

Status: Needs review » Needs work
mohit_aghera’s picture

Issue summary: View changes
Status: Needs work » Needs review
Issue tags: -Needs tests, -Needs issue summary update
StatusFileSize
new4.67 KB
new4.77 KB
new3.99 KB

- Added a test-only patch and test cases for the issue.
- Patches #23 #24 and #25 are completely wrong and without any direction.
- Interdiff is taken against patch #21
- Updated issue summary as well.

Status: Needs review » Needs work

The last submitted patch, 30: test-only-2887144-30.patch, failed testing. View results

mohit_aghera’s picture

Status: Needs work » Needs review
smustgrave’s picture

Status: Needs review » Reviewed & tested by the community

Issue summary looks good.

Tests-only patch in #30 shows the failure I think perfectly, good job @mohit_aghera!

Applied cleanly and everything appears to function as normal.

The last submitted patch, 30: 2887144-30.patch, failed testing. View results

borisson_’s picture

Status: Reviewed & tested by the community » Needs work

Looks like the latest patch fails.

mohit_aghera’s picture

Status: Needs work » Needs review

Triggering the test bot again for patches in #30.
Failures are in CkEditor5\FunctionalJavascript\MediaTest

The last submitted patch, 30: 2887144-30.patch, failed testing. View results

mohit_aghera’s picture

Status: Needs review » Needs work

Version: 10.1.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch, which currently accepts only minor-version allowed changes. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

mxr576 made their first commit to this issue’s fork.

mxr576’s picture

let's start with a clean up

mxr576’s picture

mxr576’s picture

The failing test confirms that even with #3493858: Extend ViewsBlockBase to merge cache metadata from display handler merged into Drupal core, this issue still persists. The cacheability metadata from the View config entity is still not bubbling up to the block, so the underlying problem remains unresolved.

Relying on View::getCacheTags() should be a better solution instead of a hand-crafted config cache id, since \Drupal\views\Entity\View::addCacheMetadata() ensures that before a View config is changed display plugin's cacheability information is also incorporated into the stored cache tags.

Question: What about cache contexts and cache max age bubble up from the View entity?

The merge request is currently failing due to the test coverage introduced in #3493858: Extend ViewsBlockBase to merge cache metadata from display handler, which added significant amounts of mocking. Somebody has to fix those, because I tried and failed miserably due to interconnected dependencies and protected properties... (This is one of the main reasons I try to avoid overusing mocks in my own projects - they tend to make the test suite fragile and harder to maintain. </personal_opinion>)

(There may also be a related issue in the contrib space: #3523416: Filter configuration changes does not propagate immeditelly to BEF in a block.)

xjm’s picture

Amending attribution.

Version: 11.x-dev » main

Drupal core is now using the main branch as the primary development branch. New developments and disruptive changes should now be targeted to the main branch.

Read more in the announcement.