src/Controller/NewsController.php line 29

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use Pimcore\Model\DataObject\News;
  4. use Symfony\Component\HttpFoundation\Request;
  5. use Symfony\Component\HttpFoundation\Response;
  6. use App\Website\LinkGenerator\NewsLinkGenerator;
  7. use App\Website\Navigation\BreadcrumbHelperService;
  8. use Knp\Component\Pager\PaginatorInterface;
  9. use Pimcore\Twig\Extension\Templating\HeadTitle;
  10. use Pimcore\Twig\Extension\Templating\Placeholder;
  11. use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
  12. use Symfony\Component\Routing\Annotation\Route;
  13. class NewsController extends BaseController
  14. {
  15.     const NEWS_DEFAULT_DOCUMENT_PROPERTY_NAME 'news_default_document';
  16.   
  17.      /**
  18.      * @param Request $request
  19.      *
  20.      * @return Response
  21.      *
  22.      * @throws \Exception
  23.      */
  24.      public function listingAction(Request $requestPaginatorInterface $paginator)
  25.     {
  26.         $newsListing = new News\Listing();
  27.         $newsListing->setOrderKey('publish_date');
  28.         $newsListing->setOrder('DESC');
  29.         $paginator $paginator->paginate(
  30.             $newsListing,
  31.             $request->get('page'1),
  32.             6
  33.         );
  34.         return $this->render('news/listing.html.twig', [
  35.             'newsListing' => $paginator,
  36.             'paginationVariables' => $paginator->getPaginationData()
  37.         ]);
  38.       //  return $this->render('news/listing.html.twig', ['newsListing' => $newsListing]);
  39.     }
  40.     /**
  41.       * @Route("{path}/{newstitle}-nid{news}", name="news-detail", defaults={"path"=""}, requirements={"path"=".*?", "newstitle"="[\w-]+", "news"="\d+"})
  42.      *
  43.      * @param Request $request
  44.      * @param HeadTitle $headTitleHelper
  45.      * @param Placeholder $placeholderHelper
  46.      * @param NewsLinkGenerator $newsLinkGenerator
  47.      * @param BreadcrumbHelperService $breadcrumbHelperService
  48.      *
  49.      * @return Response
  50.      */
  51.     public function detailAction(Request $requestHeadTitle $headTitleHelperPlaceholder $placeholderHelperNewsLinkGenerator $newsLinkGeneratorBreadcrumbHelperService $breadcrumbHelperService)
  52.     {
  53.         $news News::getById($request->get('news'));
  54.         //$news = News::getById(4);
  55.         if (!($news instanceof News && ($news->isPublished() || $this->verifyPreviewRequest($request$news)))) {
  56.             throw new NotFoundHttpException('News not found.');
  57.         }
  58.         $headTitleHelper($news->getTitle());
  59.         $breadcrumbHelperService->enrichNewsPage($news);
  60.         $placeholderHelper('canonical')->set($newsLinkGenerator->generate($news, ['document' => $this->document->getProperty(self::NEWS_DEFAULT_DOCUMENT_PROPERTY_NAME)]));
  61.         return $this->render('news/detail.html.twig', [
  62.             'news' => $news
  63.         ]);
  64.     }
  65.     /**
  66.       * @Route("/News-Events/News/{path}{newstitle}", name="news-oldpath", defaults={"newstitle"="","path"=""}, requirements={"path"=".*?", "newstitle"="[\w-]+"})
  67.      *
  68.      * @param Request $request
  69.      * @param HeadTitle $headTitleHelper
  70.      * @param Placeholder $placeholderHelper
  71.      * @param NewsLinkGenerator $newsLinkGenerator
  72.      * @param BreadcrumbHelperService $breadcrumbHelperService
  73.      *
  74.      * @return Response
  75.      */
  76.     public function titleAction(Request $requestHeadTitle $headTitleHelperPlaceholder $placeholderHelperNewsLinkGenerator $newsLinkGeneratorBreadcrumbHelperService $breadcrumbHelperService)
  77.     {
  78.         //return '/News-Events/News/CESSDA/' . $request->get('newstitle');
  79.          
  80.         $news News::getByOld_path('News-Events/News/' $request->get('path') . $request->get('newstitle'), ['limit' => 1]);
  81.         //$news = News::getByOld_path('News-Events/News/CESSDA/Academy-of-Finland-awards-funding-for-FSD-to-develop-services-for-researchers',   ['limit' => 1]);
  82.         $document \Pimcore\Model\Document::getById(43);
  83.         if (!($news instanceof News && ($news->isPublished() || $this->verifyPreviewRequest($request$news)))) {
  84.             throw new NotFoundHttpException('News not found.');
  85.         }
  86.         $headTitleHelper($news->getTitle());
  87.         $breadcrumbHelperService->enrichNewsPage($news);
  88.        // $placeholderHelper('canonical')->set($newsLinkGenerator->generate($news, ['document' => $this->document->getProperty(self::NEWS_DEFAULT_DOCUMENT_PROPERTY_NAME)]));
  89.         $placeholderHelper('canonical')->set($newsLinkGenerator->generate($news, ['document' => $document]));
  90.         return $this->render('news/detail.html.twig', [
  91.             'news' => $news,
  92.             'document' => $document
  93.         ]);
  94.     }
  95. }