Problem/Motivation

If a pager is rendered within a modal, the pager links do not contain relevant ajax attributes therefore breaking out of the modal when clicked.

Steps to reproduce

  1. Create a custom route with a pager
  2. Create a route with a link to open the route in step 1 in a modal
  3. Open the modal, click a pager link
  4. Expected to see that page in the modal, but page is reloaded with ajax params rendered.

Proposed resolution

Add ajax/dialog options to pager when inside a modal.

Remaining tasks

None

User interface changes

NA

Introduced terminology

NA

API changes

NA

Data model changes

NA

Release notes snippet

NA

Issue fork drupal-3122526

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

dpi created an issue. See original summary.

dpi’s picture

Assigned: dpi » Unassigned
Status: Active » Needs review
StatusFileSize
new3.08 KB

Not sure if this is the right way to go...

Status: Needs review » Needs work

The last submitted patch, 2: 3122526-pager-modal.patch, failed testing. View results

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.

dpi’s picture

Status: Needs work » Needs review
StatusFileSize
new3.06 KB

Status: Needs review » Needs work

The last submitted patch, 5: 3122526-pager-modal-5.patch, failed testing. View results

ravi.shankar’s picture

StatusFileSize
new3.08 KB

Re-rolled patch #5 for Drupal 9.1.x.

hardik_patel_12’s picture

Assigned: Unassigned » hardik_patel_12
hardik_patel_12’s picture

Assigned: hardik_patel_12 » Unassigned
Status: Needs work » Needs review
StatusFileSize
new1.35 KB
new4.36 KB

Kindly review a new patch.

Status: Needs review » Needs work

The last submitted patch, 9: 3122526-9.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

pavnish’s picture

Assigned: Unassigned » pavnish

Working on it

pavnish’s picture

Assigned: pavnish » Unassigned
Status: Needs work » Needs review
StatusFileSize
new4.37 KB
new603 bytes

Could you please review this patch

priyanka.sahni’s picture

Assigned: Unassigned » priyanka.sahni
priyanka.sahni’s picture

StatusFileSize
new734.76 KB

Verified by applying the patch #12 , it was successfully applied but couldn't able to test the issue as getting "The service "modal_page.modals" has a dependency on a non-existent service "path.alias_manager"." on enabling the the modal_page module.

After Patch

priyanka.sahni’s picture

Assigned: priyanka.sahni » Unassigned
pavnish’s picture

Assigned: Unassigned » pavnish

Checking

pavnish’s picture

@priyanka.sahni
Could you please check after apply this patch .
https://www.drupal.org/files/issues/2020-06-09/3132535-15.patch
It's an issue with model page module and also post the patch for this .

Thanks
Pavnish

pavnish’s picture

Assigned: pavnish » Unassigned
priyanka.sahni’s picture

Assigned: Unassigned » priyanka.sahni
priyanka.sahni’s picture

StatusFileSize
new642.09 KB

@pavinsh I verified by applying the latest modal_page modules.It was applied successfully but now i am facing issue while applying the patch #12.

After Patch

pavnish’s picture

Assigned: priyanka.sahni » pavnish

@priyanka.sahni let me check

pavnish’s picture

Assigned: pavnish » Unassigned
StatusFileSize
new60.16 KB
new60.16 KB

@priyanka.sahni I thing you are not using latest 9.1.x code .I have tested on 9.1.x , the patch #12 applied successfully on latest 9.1.x

For your reference please find the screenshot.

Thanks
Pavnish

pavnish’s picture

priyanka.sahni’s picture

StatusFileSize
new356.44 KB
new198.37 KB

@Pavinsh I am using the latest 9.1.x code.Refer to the attached screenshot.

version

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.

kim.pepper’s picture

Issue tags: +#pnx-sprint
mstrelan’s picture

StatusFileSize
new4.38 KB

Reroll of #12 against 9.3.x

mstrelan’s picture

StatusFileSize
new4.18 KB

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.

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.

needs-review-queue-bot’s picture

Status: Needs review » Needs work
StatusFileSize
new144 bytes

The Needs Review Queue Bot tested this issue. It either no longer applies to Drupal core, or fails the Drupal core commit checks. Therefore, this issue status is now "Needs work".

Apart from a re-roll or rebase, this issue may need more work to address feedback in the issue or MR comments. To progress an issue, incorporate this feedback as part of the process of updating the issue. This helps other contributors to know what is outstanding.

Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.

acbramley’s picture

Title: Load pages from pager within active modal » Pager links inside a modal do not open in the modal
Issue summary: View changes

acbramley’s picture

Status: Needs work » Needs review

Rebased onto an MR and added additional tests.

smustgrave’s picture

Status: Needs review » Needs work
Issue tags: +Needs Review Queue Initiative

So using views_test_modal module from core
When I click the link (which has class use-ajax)
Modal opens
Clicking a page items renders some errors

Applying the patch

I get the same results.

