/**
  * @return Layout
  */
 public function getLayout()
 {
     if ($this->layout) {
         return $this->layout;
     }
     return $this->messageContent->getMessage()->getLayout();
 }
 /**
  * {@inheritdoc}
  */
 public function renderContent(MessageContent $messageContent, Layout $layout = null)
 {
     if ($messageContent->getInvisible() && TL_MODE != 'BE' && !BE_USER_LOGGED_IN) {
         return '';
     }
     $event = new RenderMessageContentEvent($messageContent, $layout ?: $messageContent->getMessage()->getLayout());
     /** @var EventDispatcher $eventDispatcher */
     $eventDispatcher = $GLOBALS['container']['event-dispatcher'];
     $eventDispatcher->dispatch(AvisotaMessageEvents::RENDER_MESSAGE_CONTENT, $event);
     return $event->getRenderedContent();
 }
 /**
  * @param array|\ArrayObject $options
  * @param MessageContent     $content
  *
  * @return array|\ArrayObject
  * @SuppressWarnings(PHPMD.LongVariable)
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  * @SuppressWarnings(PHPMD.NPathComplexity)
  * @SuppressWarnings(PHPMD.Superglobals)
  */
 public function getCellContentTypeOptions($options = array(), MessageContent $content = null)
 {
     $message = $content->getMessage();
     $layout = $message->getLayout();
     if (!$layout || $layout->getType() != 'mailChimp') {
         return $options;
     }
     $allowedTypes = array($content->getType());
     list($group, $mailChimpTemplate) = explode(':', $layout->getMailchimpTemplate());
     if (isset($GLOBALS['AVISOTA_MAILCHIMP_TEMPLATE'][$group][$mailChimpTemplate])) {
         $config = $GLOBALS['AVISOTA_MAILCHIMP_TEMPLATE'][$group][$mailChimpTemplate];
         if (isset($config['cells'][$content->getCell()])) {
             $cellConfig = $config['cells'][$content->getCell()];
             if (!isset($cellConfig['content'])) {
                 if (isset($cellConfig['preferredElements'])) {
                     $allowedTypes = array_merge($allowedTypes, $cellConfig['preferredElements']);
                 } else {
                     foreach ($GLOBALS['TL_MCE'] as $elements) {
                         foreach ($elements as $elementType) {
                             $allowedTypes[] = $elementType;
                         }
                     }
                 }
             }
         }
     }
     foreach ($layout->getAllowedCellContents() as $allowedCellContentType) {
         list($cell, $elementType) = explode(':', $allowedCellContentType);
         if ($cell == $content->getCell()) {
             $allowedTypes[] = $elementType;
         }
     }
     foreach ($options as $group => &$values) {
         if (is_array($values)) {
             foreach ($values as $key => $value) {
                 if (!in_array($key, $allowedTypes) && $value) {
                     unset($values[$key]);
                 }
             }
         } else {
             if (!in_array($group, $allowedTypes)) {
                 unset($options[$group]);
             }
         }
     }
     return $options;
 }
 /**
  * @param MessageContent $messageContent
  * @param array          $contents
  *
  * @return array
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  */
 protected function handleFoundedContent(MessageContent $messageContent, array $contents)
 {
     if (count($contents) < 1) {
         return array();
     }
     $messageCategory = $messageContent->getMessage()->getCategory();
     $viewOnlinePageModel = \PageModel::findByPk($messageCategory->getViewOnlinePage());
     if (!$viewOnlinePageModel) {
         $viewOnlinePageModel = \PageModel::findByPk(Frontend::getRootIdFromUrl());
     }
     $viewOnlinePageModel->loadDetails();
     $replaced = array();
     $replacedIn = array();
     foreach ($contents as $content) {
         foreach (array('type', 'galleryTpl', 'customTpl', 'eventTemplate', 'newsTemplate') as $propertyTemplate) {
             if ($content instanceof \Model) {
                 if (empty($content->{$propertyTemplate})) {
                     continue;
                 }
                 $template = $this->findTemplate($content->{$propertyTemplate}, $messageCategory);
                 if ($content->{$propertyTemplate} === $template) {
                     continue;
                 }
                 $content->{$propertyTemplate} = $template;
                 $replaced[] = $template;
                 $replacedIn[] = $content;
             }
             if ($content instanceof EntityInterface) {
                 $getPropertyTemplate = 'get' . ucfirst($propertyTemplate);
                 $setPropertyTemplate = 'set' . ucfirst($propertyTemplate);
                 if (!method_exists($content, $getPropertyTemplate) || !$content->{$getPropertyTemplate}()) {
                     continue;
                 }
                 $template = $this->findTemplate($content->{$getPropertyTemplate}(), $messageCategory);
                 if ($content->{$getPropertyTemplate}() === $template) {
                     continue;
                 }
                 $content->{$setPropertyTemplate}($template);
                 $replaced[] = $template;
                 $replacedIn[] = $content;
             }
         }
     }
     return array($replaced, $replacedIn);
 }