src/Controller/NewsController.php line 71

Open in your IDE?
  1. <?php
  2. /**
  3.  * Pimcore
  4.  *
  5.  * This source file is available under two different licenses:
  6.  * - GNU General Public License version 3 (GPLv3)
  7.  * - Pimcore Enterprise License (PEL)
  8.  * Full copyright and license information is available in
  9.  * LICENSE.md which is distributed with this source code.
  10.  *
  11.  *  @copyright  Copyright (c) Pimcore GmbH (http://www.pimcore.org)
  12.  *  @license    http://www.pimcore.org/license     GPLv3 and PEL
  13.  */
  14. namespace App\Controller;
  15. use App\Website\LinkGenerator\NewsLinkGenerator;
  16. use App\Website\Navigation\BreadcrumbHelperService;
  17. use Knp\Component\Pager\PaginatorInterface;
  18. use Pimcore\Model\DataObject\News;
  19. use Pimcore\Twig\Extension\Templating\HeadTitle;
  20. use Pimcore\Twig\Extension\Templating\Placeholder;
  21. use Symfony\Component\HttpFoundation\Request;
  22. use Symfony\Component\HttpFoundation\Response;
  23. use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
  24. use Symfony\Component\Routing\Annotation\Route;
  25. class NewsController extends BaseController
  26. {
  27.     const NEWS_DEFAULT_DOCUMENT_PROPERTY_NAME 'news_default_document';
  28.     /**
  29.      * @param Request $request
  30.      *
  31.      * @return Response
  32.      *
  33.      * @throws \Exception
  34.      */
  35.     public function listingAction(Request $requestPaginatorInterface $paginator)
  36.     {
  37.         // get a list of news objects and order them by date
  38.         $newsList = new News\Listing();
  39.         $newsList->setOrderKey('date');
  40.         $newsList->setOrder('DESC');
  41.         $paginator $paginator->paginate(
  42.             $newsList,
  43.             $request->get('page'1),
  44.             6
  45.         );
  46.         return $this->render('news/listing.html.twig', [
  47.             'news' => $paginator,
  48.             'paginationVariables' => $paginator->getPaginationData()
  49.         ]);
  50.     }
  51.     /**
  52.      * @Route("{path}/{newstitle}~n{news}", name="news-detail", defaults={"path"=""}, requirements={"path"=".*?", "newstitle"="[\w-]+", "news"="\d+"})
  53.      *
  54.      * @param Request $request
  55.      * @param HeadTitle $headTitleHelper
  56.      * @param Placeholder $placeholderHelper
  57.      * @param NewsLinkGenerator $newsLinkGenerator
  58.      * @param BreadcrumbHelperService $breadcrumbHelperService
  59.      *
  60.      * @return Response
  61.      */
  62.     public function detailAction(Request $requestHeadTitle $headTitleHelperPlaceholder $placeholderHelperNewsLinkGenerator $newsLinkGeneratorBreadcrumbHelperService $breadcrumbHelperService)
  63.     {
  64.         $news News::getById($request->get('news'));
  65.         if (!($news instanceof News && ($news->isPublished() || $this->verifyPreviewRequest($request$news)))) {
  66.             throw new NotFoundHttpException('News not found.');
  67.         }
  68.         $headTitleHelper($news->getTitle());
  69.         $breadcrumbHelperService->enrichNewsPage($news);
  70.         $placeholderHelper('canonical')->set($newsLinkGenerator->generate($news, ['document' => $this->document->getProperty(self::NEWS_DEFAULT_DOCUMENT_PROPERTY_NAME)]));
  71.         return $this->render('news/detail.html.twig', [
  72.             'news' => $news
  73.         ]);
  74.     }
  75.     /**
  76.      * @param Request $request
  77.      *
  78.      * @return \Symfony\Component\HttpFoundation\Response
  79.      */
  80.     public function newsTeaserAction(Request $request)
  81.     {
  82.         $paramsBag = [];
  83.         if ($request->get('type') == 'object') {
  84.             $news News::getById($request->get('id'));
  85.             $paramsBag['news'] = $news;
  86.             return $this->render('news/news_teaser.html.twig'$paramsBag);
  87.         }
  88.         throw new NotFoundHttpException('News not found.');
  89.     }
  90.     /**
  91.      * @param Request $request
  92.      *
  93.      * @return \Symfony\Component\HttpFoundation\Response
  94.      */
  95.     public function emailNewsTeaserAction(Request $requestNewsLinkGenerator $newsLinkGenerator)
  96.     {
  97.         $paramsBag = [];
  98.         if ($request->get('type') == 'object') {
  99.             $news News::getById($request->get('id'));
  100.             $paramsBag['news'] = $news;
  101.             $paramsBag['detailLink'] = $newsLinkGenerator->generate($news, ['document' => $this->document->getProperty('news_default_document')]);
  102.             return $this->render('news/email_news_teaser.html.twig'$paramsBag);
  103.         }
  104.         throw new NotFoundHttpException('News not found.');
  105.     }
  106. }