/** * @param TokenReplacementEvent $event */ public function onTokenReplacement(TokenReplacementEvent $event) { $clickthrough = $event->getClickthrough(); if (!array_key_exists('dynamicContent', $clickthrough)) { return; } $lead = $event->getLead(); $tokenData = $clickthrough['dynamicContent']; if ($lead instanceof Lead) { $lead = $lead->getProfileFields(); } foreach ($tokenData as $data) { $defaultContent = $data['content']; $filterContent = null; foreach ($data['filters'] as $filter) { if ($this->matchFilterForLead($filter['filters'], $lead)) { $filterContent = $filter['content']; } } $event->addToken('{dynamiccontent="' . $data['tokenName'] . '"}', $filterContent ?: $defaultContent); } }
/** * @param TokenReplacementEvent $event */ public function onTokenReplacement(TokenReplacementEvent $event) { /** @var Lead $lead */ $lead = $event->getLead(); $content = $event->getContent(); $clickthrough = $event->getClickthrough(); if ($content) { $tokens = array_merge(TokenHelper::findLeadTokens($content, $lead->getProfileFields()), $this->pageTokenHelper->findPageTokens($content, $clickthrough), $this->assetTokenHelper->findAssetTokens($content, $clickthrough)); list($content, $trackables) = $this->trackableModel->parseContentForTrackables($content, $tokens, 'sms', $clickthrough['channel'][1]); /** * @var string * @var Trackable $trackable */ foreach ($trackables as $token => $trackable) { $tokens[$token] = $this->trackableModel->generateTrackableUrl($trackable, $clickthrough, true); } $content = str_replace(array_keys($tokens), array_values($tokens), $content); $event->setContent($content); } }