added transactional email handling

This commit is contained in:
2025-08-06 20:43:34 +02:00
parent 43e0566ab0
commit ea63a56a55
5 changed files with 52 additions and 19 deletions

View File

@@ -93,3 +93,16 @@ form:
placeholder: '{"attribute": "value"}'
validate:
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
View File

@@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
"content-hash": "096d3c9059b402b96784b2897ab5dba7",
"content-hash": "4c5328ecf25c0457de8450b214fe18de",
"packages": [
{
"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",
"transport-options": {
"symlink": false,
"symlink": true,
"relative": false
}
},

View File

@@ -20,3 +20,6 @@ de:
NEWSLETTER_STATUS_HELP: Standard-Status für neue Newsletter-Empfänger
NEWSLETTER_ATTRIBUTES: Globale Attribute (JSON)
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

View File

@@ -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([
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'));
if (isset($params['data']) && is_array($params['data'])) {
$txEmail->setData($params['data']);
}
$this->grav->fireEvent('onTransactionalEmailInitialized', new Event([
'email' => $txEmail,
'params' => $params,
'form' => $form,
'message' => 'Sending transactional emails is not implemented yet',
]));
#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);
#}
$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

View File

@@ -7,3 +7,5 @@ newsletter:
list: 1
subscriber:
status: enabled
tx:
template: 1