public function createRecipientSource(RecipientSource $recipientSourceEntity)
 {
     $recipientSource = new RecipientsRecipientSourceSalutations();
     if ($recipientSourceEntity->getFilter()) {
         if ($recipientSourceEntity->getFilterByMailingLists()) {
             $recipientSource->setFilteredMailingLists($recipientSourceEntity->getMailingLists()->toArray());
         }
         if ($recipientSourceEntity->getRecipientsUsePropertyFilter()) {
             $recipientSource->setFilteredProperties($recipientSourceEntity->getRecipientsPropertyFilter());
         }
     }
     /** @var EventDispatcherInterface $eventDispatcher */
     $eventDispatcher = $GLOBALS['container']['event-dispatcher'];
     if ($recipientSourceEntity->getRecipientsManageSubscriptionPage()) {
         $getPageDetailsEvent = new GetPageDetailsEvent($recipientSourceEntity->getRecipientsManageSubscriptionPage());
         $eventDispatcher->dispatch(ContaoEvents::CONTROLLER_GET_PAGE_DETAILS, $getPageDetailsEvent);
         $generateFrontendUrlEvent = new GenerateFrontendUrlEvent($getPageDetailsEvent->getPageDetails());
         $eventDispatcher->dispatch(ContaoEvents::CONTROLLER_GENERATE_FRONTEND_URL, $generateFrontendUrlEvent);
         $url = $generateFrontendUrlEvent->getUrl();
         $url .= (strpos($url, '?') !== false ? '&' : '?') . 'avisota_subscription_email=##email##';
         if (!preg_match('~^\\w+:~', $url)) {
             $environment = \Environment::getInstance();
             $url = rtrim($environment->base, '/') . '/' . ltrim($url, '/');
         }
         $recipientSource->setManageSubscriptionUrlPattern($url);
     }
     if ($recipientSourceEntity->getRecipientsUnsubscribePage()) {
         $getPageDetailsEvent = new GetPageDetailsEvent($recipientSourceEntity->getRecipientsUnsubscribePage());
         $eventDispatcher->dispatch(ContaoEvents::CONTROLLER_GET_PAGE_DETAILS, $getPageDetailsEvent);
         $generateFrontendUrlEvent = new GenerateFrontendUrlEvent($getPageDetailsEvent->getPageDetails());
         $eventDispatcher->dispatch(ContaoEvents::CONTROLLER_GENERATE_FRONTEND_URL, $generateFrontendUrlEvent);
         $url = $generateFrontendUrlEvent->getUrl();
         $url .= (strpos($url, '?') !== false ? '&' : '?') . 'avisota_subscription_email=##email##';
         if (!preg_match('~^\\w+:~', $url)) {
             $environment = \Environment::getInstance();
             $url = rtrim($environment->base, '/') . '/' . ltrim($url, '/');
         }
         $recipientSource->setUnsubscribeUrlPattern($url);
     }
     $event = new CreateRecipientSourceEvent($recipientSourceEntity, $recipientSource);
     $eventDispatcher->dispatch(CoreEvents::CREATE_RECIPIENT_SOURCE, $event);
     return $event->getRecipientSource();
 }
 /**
  * @param RecipientSource           $entity
  * @param RecipientsRecipientSource $recipientSource
  * @SuppressWarnings(PHPMD.LongVariable)
  */
 protected function parseRecipientsManageSubscriptionPage(RecipientSource $entity, RecipientsRecipientSource &$recipientSource)
 {
     if (!$entity->getRecipientsManageSubscriptionPage()) {
         return;
     }
     global $container;
     /** @var EventDispatcherInterface $eventDispatcher */
     $eventDispatcher = $container['event-dispatcher'];
     $getPageDetailsEvent = new GetPageDetailsEvent($entity->getRecipientsManageSubscriptionPage());
     $eventDispatcher->dispatch(ContaoEvents::CONTROLLER_GET_PAGE_DETAILS, $getPageDetailsEvent);
     $generateFrontendUrlEvent = new GenerateFrontendUrlEvent($getPageDetailsEvent->getPageDetails());
     $eventDispatcher->dispatch(ContaoEvents::CONTROLLER_GENERATE_FRONTEND_URL, $generateFrontendUrlEvent);
     $url = $generateFrontendUrlEvent->getUrl();
     $url .= (strpos($url, '?') !== false ? '&' : '?') . 'avisota_subscription_email=##email##';
     if (!preg_match('~^\\w+:~', $url)) {
         $url = rtrim(\Environment::get('base'), '/') . '/' . ltrim($url, '/');
     }
     $recipientSource->setManageSubscriptionUrlPattern($url);
     $event = new CreateRecipientSourceEvent($entity, $recipientSource);
     $eventDispatcher->dispatch(CoreEvents::CREATE_RECIPIENT_SOURCE, $event);
     $recipientSource = $event->getRecipientSource();
 }