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

Add a placeholder for a link to the submission in the Control Panel #2220

Closed
MoritzLost opened this issue Jan 9, 2025 · 5 comments
Closed
Milestone

Comments

@MoritzLost
Copy link
Contributor

MoritzLost commented Jan 9, 2025

What are you trying to do?

We want to include a link to the submission in an email notification. There's a placeholder with that URL available:

Screenshot 2025-01-09 at 14 27 14

However, that only outputs the URL as plain text:

Screenshot 2025-01-09 at 14 28 44

That's inconvenient because you have to select the URL and copy-and-paste it into a new browser tab, instead of just clicking on a link.

What's your proposed solution?

Add a new placeholder Submission CP link that outputs a link. The link should have the Submission CP URL as its href, and the submission title as the link text, or just the URL as the link text so it's clickable.

Ideally, the link text would be configurable, though I'm not sure if that is possible with those placeholders. Alternatively, the rich text editor that already has buttons for bold and italic text could be extended to provide a link button, where you can use a placeholder as the href and write a custom link text.

Additional context

No response

@engram-design
Copy link
Member

We've got plans to expand the functionality of these placeholders/variables that will likely allow for this sort of advanced behaviour.

@engram-design engram-design added this to the 2.3.0 milestone Jan 9, 2025
@MoritzLost
Copy link
Contributor Author

@engram-design That looks really promising! Any idea when those changes might be implemented? We have a signup form where a link to the submission would be really helpful, and I couldn't find a good workaround yet.

@engram-design
Copy link
Member

Not until later this year I'm afraid in 2.3.0.

So I suppose this depends on your email client as well. For example, my Mac Mail seems to render the link as HTML.

But in any case, I've added handling for you to register your own variables. They were half-done, but didn't feature a way to handle parsing logic.

use craft\helpers\Html;
use craft\helpers\Template;

use verbb\formie\events\RegisterVariablesEvent;
use verbb\formie\events\ParseVariablesEvent;
use verbb\formie\helpers\Variables;

use yii\base\Event;

Event::on(Variables::class, Variables::EVENT_REGISTER_VARIABLES, function(RegisterVariablesEvent $event) {
    $event->variables['custom'][] = [
        'label' => 'Custom',
        'heading' => true,
    ];

    $event->variables['custom'][] = [
        'label' => 'Submission URL HTML',
        'value' => '{submissionUrlHtml}',
    ];
});


Event::on(Variables::class, Variables::EVENT_PARSE_VARIABLES, function(ParseVariablesEvent $event) {
    if ($event->submission) {
        $event->variables['submissionUrlHtml'] = Template::raw(Html::tag('a', $event->submission->title, ['href' => $event->submission->cpEditUrl]));
    }
});

Which will give you a new option in the variable picker, and output the raw HTML to the cpEditUrl to the submission.

To get this early, run composer require verbb/formie:"dev-craft-4 as 2.1.37".

@MoritzLost
Copy link
Contributor Author

@engram-design Got it, thanks!

So I suppose this depends on your email client as well. For example, my Mac Mail seems to render the link as HTML.

Interesting – since it's already an HTML mail, that's probably some kind of link detection algorithm? I'll check what my clients use in this case.

But in any case, I've added handling for you to register your own variables. They were half-done, but didn't feature a way to handle parsing logic.

Thank you for the addition and the example, that's great! We'll use that to implement the link 💯

@engram-design
Copy link
Member

Updated in 2.1.39

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

2 participants