From 7a904a516cef716940c2b0bb6c586dd286c7d64d Mon Sep 17 00:00:00 2001 From: Henrik Ziegenhain Date: Wed, 6 May 2026 11:02:58 +0200 Subject: [PATCH 1/3] [FEATURE] [FEATURE] return contact-id on subscription resolves #24 --- Classes/Finishers/BrevoFinisher.php | 47 +++++++++++++++++++++-------- Readme.md | 7 +++++ 2 files changed, 42 insertions(+), 12 deletions(-) diff --git a/Classes/Finishers/BrevoFinisher.php b/Classes/Finishers/BrevoFinisher.php index d5a8629..75aef6c 100644 --- a/Classes/Finishers/BrevoFinisher.php +++ b/Classes/Finishers/BrevoFinisher.php @@ -51,7 +51,14 @@ protected function executeInternal(): void return; } - $this->addEntryToBrevo() ? $this->setFinisherSubscribedVariable(1) : $this->setFinisherSubscribedVariable(0); + $newContactId = $this->addEntryToBrevo(); + if ($newContactId !== null) { + $this->setFinisherSubscribedVariable(1); + } + if ($newContactId > 0) { + $this->setFinisherNewContactIdVariable($newContactId); + } + $this->setFinisherSubscribedVariable(0); } protected function setFinisherSubscribedVariable(int $returnValue): void @@ -63,7 +70,22 @@ protected function setFinisherSubscribedVariable(int $returnValue): void ); } - protected function addEntryToBrevo(): bool + protected function setFinisherNewContactIdVariable(int $newContactId): void + { + $this->finisherContext->getFinisherVariableProvider()->add( + 'brevo', + 'data.newContactId', + $newContactId + ); + } + + /** + * Add the entry to Brevo. + * In case of active DOI, the contact is not created immediately, so no contact ID can be returned. + * + * @return int|null + */ + protected function addEntryToBrevo(): int|null { try { $apiInstance = $this->getApi(); @@ -76,20 +98,21 @@ protected function addEntryToBrevo(): bool ->setAttributes($this->getAttributes()) ->setRedirectionUrl($this->getRedirectionUrl()); $apiInstance->createDoiContact($createContact); - } else { - $createContact = new CreateContact(); - $createContact - ->setEmail($this->parseOption('email')) - ->setUpdateEnabled(true) - ->setListIds($this->getEnrichedListIds()) - ->setAttributes($this->getAttributes()); - $apiInstance->createContact($createContact); + return 0; // in case of DOI we cannot return the contact ID, because the contact is not created immediately } - return true; + + $createContact = new CreateContact(); + $createContact + ->setEmail($this->parseOption('email')) + ->setUpdateEnabled(true) + ->setListIds($this->getEnrichedListIds()) + ->setAttributes($this->getAttributes()); + return $apiInstance->createContact($createContact)->getId(); + } catch (\Exception $exception) { // todo: should we forward it to the user? $this->logger->error($exception->getMessage()); - return false; + return null; } } diff --git a/Readme.md b/Readme.md index b729546..d2d9fce 100644 --- a/Readme.md +++ b/Readme.md @@ -70,6 +70,13 @@ The following configurations can be used to override the global settings identifier: Brevo ``` +### Returned data from Finisher + +There are some additional data returned by the finisher to use in following finishers: +- **Brevo Contact ID**: The ID of the newly created contact in brevo. This can be used for example to trigger an automation workflow for this contact. (*brevo.data.newContactId*) +- **Subscription Status**: If the user has subscribed to the newsletter or not. (*brevo.data.subscribed*) +- + ## Author This extension has been created by [StudioMitte](https://studiomitte.com) From dc14f8ffcf8b328d64dbe4b9fa8a4a081d51c03c Mon Sep 17 00:00:00 2001 From: Henrik Ziegenhain Date: Wed, 6 May 2026 13:27:40 +0200 Subject: [PATCH 2/3] [FEATURE] return contact-id on subscription --- Classes/Finishers/BrevoFinisher.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Classes/Finishers/BrevoFinisher.php b/Classes/Finishers/BrevoFinisher.php index 75aef6c..deb1e45 100644 --- a/Classes/Finishers/BrevoFinisher.php +++ b/Classes/Finishers/BrevoFinisher.php @@ -107,7 +107,7 @@ protected function addEntryToBrevo(): int|null ->setUpdateEnabled(true) ->setListIds($this->getEnrichedListIds()) ->setAttributes($this->getAttributes()); - return $apiInstance->createContact($createContact)->getId(); + return $apiInstance->createContact($createContact)?->getId() ?? 0; } catch (\Exception $exception) { // todo: should we forward it to the user? From 43dbb5ea2d5ba60d1c2e4999411ef47222939983 Mon Sep 17 00:00:00 2001 From: Henrik Ziegenhain Date: Thu, 14 May 2026 09:28:06 +0200 Subject: [PATCH 3/3] [BUGFIX] finisher always set to "not subscribed" --- Classes/Finishers/BrevoFinisher.php | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/Classes/Finishers/BrevoFinisher.php b/Classes/Finishers/BrevoFinisher.php index deb1e45..a700a40 100644 --- a/Classes/Finishers/BrevoFinisher.php +++ b/Classes/Finishers/BrevoFinisher.php @@ -23,6 +23,7 @@ use StudioMitte\Brevo\Events\FormFinisherAttributeEvent; use TYPO3\CMS\Core\EventDispatcher\EventDispatcher; use TYPO3\CMS\Core\Utility\GeneralUtility; +use TYPO3\CMS\Core\Utility\MathUtility; use TYPO3\CMS\Form\Domain\Finishers\AbstractFinisher; /** @@ -52,12 +53,14 @@ protected function executeInternal(): void } $newContactId = $this->addEntryToBrevo(); - if ($newContactId !== null) { + if (MathUtility::canBeInterpretedAsInteger($newContactId)) { $this->setFinisherSubscribedVariable(1); + if ($newContactId > 0) { + $this->setFinisherNewContactIdVariable($newContactId); + } + return; } - if ($newContactId > 0) { - $this->setFinisherNewContactIdVariable($newContactId); - } + $this->setFinisherSubscribedVariable(0); }