Problem/Motivation
Getting an error when loading in a view through ajax, if it contains fields implementing "viewsForm".
Symfony\Component\HttpKernel\Exception\HttpException: The specified #ajax callback is empty or not callable. in Drupal\Core\Form\FormAjaxResponseBuilder->buildResponse() (line 67 of core/lib/Drupal/Core/Form/FormAjaxResponseBuilder.php).
Steps to reproduce
- Install Drupal 11.x with standard profile
- Add block display to people view at /admin/structure/views/view/user_admin_people
- Enable "Use AJAX"
- Disable the page display
- Place "People" block in the Content region at /admin/structure/block
- Navigate to the front page and apply a filter to the view (e.g. Status = Active), then hit Filter
- Select any of the Actions in the view
- Press the checkbox next to the admin user in the table
- Press Apply to selected items
- 404 page displays
Proposed resolution
This is the good part. I think it is already fixed in a similar situation with exposed forms.
https://www.drupal.org/project/drupal/issues/2866386
https://www.drupal.org/project/drupal/issues/2820347
https://www.drupal.org/files/issues/2019-07-22/2820347-129.patch
In this issue the way the #action property is built has been changed. Applying this same change (with a quick patch) seems to resolve the issue.
Remaining tasks
Is there need for a Meta to make sure that all similar cases are fixed
#21 the front page you are sent back to /node instead of /.
Code review
Test only version where test fails
Comment | File | Size | Author |
---|---|---|---|
#11 | views-viewsform_incorrect_form_action-3163940-11.patch | 3.4 KB | duncancm |
Issue fork drupal-3163940
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
Comment #2
jefuri CreditAttribution: jefuri as a volunteer and at Synetic commentedComment #3
jefuri CreditAttribution: jefuri as a volunteer and at Synetic commentedImplemented the services through dependency injection. So if this is the right solution, we only need tests.
Comment #4
jefuri CreditAttribution: jefuri as a volunteer and at Synetic commentedComment #6
jefuri CreditAttribution: jefuri as a volunteer and at Synetic commentedComment #7
jefuri CreditAttribution: jefuri as a volunteer and at Synetic commentedComment #9
Lendude@jefuri :wave:
As the test failures show, this part of Views is really fragile. Yeah we want some serious test coverage for this.
Comment #10
jefuri CreditAttribution: jefuri as a volunteer and at Synetic commented@lendude :wave:
I wish a made a bet with @dsmidt, thought you would be the first one to respond haha.
But definitely, this is something to cover in tests.
Comment #11
duncancm CreditAttribution: duncancm as a volunteer commentedSimilar to the previous patch but retaining the query options.
Comment #16
richgerdesI'm still seeing this issue on Drupal 9.5. Patch from #11 did not fix the issue for me, but the patch from #5 did. Not sure why the new patch didn't work. Some investigation is needed.
My use case is a modified version of the commerce cart as well which uses ajax to update the quantities when they are changed. I'm seeing the action of the form change when the views form is replaced.
Updating the target to 11.x since that's the new standard and this code looks unchanged since the 9.5 release.
Comment #17
solideogloria CreditAttribution: solideogloria commentedNeither patch fixes the issue in every case. It's not just broken for
Viewsform
, but also forViewsExposedForm
.See #3244756: Submit broken when used with AJAX.
If I have a view with exposed filters that has a Data Export view display and a Block view display, then even if the Block display is alone on a page by itself, without the Data Export attached to it, the Apply button will still incorrectly have the URL to the data export.
When using xDebug, I stepped through the code in ViewsExposedForm.
It has:
The view does have a URL, and it returns the URL for the wrong display here, returning the Data Export URL if it has one. That happens because of this code in DisplayPluginBase:
and
getLinkDisplay()
...So despite the fact that the block is on a page with its own route, it uses the Data Export URL, which is wrong.
The views code should not assume that the first link it finds on a display will be valid for a display without a link.
However, it does reveal a workaround. I expect that adding a Page display with the correct URL and putting it right after the displays without links would make the views form have the correct URL on the form action.
Comment #20
HitchShockI want to draw attention to this issue again.
This is a fairly old issue that is still reproducible and that would be desirable to close. I personally encountered this bug on 4 projects.
To resolve the bug caused by this issue, this patch or a custom hardcode has always been used.
I am not sure how to reproduce it on a clean core, but it is a fact that it has an impact on other modules (contrib/custom) that require the correct form action when using AJAX.
This patch does not make any major changes, but only adds an additional scenario for the case when the current route is 'views.ajax'
Comment #21
mstrelan CreditAttribution: mstrelan at PreviousNext commentedAdded steps to reproduce in core. Patch works to fix this, although on the front page you are sent back to
/node
instead of/
. Needs work for test coverage.Comment #22
mstrelan CreditAttribution: mstrelan at PreviousNext commentedAdded a test and rearranged the logic a bit
Comment #23
HitchShockRTBC from my side
The patch works as expected and the new test looks good.
Many thanks to @mstrelan for providing the test and steps to reproduce
Comment #24
solideogloria CreditAttribution: solideogloria commentedViewsExposedForm
hasn't been fixed yet. See #17Comment #25
mstrelan CreditAttribution: mstrelan at PreviousNext commented@solideogloria I think that's a slightly different scenario and I think we should raise a separate issue. FWIW you can set the "Link Display" of the block display to a Custom URL (it's weirdly in the Pager part of the configuration) which would fix this issue.
Comment #26
solideogloria CreditAttribution: solideogloria commentedCreated #3396365: ViewsExposedForm has incorrect form submit URL if loaded through ajax
Comment #27
solideogloria CreditAttribution: solideogloria commentedComment #28
solideogloria CreditAttribution: solideogloria commentedComment #29
quietone CreditAttribution: quietone at PreviousNext commentedI'm triaging RTBC issues. I read the IS.
The steps to reproduce look great, although I haven't tried them and rhere are still items in the remaining tasks. The proposed resolution says this was fixed in other cases. Are there other cases that need to be checked? Do we need a meta for this work? (I have not searched to see if one exists).
I then read the change record. Instead of a statement of the bug and the error it should include actions required by the reader to make any changes needed in their core or site.
Next, I started the test only job in GitLab.
I then read the comments them and see a followup has been made for Exposed forms. However, the proposed resolution implies that exposed forms have been fixed. This goes back to my questions about maybe needing a meta to organize the work. I also do not see that anyone has reviewed the MR and there are not comments on the MR.
Back to the test job. The results show the test ran successfully when it should have failed. It also has a deprecation notice. That needs to be sorted.
I have updated the remaining tasks with the items I found. Setting to needs work.
Comment #30
acbramley CreditAttribution: acbramley at PreviousNext commentedMarked #1109980: Exposed Form Reset button Inherits the page display URL when using as a block and AJAX as a duplicate of this.
Comment #31
acbramley CreditAttribution: acbramley at PreviousNext for Service NSW commentedReplying to #29
It's just pointing out other areas where similar bugs have been fixed. I only know of this issue and the other one #3396365: ViewsExposedForm has incorrect form submit URL if loaded through ajax so far so not sure we need a meta.
I've reviewed the MR, it looks good mostly but we need some work on the new constructor params.
I don't see any failures in the gitlab pipelines, deprecations would trigger a failure? Where were you seeing it?
I've also rebased the MR.