custom/plugins/NetzpBlog6/src/Controller/BlogController.php line 55

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. namespace NetzpBlog6\Controller;
  3. use Shopware\Core\Framework\Routing\Annotation\RouteScope;
  4. use Symfony\Component\Routing\Annotation\Route;
  5. use Shopware\Storefront\Framework\Cache\Annotation\HttpCache;
  6. use NetzpBlog6\Storefront\Page\BlogPageLoader;
  7. use Shopware\Core\Framework\Context;
  8. use Shopware\Core\System\SalesChannel\SalesChannelContext;
  9. use Shopware\Core\System\SystemConfig\SystemConfigService;
  10. use Shopware\Storefront\Controller\StorefrontController;
  11. use Symfony\Component\HttpFoundation\Request;
  12. use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
  13. use NetzpBlog6\Helper\BlogHelper;
  14. /**
  15.  * @RouteScope(scopes={"storefront"})
  16.  */
  17. class BlogController extends StorefrontController
  18. {
  19.     private $helper;
  20.     private $blogPageLoader;
  21.     private $config;
  22.     public function __construct(
  23.         BlogHelper $helper,
  24.         BlogPageLoader $blogPageLoader,
  25.         SystemConfigService $config)
  26.     {
  27.         $this->helper $helper;
  28.         $this->blogPageLoader $blogPageLoader;
  29.         $this->config $config;
  30.     }
  31.     /**
  32.      * @Route("/blog.rss", name="frontend.blog.feed", methods={"GET"})
  33.      */
  34.     public function getFeed(Request $requestSalesChannelContext $salesChannelContextContext $context)
  35.     {
  36.         $posts $this->helper->getPublicBlogPosts($salesChannelContext$contextnullnulltrue);
  37.         $response $this->renderStorefront('storefront/page/blog/feed.html.twig', [
  38.             'posts' => $posts
  39.         ]);
  40.         $response->headers->set('Content-Type''text/xml');
  41.         return $response;
  42.     }
  43.     /**
  44.      * @HttpCache()
  45.      * @Route("/blog/{postId}", name="frontend.blog.post", methods={"GET"})
  46.      */
  47.     public function getPost(Request $requestSalesChannelContext $salesChannelContextContext $context$postId)
  48.     {
  49.         $shariffIsActive $this->helper->isPluginActive('NetzpShariff6'$context);
  50.         $config $this->config->get('NetzpBlog6.config'$salesChannelContext->getSalesChannel()->getId());
  51.         $page $this->blogPageLoader->load($request$salesChannelContext$postId);
  52.         $template $page->isCmsPage() ? 'storefront/page/content/index.html.twig' 'storefront/page/blog/post.html.twig';
  53.         return $this->renderStorefront($template, [
  54.             'page'               => $page,
  55.             'post'               => $page->getPost(),
  56.             'config'             => $config,
  57.             'netzpShariffActive' => $shariffIsActive
  58.         ]);
  59.     }
  60. }