removed simplenews_mailjet_subscriptions, replaced it by features in custom module materio_mailjet

This commit is contained in:
2026-09-25 20:48:46 +02:00
parent ef699e9748
commit 89d68ac548
17 changed files with 272 additions and 156 deletions
@@ -4,7 +4,6 @@ namespace Drupal\materio_mailjet\Controller;
use Drupal\Core\Controller\ControllerBase;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Drupal\simplenews_mailjet_subscriptions\Entity\SimplenewsMailjetSubscriptionEntity;
use Drupal\simplenews\Entity\Subscriber;
use Drupal\simplenews\Subscription\SubscriptionManagerInterface;
@@ -80,24 +79,10 @@ class MaterioMailjetWebhookCallbackController extends ControllerBase {
$MjlistID = $event->mj_list_id;
$email = $event->email;
// find corresponding simplenews list from mailjet listID
$newsletter_id = null;
$entities = SimplenewsMailjetSubscriptionEntity::loadMultiple();
foreach ((array) $entities as $entity) {
$listID = (int)$entity->getID();
if ($listID === $MjlistID) {
$table = $entity->get('mapping_table');
if (is_array($table)) {
foreach ($table as $category) {
$newsletter_id = $category['simplenews_news'];
break;
}
}
break;
}
}
// \Drupal::logger('simplenews_mailjet_subscriptions')->info("Unsubscribe webhook triggered for listID: " . $listID . "and email: " . $email . ".");
// Find the simplenews newsletter mapped to this Mailjet list
// (mapping lives in materio_mailjet.settings).
$newsletter_id = \Drupal::service('materio_mailjet.sync')
->getNewsletterForListId((int) $MjlistID);
// get subscriber entity
// Load entities by their property values.
@@ -108,7 +93,7 @@ class MaterioMailjetWebhookCallbackController extends ControllerBase {
$subscriber = array_shift($subscribers);
if ($subscriber instanceof Subscriber) {
// $subscriber->unsubscribe($simplenews_news, 'mailjet');
$this->subscriptionManager->unsubscribe($subscriber->getMail(), $newsletter_id, FALSE, 'materio_mailjet');
$this->subscriptionManager->unsubscribe($subscriber->getMail(), $newsletter_id);
}
}
}