verbb / formie

The most user-friendly forms plugin for Craft CMS.
Other
93 stars 69 forks source link

Submissions via GraphQL is missing site context #1808

Open jishi opened 2 months ago

jishi commented 2 months ago

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 commented 2 months ago

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 commented 2 months ago

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

https://github.com/verbb/formie/blob/d91b8d6c32a6ac3859b94ee7fda831a809e884fc/src/jobs/SendNotification.php#L49-L51

I would have thought that mean siteUrl would resolve correctly.

engram-design commented 2 months ago

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 commented 2 months ago

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 commented 2 months ago

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?