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

  1. 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.
  2. 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.

Comments

mondrake’s picture

Status: Active » Needs review
StatusFileSize
new6.15 KB

The test-only patch attached shows the issue.

mondrake’s picture

StatusFileSize
new6.15 KB

Testbot failure?

Status: Needs review » Needs work

The last submitted patch, 4: pager_form-2182555-1-test-only.patch, failed testing.

mondrake’s picture

Status: Needs work » Active

OK, 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.

The last submitted patch, 1: pager_form-2182555-1-test-only.patch, failed testing.

mondrake’s picture

Status: Active » Needs review

Status: Needs review » Needs work

The last submitted patch, 4: pager_form-2182555-1-test-only.patch, failed testing.

mondrake’s picture

Status: Needs work » Active

Just checked whether #1959574: Remove the deprecated Drupal 7 Ajax API made any difference. It didn't.

mondrake’s picture

Issue summary: View changes
Status: Active » Needs review
StatusFileSize
new9.02 KB

Well, I do not know if it's the way to go... This patch:

  1. Stores the state of the $pager_* global variables in a $form_state['pagers_state'] entry when caching the form and if at least one pager is initialised.
  2. Restores the state of $pager_* global variables from the $form_state['pagers_state'] cache entry when getting the form from cache and the entry exists.

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.

Status: Needs review » Needs work

The last submitted patch, 11: pager_form-2182555-11.patch, failed testing.

mondrake’s picture

Status: Needs work » Needs review
StatusFileSize
new4.17 KB
new8.81 KB

Looks like #11 broke PHPunit tests. Here I moved the pack/unpack functions from pager.inc to protected methods in FormBuilder.

mondrake’s picture

13: pager_form-2182555-13.patch queued for re-testing.

mondrake’s picture

StatusFileSize
new8.47 KB
new859 bytes
gagarine’s picture

mondrake’s picture

StatusFileSize
new8.35 KB

PSR-4 reroll

Jalandhar’s picture

Status: Needs review » Needs work
Issue tags: +Needs reroll

Patch needs reroll.

mfernea’s picture

Issue tags: +Amsterdam2014

I'll do the reroll.

mfernea’s picture

Status: Needs work » Needs review
Issue tags: -Needs reroll
StatusFileSize
new7.35 KB

Here's the reroll.

Status: Needs review » Needs work

The last submitted patch, 20: drupal-pager-ajax-forms-2182555-20.patch, failed testing.

mfernea’s picture

StatusFileSize
new7.35 KB

Here 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.

mondrake’s picture

Issue summary: View changes
Status: Needs work » Needs review
StatusFileSize
new8.52 KB
new5.82 KB

Rerolled.

Status: Needs review » Needs work

The last submitted patch, 23: 2182555-23-test-only.patch, failed testing.

mondrake’s picture

Status: Needs work » Needs review

The last submitted patch, 22: on_ajax_enabled_forms-2182555-22.patch, failed testing.

mondrake’s picture

Assigned: Unassigned » mondrake
StatusFileSize
new7.87 KB
mondrake’s picture

Status: Needs review » Needs work

Working on some cleanup.

mondrake’s picture

Assigned: mondrake » Unassigned
Status: Needs work » Needs review
StatusFileSize
new7.51 KB
new10.69 KB

#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.

Status: Needs review » Needs work

The last submitted patch, 29: 2182555-29.patch, failed testing.

Status: Needs work » Needs review

mondrake queued 29: 2182555-29.patch for re-testing.

mondrake queued 29: 2182555-29.patch for re-testing.

Status: Needs review » Needs work

The last submitted patch, 29: 2182555-29.patch, failed testing.

mondrake’s picture

Status: Needs work » Needs review
StatusFileSize
new10.74 KB

Rerolled

Status: Needs review » Needs work

The last submitted patch, 34: 2182555-34.patch, failed testing.

mondrake’s picture

Status: Needs work » Needs review
StatusFileSize
new612 bytes
new10.74 KB

This should fix failures - needed to change '#theme' => 'pager' to '#type' => 'pager'.

mondrake’s picture

Status: Needs review » Fixed
Related issues: +#2263569: Bypass form caching by default for forms using #ajax.

#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.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.