Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
motion-work opened this issue Jan 31, 2024 · 7 comments

Comments

@motion-work
Copy link

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: #8319

@motion-work
Copy link
Author

any updates on this? 😬

@jasonvarga
Copy link
Member

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

@motion-work
Copy link
Author

alrighty thanks for the reply

@jasonvarga
Copy link
Member

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:

return ($item->in(Site::current()->handle()) ?? $item)->url();

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.

@arcs-
Copy link
Contributor

arcs- commented Sep 17, 2024

In my project I "fixed" this by injecting a middleware into the Statamic GraphQL queries

class ResolveSite extends Middleware
{
    public function handle($root, array $args, $context, ResolveInfo $info, Closure $next)
    {
        $site = $args['site'] ?? Site::default()->handle();
        Site::setCurrent($site);

        return $next($root, $args, $context, $info);
    }
}

This solution isn't that nice because of it being a side-effect in a query, however it does work quite well even with fetching multiple sites, and doesn't require refactoring all the Site::current() occurrences.

@G-Nat
Copy link

G-Nat commented Nov 13, 2024

Currently facing same issue with REST API 😞

@duncanmcclean
Copy link
Member

Closing as I believe this has been fixed in #11207, which will be part of the next release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants