1
0
Fork 0
mirror of synced 2024-10-01 17:58:02 +13:00

support maile template override

This commit is contained in:
Damodar Lohani 2023-12-06 14:52:13 +01:00 committed by GitHub
parent f16aa598e2
commit 83d4de9f73
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 29 additions and 4 deletions

View file

@ -13,6 +13,7 @@ class Mail extends Event
protected string $body = '';
protected array $smtp = [];
protected array $variables = [];
protected string $bodyTemplate = '';
public function __construct(protected Connection $connection)
{
@ -115,6 +116,29 @@ class Mail extends Event
return $this->name;
}
/**
* Sets bodyTemplate for the mail event.
*
* @param string $bodyTemplate
* @return self
*/
public function setbodyTemplate(string $bodyTemplate): self
{
$this->bodyTemplate = $bodyTemplate;
return $this;
}
/**
* Returns subject for the mail event.
*
* @return string
*/
public function getbodyTemplate(): string
{
return $this->bodyTemplate;
}
/**
* Set SMTP Host
*
@ -327,10 +351,11 @@ class Mail extends Event
'recipient' => $this->recipient,
'name' => $this->name,
'subject' => $this->subject,
'bodyTemplate' => $this->bodyTemplate,
'body' => $this->body,
'smtp' => $this->smtp,
'variables' => $this->variables,
'events' => Event::generateEvents($this->getEvent(), $this->getParams())
]);
}
}
}

View file

@ -59,8 +59,8 @@ class Mails extends Action
$variables = $payload['variables'];
$name = $payload['name'];
$body = $payload['body'];
$bodyTemplate = Template::fromFile(__DIR__ . '/../../../../app/config/locale/templates/email-base.tpl');
$bodyTemplate = $payload['bodyTemplate'] ?? __DIR__ . '/../../../../app/config/locale/templates/email-base.tpl';
$bodyTemplate = Template::fromFile($bodyTemplate);
$bodyTemplate->setParam('{{body}}', $body);
foreach ($variables as $key => $value) {
$bodyTemplate->setParam('{{' . $key . '}}', $value);
@ -131,4 +131,4 @@ class Mails extends Action
return $mail;
}
}
}