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

Submissions via GraphQL is missing site context #1808

Open
jishi opened this issue Apr 5, 2024 · 5 comments
Open

Submissions via GraphQL is missing site context #1808

jishi opened this issue Apr 5, 2024 · 5 comments

Comments

@jishi
Copy link

jishi commented Apr 5, 2024

Describe the bug

I'm trying to adjust an email notifications for submissions that comes via GrahpQL.

For some reason, the linking context is off. the global siteUrl isn't set, and it seems like it doesn't understand under which site context it has been submitted. I tried adding siteId to the graphQL submission, but that doesn't make a difference.

I'm trying to link to the public facing website for links and images, and I have an entry submission that also links wrong (or rather, some weird relative linking).

I'm not sure if I'm using it wrong or if it is a bug. The same variables are linking correctly on forms that are submitted normally (not via GraphQL).

Steps to reproduce

  1. Try to add a link to home page in the email template (like {{ siteUrl }}
  2. Submit form via GraphQL
  3. Check resulting email, which links to @web/

Form settings

Submission via GraphQL

Craft CMS version

4.8.0

Plugin version

2.1.5

Multi-site?

No

Additional context

No response

@jishi
Copy link
Author

jishi commented Apr 5, 2024

I actually think this is mostly broken alias resolution, not even doing {{ craft.app.sites.primarySite.baseUrl }} gives me the proper url, only @web/

@engram-design
Copy link
Member

engram-design commented Apr 5, 2024

So within the queue job itself that sends out the email notifications, we set the current site based on the site of the submission

Craft::$app->language = $submission->getSite()->language;
Craft::$app->set('locale', Craft::$app->getI18n()->getLocaleById($submission->getSite()->language));
Craft::$app->getSites()->setCurrentSite($submission->getSite());

I would have thought that mean siteUrl would resolve correctly.

@engram-design
Copy link
Member

engram-design commented Apr 5, 2024

Just a quick test on my end, and they seem to be resolving correctly for me:

primarySite: {{ craft.app.sites.primarySite.baseUrl }}
siteUrl: {{ siteUrl }}
currentSite: {{ craft.app.sites.currentSite.baseUrl }}

primarySite: https://formie.test/
siteUrl: https://formie.test/
currentSite: https://formie.test/

Just using a simple mutation:

mutation saveSubmission {
    save_contactForm_Submission(siteId:2) {
        title
    }
}

I assume you have an Email Template setup, and your adding it to the Twig template, and not just the "Email Content" setting for the notification?

@jishi
Copy link
Author

jishi commented Apr 9, 2024

I'm confused now, I'm trying something different for another site I'm developing, and I have an Entry field (drop down) in my form. I'm trying to create an email notification for it but I'm seeing similar odd behavior. This is not submitted via GraphQL, so the GraphQL might be a red herring.

Firstly, I didn't have @web set for this site, so the link to the entry in the email became relative. Adding the @web alias, I get an absolut url at least, but the link also points to the admin page which is not my intention. But firstly, I don't actually use @web in the baseurl, I use a different alias that was indeed set, so seems like the link building doesn't actually work as intended. But I can't control how the email template links to the entry, unless I override the email template rendering of entry fields. Is the intention that it always links to the admin url of an entry?

@engram-design
Copy link
Member

I will say elements linking to their admin cpEditUrl rather than their front-end URL is something we've addressed in Formie 3 for Craft 5 as at the moment, you can't pick which to use.

So the cpEditUrl (the URL for the admin control panel to edit an entry) is set by the section settings - there's nothing special Formie does to change that, so it seems incredibly odd that's not resolving correctly. That's relative to your primary site settings.

What's your site settings look like?

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

No branches or pull requests

2 participants