![]() Server : Apache System : Linux server2.corals.io 4.18.0-348.2.1.el8_5.x86_64 #1 SMP Mon Nov 15 09:17:08 EST 2021 x86_64 User : corals ( 1002) PHP Version : 7.4.33 Disable Function : exec,passthru,shell_exec,system Directory : /home/corals/mautic.corals.io/app/bundles/LeadBundle/EventListener/ |
<?php namespace Mautic\LeadBundle\EventListener; use Mautic\CoreBundle\Event\TokenReplacementEvent; use Mautic\CoreBundle\Helper\BuilderTokenHelperFactory; use Mautic\EmailBundle\EmailEvents; use Mautic\EmailBundle\Event\EmailBuilderEvent; use Mautic\EmailBundle\Event\EmailSendEvent; use Mautic\LeadBundle\Helper\TokenHelper; use Symfony\Component\EventDispatcher\EventSubscriberInterface; class EmailSubscriber implements EventSubscriberInterface { private static string $contactFieldRegex = '{contactfield=(.*?)}'; public function __construct( private BuilderTokenHelperFactory $builderTokenHelperFactory ) { } public static function getSubscribedEvents(): array { return [ EmailEvents::EMAIL_ON_BUILD => ['onEmailBuild', 0], EmailEvents::EMAIL_ON_SEND => ['onEmailGenerate', 0], EmailEvents::EMAIL_ON_DISPLAY => ['onEmailDisplay', 0], EmailEvents::ON_EMAIL_ADDRESS_TOKEN_REPLACEMENT => ['onEmailAddressReplacement', 0], ]; } public function onEmailBuild(EmailBuilderEvent $event): void { $tokenHelper = $this->builderTokenHelperFactory->getBuilderTokenHelper('lead.field', 'lead:fields', 'MauticLeadBundle'); // the permissions are for viewing contact data, not for managing contact fields $tokenHelper->setPermissionSet(['lead:leads:viewown', 'lead:leads:viewother']); if ($event->tokensRequested(self::$contactFieldRegex)) { $event->addTokensFromHelper($tokenHelper, self::$contactFieldRegex, 'label', 'alias'); } } public function onEmailDisplay(EmailSendEvent $event): void { $this->onEmailGenerate($event); } public function onEmailGenerate(EmailSendEvent $event): void { // Combine all possible content to find tokens across them $content = $event->getSubject(); $content .= $event->getContent(); $content .= $event->getPlainText(); $content .= implode(' ', $event->getTextHeaders()); $lead = $event->getLead(); $tokenList = TokenHelper::findLeadTokens($content, $lead); if (count($tokenList)) { $event->addTokens($tokenList); unset($tokenList); } } public function onEmailAddressReplacement(TokenReplacementEvent $event): void { $event->setContent(TokenHelper::findLeadTokens($event->getContent(), $event->getLead()->getProfileFields(), true)); } }