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
- Create a custom route with a pager
- Create a route with a link to open the route in step 1 in a modal
- Open the modal, click a pager link
- 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
| Comment | File | Size | Author |
|---|
Issue fork drupal-3122526
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:
- 3122526-pager-links-inside
changes, plain diff MR !3558
Comments
Comment #2
dpiNot sure if this is the right way to go...
Comment #5
dpiReroll since pager.inc removed #2044435: Convert pager.inc to a service + #3087517: Remove BC layer for Pager service
Comment #7
ravi.shankar commentedRe-rolled patch #5 for Drupal 9.1.x.
Comment #8
hardik_patel_12 commentedComment #9
hardik_patel_12 commentedKindly review a new patch.
Comment #11
pavnish commentedWorking on it
Comment #12
pavnish commentedCould you please review this patch
Comment #13
priyanka.sahni commentedComment #14
priyanka.sahni commentedVerified 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.
Comment #15
priyanka.sahni commentedComment #16
pavnish commentedChecking
Comment #17
pavnish commented@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
Comment #18
pavnish commentedComment #19
priyanka.sahni commentedComment #20
priyanka.sahni commented@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.
Comment #21
pavnish commented@priyanka.sahni let me check
Comment #22
pavnish commented@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
Comment #23
pavnish commentedComment #24
priyanka.sahni commented@Pavinsh I am using the latest 9.1.x code.Refer to the attached screenshot.
Comment #27
kim.pepperComment #28
mstrelan commentedReroll of #12 against 9.3.x
Comment #29
mstrelan commentedComment #33
needs-review-queue-bot commentedThe 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.
Comment #34
acbramley commentedComment #36
acbramley commentedRebased onto an MR and added additional tests.
Comment #37
smustgrave commentedSo 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)
Comment #38
acbramley commentedLooking 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?)
Comment #39
acbramley commentedLooks like testing this is also affected by #3123666: Custom classes for pager links do not work with Claro theme which also affects Olivero. Opened #3346136: Custom classes for pager links do not work with Olivero theme for that.
Comment #40
acbramley commentedAdded a JS test to show the issue that fails without the fix.
Comment #41
acbramley commentedTest 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.Comment #42
smustgrave commentedSo 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
Comment #43
acbramley commentedWas 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.
Comment #44
smustgrave commentedThat 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.
Comment #45
acbramley commentedAwesome, thanks for testing @smustgrave!
Comment #46
lauriiiPosted review on the MR
Comment #48
acbramley commentedRebased 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.
Comment #49
maurizio.ganovelliUsing 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.
Comment #50
nicodh commentedTested with Drupal 10.2.6, it works well with pager inside modal and without views. I use pager render array like this :
Comment #52
sakthi_dev commentedRebased and resolved the conflicts.
Comment #53
acbramley commentedReady for another review.
Comment #54
smustgrave commentedLeft some comments in the MR.
Comment #55
acbramley commentedFeedback 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.
Comment #56
smustgrave commentedDrupal\Tests\file\Functional\DownloadTest pretty sure unrelated.
Rest of the feedback appears to be addressed.
Comment #57
gaurav.kapoor commented+1 RTBC, works fine when the modal has a pager.
Comment #58
needs-review-queue-bot commentedThe 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.
Comment #59
acbramley commentedMR is rebased but core pipelines are having issues atm for subsystem maintainers. If someone can click rerun on the pipeline that'd be great.
Comment #60
smustgrave commentedOnly 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
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.
Comment #61
catchNeeds a rebase.
Comment #62
acbramley commentedRebased and squashed the MR now that everything has changed.
Comment #63
smustgrave commentedSeems like a good rebase
Comment #65
catchOpened #3537845: Move MainContentViewSubscriber::WRAPPER_FORMAT somewhere else because it felt odd seeing the event subscriber constant referenced.
Committed/pushed to 11.x, thanks!
Comment #67
acbramley commentedAgree with #65, appreciate the commit on this one. I lost count of the number of times I rebased conflicts here xD
Comment #69
godotislateWhile 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.