statamic / cms

The core Laravel CMS Composer package
https://statamic.com
Other
3.68k stars 506 forks source link

Bard fieldtype: Linked entries in Bard field resolves to wrong locale of the entry (GraphQL and RESTful API) #9424

Open motion-work opened 7 months ago

motion-work commented 7 months ago

Bug description

I have a Statamic instance configured with multisite (German, French, and Italian). The default root locale is set to German. Also I am fetching the CMS data via the GraphQL endpoint. the same bug applies for the REST api as well.

Within a bard field, when I link to an entry of the same locale - for example, French entry to another French entry, I expect the linked entry to resolve to the French URL /fr/first-page -> /fr/second-page, but it currently does not.

How to reproduce

Current behavior

French linked entry within Bard field resolves to German url of the linked entry. for example:

/fr/french-page-a -> /de/german-page-a

it resolves to the correct entry but in the wrong locale

Expected behavior

/fr/french-page-a -> /fr/french-page-a

Screenshot 2024-01-31 at 11 21 07

Logs

No response

Environment

Environment
Laravel Version: 9.52.16
PHP Version: 8.2.13
Composer Version: 2.5.5
Environment: local
Debug Mode: ENABLED
URL: app.url
Maintenance Mode: OFF

Cache
Config: NOT CACHED
Events: NOT CACHED
Routes: NOT CACHED
Views: CACHED

Drivers
Broadcasting: log
Cache: redis
Database: mysql
Logs: stack / daily, sentry
Mail: smtp
Queue: sync
Session: redis

Sentry
Enabled: MISSING DSN
Environment: local
Laravel SDK Version: 3.8.2
PHP SDK Version: 3.22.1
Release: e6c02a7f0
Sample Rate Errors: 100%
Sample Rate Performance Monitoring: 100%
Sample Rate Profiling: NOT SET
Send Default PII: ENABLED

Statamic
Addons: 4
Antlers: regex
Stache Watcher: Enabled
Static Caching: Disabled
Version: 4.46.0 PRO

Installation

Fresh statamic/statamic site via CLI

Antlers Parser

None

Additional details

I have found this merged issue which seems to fix this similar bug but not for the GraphQL and REST api: https://github.com/statamic/cms/pull/8319

motion-work commented 6 months ago

any updates on this? 😬

jasonvarga commented 6 months ago

No updates yet sorry. You'd see them here if there were.

motion-work commented 6 months ago

alrighty thanks for the reply

jasonvarga commented 6 months ago

I'm not able to fix it right now, but this is a note for us or whoever wants to tackle this:

The issue is here: https://github.com/statamic/cms/blob/1f08790aa9b53325c1f4a4bd4ee91507b95362ad/src/Fieldtypes/Bard/LinkMark.php#L69

It's localizing to the current site, which works great on the frontend but not in the APIs. Instead of Site::current(), it should somehow get the site of the parent entry (the one where the bard field is). Accessing that from within the LinkMark class might be challenging.