Ajax issue on multilingual sites

Created on 13 January 2025, 18 days ago

Problem/Motivation

When using the kontainer entity reference or media library widgets to select an image on a multilingual site, the following error appears: "Oops, something went wrong. Check your browser's developer console for more details".

The JS console error shows:

An AJAX HTTP error occurred.

HTTP Result Code: 200 Debugging information follows. Path: /en/kontainer/create-media?token=mytoken StatusText: success CustomMessage: The response failed verification so will not be processed. ResponseText: {"media_id":"1","media_label":"my-image.jpg","kontainer_file_id":1}"

This points to the drupalSettings.ajaxTrustedUrl object that does not contain the expected path.
It actually contains /kontainer/create-media?token=mytoken, but the request path on a multilingual site is /en/kontainer/create-media?token=mytoken.

Proposed resolution

Instead of getting the language independent path from routeProvider, construct it using a drupal Url object, which will automatically handle multilingual paths.

I'll attach a merge request to fix this for both entity reference & media library widgets.

🐛 Bug report
Status

Active

Version

1.1

Component

Code

Created by

🇧🇪Belgium robindh

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

Production build 0.71.5 2024