vendor/shopware/storefront/Page/LandingPage/LandingPageLoader.php line 45

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. namespace Shopware\Storefront\Page\LandingPage;
  3. use Shopware\Core\Content\Cms\Exception\PageNotFoundException;
  4. use Shopware\Core\Content\LandingPage\SalesChannel\AbstractLandingPageRoute;
  5. use Shopware\Core\Framework\Feature;
  6. use Shopware\Core\Framework\Routing\Exception\MissingRequestParameterException;
  7. use Shopware\Core\System\SalesChannel\SalesChannelContext;
  8. use Shopware\Storefront\Page\GenericPageLoaderInterface;
  9. use Shopware\Storefront\Page\MetaInformation;
  10. use Symfony\Component\EventDispatcher\EventDispatcherInterface;
  11. use Symfony\Component\HttpFoundation\Request;
  12. class LandingPageLoader
  13. {
  14.     /**
  15.      * @var GenericPageLoaderInterface
  16.      */
  17.     private $genericPageLoader;
  18.     /**
  19.      * @var AbstractLandingPageRoute
  20.      */
  21.     private $landingPageRoute;
  22.     private EventDispatcherInterface $eventDispatcher;
  23.     /**
  24.      * @internal
  25.      */
  26.     public function __construct(
  27.         GenericPageLoaderInterface $genericPageLoader,
  28.         AbstractLandingPageRoute $landingPageRoute,
  29.         EventDispatcherInterface $eventDispatcher
  30.     ) {
  31.         $this->genericPageLoader $genericPageLoader;
  32.         $this->landingPageRoute $landingPageRoute;
  33.         $this->eventDispatcher $eventDispatcher;
  34.     }
  35.     /**
  36.      * @throws PageNotFoundException
  37.      */
  38.     public function load(Request $requestSalesChannelContext $context): LandingPage
  39.     {
  40.         $landingPageId $request->attributes->get('landingPageId');
  41.         if (!$landingPageId) {
  42.             throw new MissingRequestParameterException('landingPageId''/landingPageId');
  43.         }
  44.         $landingPage $this->landingPageRoute->load($landingPageId$request$context)->getLandingPage();
  45.         if ($landingPage->getCmsPage() === null) {
  46.             throw new PageNotFoundException($landingPageId);
  47.         }
  48.         $page $this->genericPageLoader->load($request$context);
  49.         /** @var LandingPage $page */
  50.         $page LandingPage::createFrom($page);
  51.         /** @deprecated tag:v6.5.0 - LandingPage::cmsPage will be removed. Use LandingPage->getLandingPage()->getCmsPage() instead */
  52.         if (!Feature::isActive('v6.5.0.0')) {
  53.             $page->setCmsPage($landingPage->getCmsPage());
  54.         }
  55.         $page->setLandingPage($landingPage);
  56.         $metaInformation = new MetaInformation();
  57.         $metaTitle $landingPage->getMetaTitle() ?? $landingPage->getName();
  58.         $metaInformation->setMetaTitle($metaTitle ?? '');
  59.         $metaInformation->setMetaDescription($landingPage->getMetaDescription() ?? '');
  60.         $metaInformation->setMetaKeywords($landingPage->getKeywords() ?? '');
  61.         $page->setMetaInformation($metaInformation);
  62.         /* @deprecated tag:v6.5.0 remove the whole if branch */
  63.         if (!Feature::isActive('v6.5.0.0')) {
  64.             $page->setNavigationId($landingPage->getId());
  65.             $page->setCustomFields($landingPage->getCustomFields());
  66.         }
  67.         $this->eventDispatcher->dispatch(
  68.             new LandingPageLoadedEvent($page$context$request)
  69.         );
  70.         return $page;
  71.     }
  72. }