Using content view with ajax turned off ( as the issue summary didn't mention turning it on)

acbramley’s picture

Issue summary: View changes
Issue tags: +Needs steps to reproduce

Looking back on when we added this patch to our site it was for a paged route outside of views. Confirmed #37 that views inside modals with pagers work as long as the view has AJAX enabled (there doesn't seem to be any automated tests around this?)

acbramley’s picture

acbramley’s picture

Issue summary: View changes
Status: Needs work » Needs review
Issue tags: -Needs steps to reproduce

Added a JS test to show the issue that fails without the fix.

acbramley’s picture

Test failure is due to the '#route_name' => '<current>', changes. This is required for the pager to work inside a modal as well. Since the test is just checking the query parameters are correct, we can just check that the href ends with the expected query.

smustgrave’s picture

Status: Needs review » Needs work

So not fully understanding this issue

When ajax is enabled on the view it works fine in a modal without a fix.

Tried testing the new route added to pager_test and I get the same error with or without the fix to theme.inc

acbramley’s picture

Status: Needs work » Needs review

Tried testing the new route added to pager_test and I get the same error with or without the fix to theme.inc

Was that in the olivero theme? Because that needs #3346136: Custom classes for pager links do not work with Olivero theme to work. The test correctly fails without the fix.

smustgrave’s picture

Status: Needs review » Reviewed & tested by the community

That was the trick. I tested with a random theme I use for work, uswds,

Using the new route you added
With the change to theme.inc not there I get an error
With the change the pagination works fine.

acbramley’s picture

Awesome, thanks for testing @smustgrave!

lauriii’s picture

Status: Reviewed & tested by the community » Needs work

Posted review on the MR

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.

acbramley’s picture

Rebased onto 11.x and changed target. There was a conflict with 10.1.x that needed resolving first. Thanks to @larowlan for helping with the git foo.

maurizio.ganovelli’s picture

Using only this condition:
\Drupal::request()->get(MainContentViewSubscriber::WRAPPER_FORMAT) === 'drupal_modal'
seems to fail in some use cases.
I have a modal form with ajax submit and tableselect element with pager. Applying this patch, pager links get ajaxified and work well until a validation error occurs. During submit, request wrapper format is "drupal_ajax", so after validation fails condition does not pass and links don't have use-ajax class and data attributes anymore.
Adding this:
in_array(\Drupal::request()->get(MainContentViewSubscriber::WRAPPER_FORMAT), ['drupal_ajax', 'drupal_modal'])
make pager work also after a failed validation, but i don't know if this can have unwanted side effects.

nicodh’s picture

Tested with Drupal 10.2.6, it works well with pager inside modal and without views. I use pager render array like this :

[
        '#type' => 'pager',
        '#route_name' => '<current>',
]

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

sakthi_dev’s picture

Rebased and resolved the conflicts.

acbramley’s picture

Status: Needs work » Needs review

Ready for another review.

smustgrave’s picture

Status: Needs review » Needs work

Left some comments in the MR.

acbramley’s picture

Status: Needs work » Needs review

Feedback addressed, I tried to find why we were using olivero and I think it was mainly to demonstrate the fix works there but I think Stark makes more sense.

smustgrave’s picture

Status: Needs review » Reviewed & tested by the community

Drupal\Tests\file\Functional\DownloadTest pretty sure unrelated.

Rest of the feedback appears to be addressed.

gaurav.kapoor’s picture

+1 RTBC, works fine when the modal has a pager.

needs-review-queue-bot’s picture

Status: Reviewed & tested by the community » Needs work
StatusFileSize
new90 bytes

The Needs Review Queue Bot tested this issue. It no longer applies to Drupal core. Therefore, this issue status is now "Needs work".

This does not mean that the patch necessarily needs to be re-rolled or the MR rebased. Read the Issue Summary, the issue tags and the latest discussion here to determine what needs to be done.

Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.

acbramley’s picture

Status: Needs work » Needs review

MR is rebased but core pipelines are having issues atm for subsystem maintainers. If someone can click rerun on the pipeline that'd be great.

smustgrave’s picture

Issue summary: View changes
Status: Needs review » Reviewed & tested by the community

Only change I wasn't sure was instantiating $link_attributes = []; vs $link_attributes = new attribute(). But seems to return the same.

Ran the test-only job here https://git.drupalcode.org/issue/drupal-3122526/-/jobs/5648445 which gave

1) Drupal\Tests\system\Unit\Pager\PreprocessPagerTest::testPagerModalAttributes
null does not match expected type "array".
/builds/issue/drupal-3122526/core/modules/system/tests/src/Unit/Pager/PreprocessPagerTest.php:218
--
1 test triggered 1 PHP warning:
1) /builds/issue/drupal-3122526/core/modules/system/tests/src/Unit/Pager/PreprocessPagerTest.php:218
Undefined array key "class"
FAILURES!
Tests: 7, Assertions: 9, Failures: 1, Warnings: 1, PHPUnit Deprecations: 7.

Appears to be 1 thread from 2 years ago but no follow up from the response. Also not sure how to do that outside the preprocess_function. Leaving thread open but don't want to hold the ticket.

Rest appears to be addressed, LGTM.

catch’s picture

Status: Reviewed & tested by the community » Needs work

Needs a rebase.

acbramley’s picture

Status: Needs work » Needs review

Rebased and squashed the MR now that everything has changed.

smustgrave’s picture

Status: Needs review » Reviewed & tested by the community

Seems like a good rebase

  • catch committed d911eaf6 on 11.x
    Issue #3122526 by acbramley, mstrelan, dpi, pavnish, smustgrave, lauriii...
catch’s picture

Status: Reviewed & tested by the community » Fixed

Opened #3537845: Move MainContentViewSubscriber::WRAPPER_FORMAT somewhere else because it felt odd seeing the event subscriber constant referenced.

Committed/pushed to 11.x, thanks!

acbramley’s picture

Agree with #65, appreciate the commit on this one. I lost count of the number of times I rebased conflicts here xD

Status: Fixed » Closed (fixed)

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

godotislate’s picture

While investigating #3567237: Mini pager and full pager behaving differently for views loaded by ajax, I think I discovered that the changes here didn't include the "Last" pager link, so I stubbed a new issue for that: #3572047: "Last" pager links inside a modal do not open in the modal.