-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Mautic 4 (#28) * feat: ✨ mautic v4 port * Update TemplateProcessor.php bring pixel tracking back * Update EmailSubscriber.php modify content and add pixel tracking back * Update README.md Co-authored-by: zerodois <[email protected]> * Simple bug fixes * logger, lead tags, sms support, update readme * update readme * Update README.md --------- Co-authored-by: zerodois <[email protected]> Co-authored-by: Luis Rodriguez <[email protected]>
- Loading branch information
1 parent
a70b187
commit 04d5f47
Showing
6 changed files
with
276 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
<?php | ||
|
||
namespace MauticPlugin\MauticAdvancedTemplatesBundle\EventListener; | ||
use Mautic\CampaignBundle\Entity\Lead; | ||
use Symfony\Component\EventDispatcher\EventSubscriberInterface; | ||
use Mautic\SmsBundle\SmsEvents; | ||
use Mautic\SmsBundle\Event as Events; | ||
use Mautic\EmailBundle\Helper\PlainTextHelper; | ||
use Mautic\CoreBundle\Exception as MauticException; | ||
use Mautic\LeadBundle\Model\LeadModel; | ||
use MauticPlugin\MauticAdvancedTemplatesBundle\Helper\TemplateProcessor; | ||
use Psr\Log\LoggerInterface; | ||
use Monolog\Logger; | ||
|
||
/** | ||
* Class EmailSubscriber. | ||
*/ | ||
class SmsSubscriber implements EventSubscriberInterface | ||
{ | ||
/** | ||
* @var LeadModel | ||
*/ | ||
private $leadModel; | ||
|
||
/** | ||
* @var TokenHelper $tokenHelper ; | ||
*/ | ||
protected $templateProcessor; | ||
|
||
/** | ||
* @var LoggerInterface $logger ; | ||
*/ | ||
protected $logger; | ||
|
||
/** | ||
* EmailSubscriber constructor. | ||
* | ||
* @param TokenHelper $tokenHelper | ||
*/ | ||
public function __construct(TemplateProcessor $templateProcessor, LeadModel $leadModel, Logger $logger) | ||
{ | ||
$this->templateProcessor = $templateProcessor; | ||
$this->leadModel = $leadModel; | ||
$this->logger = $logger; | ||
} | ||
/** | ||
* @return array | ||
*/ | ||
public static function getSubscribedEvents() | ||
{ | ||
return [ | ||
SmsEvents::SMS_ON_SEND => ['onSmsGenerate', 300], | ||
// I dont know how to do this without editing core. | ||
// since there does not seem to be a simular way to call it yet. | ||
// SmsEvents::SMS_ON_DISPLAY => ['onSmsGenerate', 0], | ||
]; | ||
} | ||
|
||
/** | ||
* Search and replace tokens with content | ||
* | ||
* @param Events\SmsSendEvent $event | ||
* @throws \Throwable | ||
* @throws \Twig_Error_Loader | ||
* @throws \Twig_Error_Syntax | ||
*/ | ||
public function onSmsGenerate(Events\SmsSendEvent $event) | ||
{ | ||
$this->logger->info('onSmsGenerate MauticAdvancedTemplatesBundle\SmsSubscriber'); | ||
|
||
$content = $event->getContent(); | ||
|
||
$lead = $event->getLead(); | ||
$leadmodel = $this->leadModel->getEntity($lead['id']); | ||
$lead['tags'] = []; | ||
if ($leadmodel && count($leadmodel->getTags()) > 0) { | ||
foreach ($leadmodel->getTags() as $tag) { | ||
$lead['tags'][] = $tag->getTag(); | ||
} | ||
} | ||
|
||
$content = $this->templateProcessor->processTemplate($content, $lead); | ||
$event->setContent($content); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.