Ejemplo n.º 1
0
 /**
  * @param EmailSendEvent $event
  */
 public function onEmailGenerate(EmailSendEvent $event)
 {
     // Combine all possible content to find tokens across them
     $content = $event->getSubject();
     $content .= $event->getContent();
     $content .= $event->getPlainText();
     $lead = $event->getLead();
     $tokenList = TokenHelper::findLeadTokens($content, $lead);
     if (count($tokenList)) {
         $event->addTokens($tokenList);
         unset($tokenList);
     }
 }
Ejemplo n.º 2
0
 /**
  * @param EmailSendEvent $event
  */
 public function onEmailGenerate(EmailSendEvent $event)
 {
     $idHash = $event->getIdHash();
     $lead = $event->getLead();
     $email = $event->getEmail();
     if ($idHash == null) {
         // Generate a bogus idHash to prevent errors for routes that may include it
         $idHash = uniqid();
     }
     $unsubscribeText = $this->coreParametersHelper->getParameter('unsubscribe_text');
     if (!$unsubscribeText) {
         $unsubscribeText = $this->translator->trans('mautic.email.unsubscribe.text', ['%link%' => '|URL|']);
     }
     $unsubscribeText = str_replace('|URL|', $this->emailModel->buildUrl('mautic_email_unsubscribe', ['idHash' => $idHash]), $unsubscribeText);
     $event->addToken('{unsubscribe_text}', $unsubscribeText);
     $event->addToken('{unsubscribe_url}', $this->emailModel->buildUrl('mautic_email_unsubscribe', ['idHash' => $idHash]));
     $webviewText = $this->coreParametersHelper->getParameter('webview_text');
     if (!$webviewText) {
         $webviewText = $this->translator->trans('mautic.email.webview.text', ['%link%' => '|URL|']);
     }
     $webviewText = str_replace('|URL|', $this->emailModel->buildUrl('mautic_email_webview', ['idHash' => $idHash]), $webviewText);
     $event->addToken('{webview_text}', $webviewText);
     // Show public email preview if the lead is not known to prevent 404
     if (empty($lead['id']) && $email) {
         $event->addToken('{webview_url}', $this->emailModel->buildUrl('mautic_email_preview', ['objectId' => $email->getId()]));
     } else {
         $event->addToken('{webview_url}', $this->emailModel->buildUrl('mautic_email_webview', ['idHash' => $idHash]));
     }
     $signatureText = $this->coreParametersHelper->getParameter('default_signature_text');
     $fromName = $this->coreParametersHelper->getParameter('mailer_from_name');
     if (!empty($lead['owner_id'])) {
         $owner = $this->factory->getModel('lead')->getRepository()->getLeadOwner($lead['owner_id']);
         if ($owner && !empty($owner['signature'])) {
             $fromName = $owner['first_name'] . ' ' . $owner['last_name'];
             $signatureText = $owner['signature'];
         }
     }
     $signatureText = str_replace('|FROM_NAME|', $fromName, nl2br($signatureText));
     $event->addToken('{signature}', $signatureText);
     $event->addToken('{subject}', $event->getSubject());
 }