From 849a294750410fbda7a687b4d411071ba7694190 Mon Sep 17 00:00:00 2001 From: Dennis Ameling Date: Thu, 22 Oct 2020 11:05:24 +0200 Subject: [PATCH 1/3] Update extending pages (EventSubscriberInterface) --- source/includes/_plugin_extending_pages.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/source/includes/_plugin_extending_pages.md b/source/includes/_plugin_extending_pages.md index 77918f3f423..6ecb42f99dc 100644 --- a/source/includes/_plugin_extending_pages.md +++ b/source/includes/_plugin_extending_pages.md @@ -6,15 +6,15 @@ namespace MauticPlugin\HelloWorldBundle\EventListener; -use Mautic\CoreBundle\EventListener\CommonSubscriber; use Mautic\PageBundle\PageEvents; use Mautic\PageBundle\Event\PageBuilderEvent; use Mautic\PageBundle\Event\PageSendEvent; +use Symfony\Component\EventDispatcher\EventSubscriberInterface; /** * Class PageSubscriber */ -class PageSubscriber extends CommonSubscriber +class PageSubscriber implements EventSubscriberInterface { /** @@ -82,4 +82,4 @@ Page tokens are handled exactly the same as [Email Tokens](#page-tokens). #### Page A/B Test Winner Criteria -Custom landing page A/B test winner criteria is handled exactly the same as [page A/B test winner criteria](#page-a/b-test-winner-criteria) with the only differences being that the `callback` function is passed `Mautic\PageBundle\Entity\Page $page` and `Mautic\PageBundle\Entity\Page $parent` instead. Of course `$children` is an ArrayCollection of Page entities as well. \ No newline at end of file +Custom landing page A/B test winner criteria is handled exactly the same as [page A/B test winner criteria](#page-a/b-test-winner-criteria) with the only differences being that the `callback` function is passed `Mautic\PageBundle\Entity\Page $page` and `Mautic\PageBundle\Entity\Page $parent` instead. Of course `$children` is an ArrayCollection of Page entities as well. From 0dc50469840d3c640292aa0aef12fc058db31313 Mon Sep 17 00:00:00 2001 From: Dennis Ameling Date: Thu, 22 Oct 2020 11:24:23 +0200 Subject: [PATCH 2/3] Update events to use PageDisplayEvent The event `PageSendEvent` doesn't exist and should be `PageDisplayEvent` --- source/includes/_plugin_extending_pages.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/source/includes/_plugin_extending_pages.md b/source/includes/_plugin_extending_pages.md index 6ecb42f99dc..aa0b419acc2 100644 --- a/source/includes/_plugin_extending_pages.md +++ b/source/includes/_plugin_extending_pages.md @@ -8,7 +8,7 @@ namespace MauticPlugin\HelloWorldBundle\EventListener; use Mautic\PageBundle\PageEvents; use Mautic\PageBundle\Event\PageBuilderEvent; -use Mautic\PageBundle\Event\PageSendEvent; +use Mautic\PageBundle\Event\PageDisplayEvent; use Symfony\Component\EventDispatcher\EventSubscriberInterface; /** @@ -58,9 +58,9 @@ class PageSubscriber implements EventSubscriberInterface /** * Search and replace tokens with content * - * @param PageSendEvent $event + * @param PageDisplayEvent $event */ - public function onPageDisplay(PageSendEvent $event) + public function onPageDisplay(PageDisplayEvent $event) { // Get content $content = $event->getContent(); From baa38a19fb19c0315bb8994e9354ec9053c35010 Mon Sep 17 00:00:00 2001 From: Dennis Ameling Date: Thu, 22 Oct 2020 16:20:30 +0200 Subject: [PATCH 3/3] Make example more complete --- source/includes/_plugin_extending_pages.md | 42 ++++++++++++++++++++-- 1 file changed, 39 insertions(+), 3 deletions(-) diff --git a/source/includes/_plugin_extending_pages.md b/source/includes/_plugin_extending_pages.md index aa0b419acc2..632526de5ee 100644 --- a/source/includes/_plugin_extending_pages.md +++ b/source/includes/_plugin_extending_pages.md @@ -1,11 +1,34 @@ ### Extending Landing Pages +Make sure you reigster the event listener in your `config.php`: + +```php + [ + 'events' => [ + 'plugin.helloworld.page.subscriber' => array( + 'class' => PageSubscriber::class, + 'arguments' => [ + 'mautic.helper.templating' + ] + ) + ], + ], +]; + +``` ```php templating = $templating; + } /** * @return array @@ -36,8 +68,9 @@ class PageSubscriber implements EventSubscriberInterface public function onPageBuild(PageBuilderEvent $event) { // Add page tokens - $content = $this->templating->render('HelloWorldBundle:SubscribedEvents\PageToken:token.html.php'); - $event->addTokenSection('helloworld.token', 'plugin.helloworld.header', $content); + if ($event->tokensRequested('{myToken}')) { + $event->addToken('{myToken}', 'My Token'); + } // Add AB Test Winner Criteria $event->addAbTestWinnerCriteria( @@ -66,7 +99,10 @@ class PageSubscriber implements EventSubscriberInterface $content = $event->getContent(); // Search and replace tokens - $content = str_replace('{hello}', 'world!', $content); + $html = $this->templating->getTemplating()->render( + 'HelloWorldBundle:SubscribedEvents\PageToken:token.html.php' + ); + $content = str_replace('{myToken}', $html, $content); // Set updated content $event->setContent($content);