Updated: Comment #11
Problem/Motivation
When a form has a pager in it, and an element is Ajax enabled, if the form gets a validation error and/or the form is reloaded out of an Ajax request, the pager is no longer rendered in the returning form.
On validation error, and on Ajax reload, the form is reloaded from the cache, and buildForm is not executed. This leads to the pager theme to be rendered without the underlying $pager_* globals initialised, hence no pager rendered.
Proposed resolution
- Store the state of the $pager_* global variables in a FormState 'pagers_state' property when caching the form and if at least one pager is initialised.
- Restore the state of $pager_* global variables from the FormState 'pagers_state' property when getting the form from cache and the property exists.
Remaining tasks
Review patch.
User interface changes
None.
API changes
None.
| Comment | File | Size | Author |
|---|---|---|---|
| #23 | 2182555-23-test-only.patch | 5.82 KB | mondrake |
Comments
Comment #1
mondrakeThe test-only patch attached shows the issue.
Comment #2
mondrakeRelated, #1181370: Pager, tablesort links in a form corrupt when reloaded via AJAX (e.g., via exposed filter))
Comment #3
mondrakeComment #4
mondrakeTestbot failure?
Comment #6
mondrakeOK, the test fails as expected.
My understanding of why this happens: on validation error and on Ajax reload the form is reloaded from the cache, and buildForm is not executed. This leads to the pager theme to be rendered without the underlying $pager_* globals initialised, hence no pager rendered.
I have no idea on how to get around this though, nor whether there are other patches in the pipeline addressing this.
Comment #8
mondrake4: pager_form-2182555-1-test-only.patch queued for re-testing.
Comment #10
mondrakeJust checked whether #1959574: Remove the deprecated Drupal 7 Ajax API made any difference. It didn't.
Comment #11
mondrakeWell, I do not know if it's the way to go... This patch:
Note: the pager links are built with the wrong href (the path to the Ajax controller) when Ajax-reloading the form. I did not touch that here, there's already #1181370: Pager, tablesort links in a form corrupt when reloaded via AJAX (e.g., via exposed filter)) for that.
Comment #13
mondrakeLooks like #11 broke PHPunit tests. Here I moved the pack/unpack functions from pager.inc to protected methods in FormBuilder.
Comment #14
mondrake13: pager_form-2182555-13.patch queued for re-testing.
Comment #15
mondrakeReroll after #340723: Make modules and installation profiles only require .info.yml files
Comment #16
gagarine commentedComment #17
mondrakePSR-4 reroll
Comment #18
Jalandhar commentedPatch needs reroll.
Comment #19
mfernea commentedI'll do the reroll.
Comment #20
mfernea commentedHere's the reroll.
Comment #22
mfernea commentedHere is a better version of the patch. But still the modifications on FormBuilder.php done at #2182555-17: On Ajax-enabled forms with a pager, pager is disappearing on form validation error and on Ajax form reload have to merged with the modifications done on #2328777: Refactor FAPI getCache()/setCache() into a standalone class.
Comment #23
mondrakeRerolled.
Comment #25
mondrakeComment #27
mondrakeReroll of #23 after commit of #1588138: pager_query_add_page() [in D7, theme_pager_link()] overrides parameters passed programmatically.
Comment #28
mondrakeWorking on some cleanup.
Comment #29
mondrake#1588138: pager_query_add_page() [in D7, theme_pager_link()] overrides parameters passed programmatically and the patch in this issue were both introducing a pager_test module. Now #1588138: pager_query_add_page() [in D7, theme_pager_link()] overrides parameters passed programmatically was committed and the reroll in #27 would contain some duplicated code in the test module. So here I am just cleaning up the pager_test module and the pager tests.
Comment #34
mondrakeRerolled
Comment #36
mondrakeThis should fix failures - needed to change '#theme' => 'pager' to '#type' => 'pager'.
Comment #37
mondrake#2263569: Bypass form caching by default for forms using #ajax. fixed this issue by removing form caching for AJAX forms, so I am going to mark this issue fixed too.
The test only patch in #2504709-5: Prevent _wrapper_format and ajax_form parameters from bleeding through to generated URLs is an evolution of the test-only patch in #23, and demonstrates how this is no longer happening.