vendor/store.shopware.com/h1webblog/src/Storefront/Controller/BlogController.php line 81

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. namespace H1web\Blog\Storefront\Controller;
  3. use Shopware\Storefront\Controller\StorefrontController;
  4. use Shopware\Core\Content\Cms\Exception\PageNotFoundException;
  5. use Shopware\Core\Framework\Routing\Annotation\RouteScope;
  6. use Shopware\Core\Framework\Routing\Exception\MissingRequestParameterException;
  7. use Shopware\Core\System\SalesChannel\SalesChannelContext;
  8. use Shopware\Storefront\Framework\Cache\Annotation\HttpCache;
  9. use H1web\Blog\Storefront\Page\Blog\BlogPageLoader;
  10. use H1web\Blog\Storefront\Page\Tag\TagPageLoader;
  11. use Symfony\Component\HttpFoundation\Request;
  12. use Symfony\Component\HttpFoundation\Response;
  13. use Symfony\Component\Routing\Annotation\Route;
  14. /**
  15.  * @RouteScope(scopes={"storefront"})
  16.  */
  17. class BlogController extends StorefrontController
  18. {
  19.     /**
  20.      * @var BlogPageLoader
  21.      */
  22.     private $blogPageLoader;
  23.     /**
  24.      * @var TagPageLoader
  25.      */
  26.     private $tagPageLoader;
  27.     public function __construct(
  28.         BlogPageLoader $blogPageLoader,
  29.         TagPageLoader $tagPageLoader
  30.     ) {
  31.         $this->blogPageLoader $blogPageLoader;
  32.         $this->tagPageLoader $tagPageLoader;
  33.     }
  34.     /**
  35.      * Route for a tag overview page
  36.      *
  37.      * @HttpCache()
  38.      * @Route("/h1webblog/tag/{tagId}", name="frontend.h1webblog.tag_overview", methods={"GET"})
  39.      *
  40.      * @throws MissingRequestParameterException
  41.      * @throws PageNotFoundException
  42.      */
  43.     public function renderTagOverviewPage(string $tagIdRequest $requestSalesChannelContext $salesChannelContext): Response
  44.     {
  45.         if (!$tagId) {
  46.             throw new MissingRequestParameterException('Parameter tagId missing');
  47.         }
  48.         $tagPage $this->tagPageLoader->load($tagId$request$salesChannelContext);
  49.         return $this->renderStorefront(
  50.             '@Storefront/storefront/page/h1web_blog/tag_overview.html.twig',
  51.             [
  52.                 'page' => $tagPage
  53.             ]
  54.         );
  55.     }
  56.     /**
  57.      * Route for a single blog page
  58.      *
  59.      * @HttpCache()
  60.      * @Route("/h1webblog/{id}", name="frontend.h1webblog.blog", methods={"GET"})
  61.      *
  62.      * @throws MissingRequestParameterException
  63.      * @throws PageNotFoundException
  64.      */
  65.     public function renderSinglePage(string $idRequest $requestSalesChannelContext $salesChannelContext): Response
  66.     {
  67.         if (!$id) {
  68.             throw new MissingRequestParameterException('Parameter id missing');
  69.         }
  70.         $blogPage $this->blogPageLoader->load($id$request$salesChannelContext);
  71.         if (!$blogPage->getCmsPage()) {
  72.             return $this->renderStorefront('@Storefront/storefront/page/h1web_blog/index.html.twig', ['page' => $blogPage]);
  73.         }
  74.         return $this->renderStorefront('@Storefront/storefront/page/content/blog-detail.html.twig', ['page' => $blogPage]);
  75.     }
  76. }