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

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