You've already forked grav-plugin-listmonk
added transactional email handling
This commit is contained in:
@@ -93,3 +93,16 @@ form:
|
|||||||
placeholder: '{"attribute": "value"}'
|
placeholder: '{"attribute": "value"}'
|
||||||
validate:
|
validate:
|
||||||
type: string
|
type: string
|
||||||
|
|
||||||
|
tx:
|
||||||
|
type: tab
|
||||||
|
title: PLUGIN_LISTMONK.TX
|
||||||
|
fields:
|
||||||
|
tx.template:
|
||||||
|
type: integer
|
||||||
|
label: PLUGIN_LISTMONK.TX_TEMPLATE_ID
|
||||||
|
help: PLUGIN_LISTMONK.TX_TEMPLATE_ID_HELP
|
||||||
|
size: small
|
||||||
|
validate:
|
||||||
|
type: number
|
||||||
|
min: 1
|
||||||
|
|||||||
4
composer.lock
generated
4
composer.lock
generated
@@ -4,7 +4,7 @@
|
|||||||
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
|
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
|
||||||
"This file is @generated automatically"
|
"This file is @generated automatically"
|
||||||
],
|
],
|
||||||
"content-hash": "096d3c9059b402b96784b2897ab5dba7",
|
"content-hash": "4c5328ecf25c0457de8450b214fe18de",
|
||||||
"packages": [
|
"packages": [
|
||||||
{
|
{
|
||||||
"name": "adnanhussainturki/listmonk-php",
|
"name": "adnanhussainturki/listmonk-php",
|
||||||
@@ -34,7 +34,7 @@
|
|||||||
],
|
],
|
||||||
"description": "Package aims to ease up the API calls to a listmonk API from PHP based application",
|
"description": "Package aims to ease up the API calls to a listmonk API from PHP based application",
|
||||||
"transport-options": {
|
"transport-options": {
|
||||||
"symlink": false,
|
"symlink": true,
|
||||||
"relative": false
|
"relative": false
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -20,3 +20,6 @@ de:
|
|||||||
NEWSLETTER_STATUS_HELP: Standard-Status für neue Newsletter-Empfänger
|
NEWSLETTER_STATUS_HELP: Standard-Status für neue Newsletter-Empfänger
|
||||||
NEWSLETTER_ATTRIBUTES: Globale Attribute (JSON)
|
NEWSLETTER_ATTRIBUTES: Globale Attribute (JSON)
|
||||||
NEWSLETTER_ATTRIBUTES_HELP: JSON-Objekt mit globalen Attributen für Newsletter-Empfänger
|
NEWSLETTER_ATTRIBUTES_HELP: JSON-Objekt mit globalen Attributen für Newsletter-Empfänger
|
||||||
|
TX: Transaktionen
|
||||||
|
TX_TEMPLATE_ID: ID der Vorlage
|
||||||
|
TX_TEMPLATE_ID_HELP: Listmonk-ID der Standard-Vorlage
|
||||||
|
|||||||
49
listmonk.php
49
listmonk.php
@@ -3,6 +3,7 @@ namespace Grav\Plugin;
|
|||||||
|
|
||||||
use AdnanHussainTurki\ListMonk\ListMonk;
|
use AdnanHussainTurki\ListMonk\ListMonk;
|
||||||
use AdnanHussainTurki\ListMonk\Models\MonkSubscriber;
|
use AdnanHussainTurki\ListMonk\Models\MonkSubscriber;
|
||||||
|
use AdnanHussainTurki\ListMonk\Models\TransactionalEmail;
|
||||||
use Composer\Autoload\ClassLoader;
|
use Composer\Autoload\ClassLoader;
|
||||||
use Grav\Common\Data\Data;
|
use Grav\Common\Data\Data;
|
||||||
use Grav\Common\Plugin;
|
use Grav\Common\Plugin;
|
||||||
@@ -109,7 +110,7 @@ class ListmonkPlugin extends Plugin
|
|||||||
'source' => 'gravcms',
|
'source' => 'gravcms',
|
||||||
]));
|
]));
|
||||||
|
|
||||||
$this->grav->fireEvent('onListmonkSubscriberObjectCreated', new Event([
|
$this->grav->fireEvent('onListmonkSubscriberInitialized', new Event([
|
||||||
'subscriber' => $subscriber,
|
'subscriber' => $subscriber,
|
||||||
]));
|
]));
|
||||||
|
|
||||||
@@ -131,28 +132,42 @@ class ListmonkPlugin extends Plugin
|
|||||||
/**
|
/**
|
||||||
* Send a transactional mail using listmonk
|
* Send a transactional mail using listmonk
|
||||||
*
|
*
|
||||||
* (Not implemented yet!)
|
|
||||||
*
|
|
||||||
* @param Event $event
|
* @param Event $event
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
private function processTransactionalForm(Event $event, Form $form, array $params): void
|
private function processTransactionalForm(Event $event, Form $form, array $params): void
|
||||||
{
|
{
|
||||||
$this->grav->fireEvent('onFormValidationError', new Event([
|
try {
|
||||||
'form' => $form,
|
$txEmail = new TransactionalEmail();
|
||||||
'message' => 'Sending transactional emails is not implemented yet',
|
$txEmail->setSubscriberEmail($params['email']);
|
||||||
]));
|
$txEmail->setTemplateId($this->config->get('config.plugins.listmonk.tx.template'));
|
||||||
|
$txEmail->setFromEmail($this->config->get('config.plugins.email.from'));
|
||||||
|
|
||||||
#try {
|
if (isset($params['data']) && is_array($params['data'])) {
|
||||||
# $client = $this->getListmonkClient();
|
$txEmail->setData($params['data']);
|
||||||
#} catch (ListmonkClientException $e) {
|
}
|
||||||
# $this->grav->fireEvent('onFormValidationError', new Event([
|
|
||||||
# 'form' => $form,
|
$this->grav->fireEvent('onTransactionalEmailInitialized', new Event([
|
||||||
# 'message' => $e->getMessage(),
|
'email' => $txEmail,
|
||||||
# ]));
|
'params' => $params,
|
||||||
#} catch (ListmonkException $e) {
|
'form' => $form,
|
||||||
# throw new \RuntimeException('Error while processing form', -1, $e);
|
]));
|
||||||
#}
|
|
||||||
|
$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
|
private function processAttributes(array $attributes): array
|
||||||
|
|||||||
@@ -7,3 +7,5 @@ newsletter:
|
|||||||
list: 1
|
list: 1
|
||||||
subscriber:
|
subscriber:
|
||||||
status: enabled
|
status: enabled
|
||||||
|
tx:
|
||||||
|
template: 1
|
||||||
|
|||||||
Reference in New Issue
Block a user