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

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