vendor/store.shopware.com/moorlmagazine/src/Storefront/Controller/MagazineArticleController.php line 59

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. namespace MoorlMagazine\Storefront\Controller;
  3. use MoorlMagazine\Storefront\Page\MagazineArticle\MagazineArticlePageLoader;
  4. use Shopware\Core\Framework\Routing\Annotation\RouteScope;
  5. use Shopware\Core\System\SalesChannel\SalesChannelContext;
  6. use Shopware\Storefront\Controller\StorefrontController;
  7. use Shopware\Storefront\Framework\Cache\Annotation\HttpCache;
  8. use Symfony\Component\HttpFoundation\Request;
  9. use Symfony\Component\HttpFoundation\Response;
  10. use Symfony\Component\Routing\Annotation\Route;
  11. /**
  12.  * @Route(defaults={"_routeScope"={"storefront"}})
  13.  */
  14. class MagazineArticleController extends StorefrontController
  15. {
  16.     private MagazineArticlePageLoader $magazineArticlePageLoader;
  17.     public function __construct(
  18.         MagazineArticlePageLoader $magazineArticlePageLoader
  19.     ) {
  20.         $this->magazineArticlePageLoader $magazineArticlePageLoader;
  21.     }
  22.     /**
  23.      * @HttpCache()
  24.      * @Route("/moorl-magazine/article/{magazineArticleId}", name="moorl.magazine.article", methods={"GET"})
  25.      */
  26.     public function index(SalesChannelContext $contextRequest $request): Response
  27.     {
  28.         $page $this->magazineArticlePageLoader->load($request$context);
  29.         $magazineArticle $page->getMagazineArticle();
  30.         /* If a CMS page for content is defined */
  31.         if ($magazineArticle->getContentCmsPageId() && $magazineArticle->hasExtension('contentCmsPage')) {
  32.             $contentCmsPage $magazineArticle->getExtension('contentCmsPage');
  33.             $content $this->renderView('@Storefront/storefront/page/content/detail.html.twig', [
  34.                 'cmsPage' => $contentCmsPage
  35.             ]);
  36.             $magazineArticle->addTranslated('content'$content);
  37.             $magazineArticle->setContent($content);
  38.             $magazineArticle->removeExtension('contentCmsPage');
  39.             $page $this->magazineArticlePageLoader->reload($request$page$context);
  40.         }
  41.         if (!$page->getCmsPage()) {
  42.             return $this->renderStorefront('@Storefront/plugin/moorl-magazine/page/article.html.twig', [
  43.                 'page' => $page
  44.             ]);
  45.         }
  46.         return $this->renderStorefront('@Storefront/plugin/moorl-magazine/page/content/magazine-article-detail.html.twig', [
  47.             'page' => $page
  48.         ]);
  49.     }
  50. }