I get an ajax error trying to fill out a webform on a view_mode_page.
Specifically with an address field on the webform.
When selecting a country, it ajax-submits to fetch the correct address fields.
That one errors out with the cryptic "An unrecoverable error occurred. The uploaded file likely exceeded the maximum file size (@size) that this server supports."
There are no file uploads whatsoever on my webform...

The webform itself works fine when using directly through webform.
It also works fine when using it placed via a block or paragraphs on a page.
It only fails when using it on a display mode rendered through view_mode_page.

I managed to debug it to view_mode_page: MainController.php: displayEntity(): line 89:
$response = $this->httpKernel->handle($sub_request, HttpKernelInterface::SUB_REQUEST);
But I'm stuck debugging this any further...

Could someone help to get this fixed?

Comments

weseze created an issue.

ricovandevin’s picture

I have boiled this down to \Drupal\Core\Routing\CurrentRouteMatch::getRouteMatch() where two route matches are registered when the <current> route is transformed. This happens when \Drupal\Core\Render\Element\RenderElement::preRenderAjaxForm() is getting the URL for $settings['url'] (if not set already). One of the route matches is for the view mode page route, the other for the canonical route of the entity. The latter is pulled from the SplObjectStorage, leading the the wrong URL in the settings. This in turn leads to the form being submitted to the wrong URL, which returns rendered HTML of the canonical instead of ajax commands.

When I replace the sub request with rendering of the entity in the given view mode the webform submit works perfectly find. But this also breaks stuff that (un)intentionally works with the sub request code. Think blocks that are displayed for the main page that are also visible for the view mode pages of the entity with the sub request approach. So I'm (also) not sure yet about an appropriate solution to this issue.