-
-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #257 from presprog/email-presets
Support `preset` parameter in email action
- Loading branch information
Showing
3 changed files
with
74 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -52,6 +52,7 @@ return function ($kirby) | |
|
||
The email action accepts the same options than the [email function of Kirby](https://getkirby.com/docs/guide/emails). You can pass on options like `cc`, `bcc` or even `attachments`. The `body` is ignored, however, as it is dynamically generated based on the form data. Here are some special options: | ||
|
||
|
||
### to (required) | ||
|
||
The email address that should be the receiver of the emails. It can be dynamically chosen based on the form content with the [EmailSelectAction](email-select). | ||
|
@@ -60,6 +61,9 @@ The email address that should be the receiver of the emails. It can be dynamical | |
|
||
The email address that will be the sender of the emails. This should be some address that is associated with the website. If you host it at `example.com` the address may be `[email protected]`. | ||
|
||
### preset | ||
The [Kirby email preset](https://getkirby.com/docs/guide/emails#email-presets) to use as a template. It works exactly like you pass in an preset to Kirbys own email function. Uniform uses the preset values as base and merges the action parameters with them. If you have `to` and `from` defined in your preset you do not have to pass them in as parameters again. | ||
|
||
### subject | ||
|
||
The subject of the email. By default the `uniform-email-subject` language variable is taken. The subject supports templates, too, so you can dynamically add form data to it. A template is a name of a form field surrounded by `{{}}`. Example: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,7 @@ | |
use Uniform\Tests\TestCase; | ||
use Uniform\Actions\EmailAction; | ||
use Uniform\Exceptions\PerformerException; | ||
use Kirby\Exception\NotFoundException; | ||
|
||
class EmailActionTest extends TestCase | ||
{ | ||
|
@@ -98,6 +99,46 @@ public function testPassthroughOptions() | |
$this->assertEquals($expect, $action->params['data']); | ||
} | ||
|
||
public function testEmailPresets() | ||
{ | ||
App::instance()->extend([ | ||
'options' => [ | ||
'email' => [ | ||
'presets' => [ | ||
'default' => [ | ||
'from' => '[email protected]', | ||
'fromName' => 'John Doe' | ||
], | ||
], | ||
], | ||
], | ||
]); | ||
|
||
$this->form->data('message', 'hello'); | ||
$action = new EmailActionStub($this->form, [ | ||
'preset' => 'default', | ||
'to' => '[email protected]', | ||
'fromName' => 'Janet Doe' | ||
]); | ||
$action->perform(); | ||
|
||
$email = $action->email; | ||
$this->assertEquals('[email protected]', $email->from()); | ||
$this->assertEquals('Janet Doe', $email->fromName()); | ||
} | ||
|
||
public function testEmailPresetNotDefined() | ||
{ | ||
$action = new EmailActionStub($this->form, [ | ||
'preset' => 'default', | ||
'to' => '[email protected]', | ||
'fromName' => 'Janet Doe' | ||
]); | ||
|
||
$this->expectException(NotFoundException::class); | ||
$action->perform(); | ||
} | ||
|
||
public function testSubjectTemplate() | ||
{ | ||
$this->form->data('email', "[email protected]"); | ||
|