public static function onRender(Event $event) { $renderer = $event->getEventArgs(); $application = $event->getDispatcher()->getApplication(); $em = $application->getEntityManager(); $content = $renderer->getObject(); $links = $content->getParamValue('link'); $link = ['url' => '', 'title' => 'Visit', 'target' => '_self']; if (!empty($links)) { $links = reset($links); if (isset($links['pageUid']) && !empty($links['pageUid'])) { $page = $em->getRepository('BackBee\\NestedNode\\Page')->find($links['pageUid']); if ($page !== null) { $link['url'] = $renderer->getUri($page->getUrl()); } } if (empty($link['url']) && isset($links['url'])) { $link['url'] = $links['url']; } if (isset($links['title'])) { $link['title'] = $links['title']; } if (isset($links['target'])) { $link['target'] = $links['target']; } } $renderer->assign('link', $link); }
/** * Occur on site.layout.postremove events. * * @access public * * @param Event $event */ public static function onAfterRemove(Event $event) { $layout = $event->getTarget(); if (!is_a($layout, 'BackBee\\Site\\Layout')) { return; } $dispatcher = $event->getDispatcher(); if (null !== $dispatcher->getApplication()) { $dispatcher->getApplication()->getEntityManager()->getRepository('BackBee\\Site\\Layout')->removeThumbnail($layout, $dispatcher->getApplication()); } $dispatcher->getApplication()->getRenderer()->removeLayout($layout); }
public static function onPreRenderTwitter(Event $event) { $renderer = $event->getEventArgs(); self::$application = $event->getDispatcher()->getApplication(); $config = self::getSocialConfig('twitter'); $content = $renderer->getObject(); $widgetId = $content->getParamValue('widget_id'); if (empty($widgetId)) { if (null !== $config && isset($config['widget_id'])) { $widgetId = $config['widget_id']; } } $renderer->assign('widget_id', $widgetId); }
public static function onUserCreated(Event $event) { $application = $event->getDispatcher()->getApplication(); $site = $application->getSite(); $user = $event->getTarget(); if ($user instanceof User && $site instanceof Site) { $body = $application->getRenderer()->partial('Email/NewUser.twig', ['user' => $user, 'site_name' => $site->getLabel(), 'home_link' => $site->getServerName()]); $message = static::buildMessage($application->getSecurityContext()->getToken()->getUser(), $user, $body, $application->getSite()); if (null !== $application->getMailer()) { $application->getMailer()->send($message); } else { throw new \RuntimeException('Mailer not available'); } } }
/** * Occur on nestednode.page.onflush events. * * @param \BackBee\Event\Event $event */ public static function onFlushPage(Event $event) { $page = $event->getTarget(); if (!$page instanceof Page) { return; } $maincontent = $event->getEventArgs(); if (!$maincontent instanceof AbstractClassContent) { $maincontent = null; } $dispatcher = $event->getDispatcher(); $application = $dispatcher->getApplication(); if (self::updateUrl($application, $page, $maincontent)) { $descendants = $application->getEntityManager()->getRepository('BackBee\\NestedNode\\Page')->getDescendants($page, 1); foreach ($descendants as $descendant) { self::updateUrl($application, $descendant); } } }
public static function onRender(Event $event) { $renderer = $event->getEventArgs(); $application = $event->getDispatcher()->getApplication(); $content = $renderer->getObject(); $tag = null; $url = '#'; $mainNode = $content->getMainNode(); if ($mainNode !== null) { $url = $renderer->getUri($mainNode->getUrl()); $parentNode = $mainNode->getParent(); if (null !== $parentNode) { $altTitle = $parentNode->getAltTitle(); $tag = !empty($altTitle) ? $altTitle : $parentNode->getTitle(); } } $renderer->assign('tag', $tag); $renderer->assign('url', $url); }
/** * Occur on classcontent.onflush events. * * @param \BackBee\Event\Event $event */ public static function onFlushContent(Event $event) { $content = $event->getTarget(); if (!$content instanceof AbstractClassContent) { return; } $application = $event->getApplication(); $em = $application->getEntityManager(); $uow = $em->getUnitOfWork(); if ($uow->isScheduledForDelete($content)) { return; } if (null !== ($page = $content->getMainNode())) { if (null !== $page->getMetaData()) { $newEvent = new Event($page, $content); $newEvent->setDispatcher($event->getDispatcher()); self::onFlushPage($newEvent); } } }
public static function onRender(Event $event) { $dispatcher = $event->getDispatcher(); $renderer = $event->getEventArgs(); $renderer->assign('keyword', null); if (null !== $dispatcher) { $application = $dispatcher->getApplication(); if (null === $application) { return; } $keywordloaded = $event->getTarget(); if (!is_a($renderer, 'BackBee\\Renderer\\AbstractRenderer')) { return; } $keyWord = $application->getEntityManager()->find('BackBee\\NestedNode\\KeyWord', $keywordloaded->value); if (!is_null($keyWord)) { $renderer->assign('keyword', $keyWord); } } }
public static function onPrerenderContent(Event $event) { $dispatcher = $event->getDispatcher(); if (null === ($application = $dispatcher->getApplication())) { return; } if (null === ($token = $application->getBBUserToken())) { return; } $renderer = $event->getEventArgs(); if (!is_a($renderer, 'BackBee\\Renderer\\AbstractRenderer')) { return; } $content = $renderer->getObject(); if (!is_a($content, 'BackBee\\ClassContent\\AbstractClassContent')) { return; } $em = $application->getEntityManager(); if (null !== ($revision = $em->getRepository('BackBee\\ClassContent\\Revision')->getDraft($content, $token))) { $content->setDraft($revision); $application->debug(sprintf('Revision found for `%s` content and `%s` user', $content->getUid(), $token->getUsername())); } if (!$content instanceof ContentSet) { foreach ($content->getData() as $key => $subcontent) { if (null === $subcontent) { $contenttype = $content->getAcceptedType($key); if (0 === strpos($contenttype, 'BackBee\\ClassContent\\')) { if (null === $content->getDraft()) { $revision = $em->getRepository('BackBee\\ClassContent\\Revision')->getDraft($content, $token, true); $content->setDraft($revision); } $content->{$key} = new $contenttype(); } } } } }
public static function onRemoveElementFile(Event $event) { $dispatcher = $event->getDispatcher(); $application = $dispatcher->getApplication(); try { $content = $event->getEventArgs()->getEntity(); if (!$content instanceof ElementFile) { return; } $includePath = array($application->getStorageDir(), $application->getMediaDir()); if (null !== $application->getBBUserToken()) { $includePath[] = $application->getTemporaryDir(); } $filename = $content->path; File::resolveFilepath($filename, null, array('include_path' => $includePath)); @unlink($filename); } catch (\Exception $e) { $application->warning('Unable to delete file: ' . $e->getMessage()); } }
/** * Returns the current application. * * @param \BackBee\Event\Event $event * * @return \BackBee\BBApplication */ private static function _getApplication(Event $event) { if (null === self::$_application) { if (null !== $event->getDispatcher()) { self::$_application = $event->getDispatcher()->getApplication(); } } return self::$_application; }