Viewsform has incorrect form submit url if loaded through ajax

Created on 7 August 2020, over 4 years ago
Updated 7 September 2023, about 1 year ago

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

My personal situation is upon using the commerce and dc_ajax_add_cart contribs (with dc_ajax_add_cart_views submodule). To reload my cart view through ajax when a product is added to the cart.
The cart view contains (non ajax) remove buttons from the commerce module.

What happens is that the action, after replacing/inserting the cart view from the ajax response, is built like this:
/some-product-page?ajax_form=1&_wrapper_format=html
Containing the ajax_form and _wrapper_format parameters.

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 πŸ“Œ Assert the view path is set correctly after second ajax request Fixed
https://www.drupal.org/project/drupal/issues/2820347 πŸ› Exposed filter reset redirects user to 404 page on AJAX view when placed as a block Fixed
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

- Creating a new patch, while using dependency injection for the services to use. Using Drupal::service() right now in the initial patch.
- Tests

πŸ› Bug report
Status

Needs work

Version

11.0 πŸ”₯

Component
ViewsΒ  β†’

Last updated 8 minutes ago

Created by

πŸ‡³πŸ‡±Netherlands jefuri

Live updates comments and jobs are added and updated live.
  • Needs tests

    The change is currently missing an automated test that fails when run with the original code, and succeeds when the bug has been fixed.

Sign in to follow issues

Merge Requests

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024