Built‐in Actions - comhon-project/custom-action GitHub Wiki

Built-in Actions

The custom action library come with some built-in actions.

AbstractSendEmail

Actually, AbstractSendEmail is not directly usable (since it’s abstract), but it serves as a useful skeleton for building actions that send emails. When extending from this class, you just need to implement functions to define the sender, recipients, subject, body, and attachments. You don’t need to implement the rest :

  • settings selection (default setting or scoped setting)
  • localized settings selection (according recipient preferred locale)
  • variable substitution according context in the subject and in the body (using twig by default)
  • and the actual email sending.

When extending AbstractSendEmail, to expose the context, instead of implementing getContextSchema, You must implements getCommonContextSchema.

AbstractSendManualEmail

Actually, AbstractSendManualEmail is not directly usable (since it’s abstract), but it serves as a useful skeleton for building very generic manual actions that send emails. When extending from this class, you just need to define the context. You don’t need to implement the rest. It is fully customizable through the Customization API. To expose the context, instead of implementing getContextSchema, You must implements getCommonContextSchema.

When extending from this class, you can generate a preview of the email body by using the function preview:

$preview = (new SendUserRegisteredEmail($user))->preview();

And you can override email settings to inject exactly what you want in the email. You just have to define from, subject, body in your class as public or protected attributes and set them if you want (typically inside your constructor).

$from = '[email protected]';
$subject = 'overridden subject';
$body = 'overridden body';
SendUserRegisteredEmail::dispatch($user, $from, $subject, $body);

Preview generation and settings overriding allow you to fine-tune each email before sending.

Note: If you use your own Model Resolver, make sure following classes are registered :

  • stored-file => StoredFileInterface::class
  • mailable-entity => MailableEntityInterface::class

SendAutomaticEmail

SendAutomaticEmail is a very generic action that should be triggered from events to send email. It is fully customizable through the Customization API.

Note: If you use your own Model Resolver, make sure following classes are registered :

  • stored-file => StoredFileInterface::class
  • mailable-entity => MailableEntityInterface::class

QueueAutomaticEmail

QueueAutomaticEmail is the same action as SendAutomaticEmail except that the action is dispatched via queues.