You've already forked grav-plugin-listmonk
added transactional email handling
This commit is contained in:
49
listmonk.php
49
listmonk.php
@@ -3,6 +3,7 @@ namespace Grav\Plugin;
|
||||
|
||||
use AdnanHussainTurki\ListMonk\ListMonk;
|
||||
use AdnanHussainTurki\ListMonk\Models\MonkSubscriber;
|
||||
use AdnanHussainTurki\ListMonk\Models\TransactionalEmail;
|
||||
use Composer\Autoload\ClassLoader;
|
||||
use Grav\Common\Data\Data;
|
||||
use Grav\Common\Plugin;
|
||||
@@ -109,7 +110,7 @@ class ListmonkPlugin extends Plugin
|
||||
'source' => 'gravcms',
|
||||
]));
|
||||
|
||||
$this->grav->fireEvent('onListmonkSubscriberObjectCreated', new Event([
|
||||
$this->grav->fireEvent('onListmonkSubscriberInitialized', new Event([
|
||||
'subscriber' => $subscriber,
|
||||
]));
|
||||
|
||||
@@ -131,28 +132,42 @@ class ListmonkPlugin extends Plugin
|
||||
/**
|
||||
* Send a transactional mail using listmonk
|
||||
*
|
||||
* (Not implemented yet!)
|
||||
*
|
||||
* @param Event $event
|
||||
* @return void
|
||||
*/
|
||||
private function processTransactionalForm(Event $event, Form $form, array $params): void
|
||||
{
|
||||
$this->grav->fireEvent('onFormValidationError', new Event([
|
||||
'form' => $form,
|
||||
'message' => 'Sending transactional emails is not implemented yet',
|
||||
]));
|
||||
try {
|
||||
$txEmail = new TransactionalEmail();
|
||||
$txEmail->setSubscriberEmail($params['email']);
|
||||
$txEmail->setTemplateId($this->config->get('config.plugins.listmonk.tx.template'));
|
||||
$txEmail->setFromEmail($this->config->get('config.plugins.email.from'));
|
||||
|
||||
#try {
|
||||
# $client = $this->getListmonkClient();
|
||||
#} catch (ListmonkClientException $e) {
|
||||
# $this->grav->fireEvent('onFormValidationError', new Event([
|
||||
# 'form' => $form,
|
||||
# 'message' => $e->getMessage(),
|
||||
# ]));
|
||||
#} catch (ListmonkException $e) {
|
||||
# throw new \RuntimeException('Error while processing form', -1, $e);
|
||||
#}
|
||||
if (isset($params['data']) && is_array($params['data'])) {
|
||||
$txEmail->setData($params['data']);
|
||||
}
|
||||
|
||||
$this->grav->fireEvent('onTransactionalEmailInitialized', new Event([
|
||||
'email' => $txEmail,
|
||||
'params' => $params,
|
||||
'form' => $form,
|
||||
]));
|
||||
|
||||
$result = $this->getListmonkClient()
|
||||
->transactional()
|
||||
->send($txEmail);
|
||||
|
||||
$this->grav->fireEvent('onTransactionalEmailSent', new Event([
|
||||
'email' => $txEmail,
|
||||
'result' => $result,
|
||||
]));
|
||||
|
||||
} catch (\Exception $e) {
|
||||
$this->grav->fireEvent('onFormValidationError', new Event([
|
||||
'form' => $form,
|
||||
'message' => $e->getMessage(),
|
||||
]));
|
||||
}
|
||||
}
|
||||
|
||||
private function processAttributes(array $attributes): array
|
||||
|
||||
Reference in New Issue
Block a user