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

  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\Log\Package;
  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. /**
  13.  * Do not use direct or indirect repository calls in a PageLoader. Always use a store-api route to get or put data.
  14.  */
  15. #[Package('content')]
  16. class LandingPageLoader
  17. {
  18.     /**
  19.      * @internal
  20.      */
  21.     public function __construct(
  22.         private readonly GenericPageLoaderInterface $genericPageLoader,
  23.         private readonly AbstractLandingPageRoute $landingPageRoute,
  24.         private readonly EventDispatcherInterface $eventDispatcher
  25.     ) {
  26.     }
  27.     /**
  28.      * @throws PageNotFoundException
  29.      */
  30.     public function load(Request $requestSalesChannelContext $context): LandingPage
  31.     {
  32.         $landingPageId $request->attributes->get('landingPageId');
  33.         if (!$landingPageId) {
  34.             throw new MissingRequestParameterException('landingPageId''/landingPageId');
  35.         }
  36.         $landingPage $this->landingPageRoute->load($landingPageId$request$context)->getLandingPage();
  37.         if ($landingPage->getCmsPage() === null) {
  38.             throw new PageNotFoundException($landingPageId);
  39.         }
  40.         $page $this->genericPageLoader->load($request$context);
  41.         $page LandingPage::createFrom($page);
  42.         $page->setLandingPage($landingPage);
  43.         $metaInformation = new MetaInformation();
  44.         $metaTitle $landingPage->getMetaTitle() ?? $landingPage->getName();
  45.         $metaInformation->setMetaTitle($metaTitle ?? '');
  46.         $metaInformation->setMetaDescription($landingPage->getMetaDescription() ?? '');
  47.         $metaInformation->setMetaKeywords($landingPage->getKeywords() ?? '');
  48.         $page->setMetaInformation($metaInformation);
  49.         $this->eventDispatcher->dispatch(
  50.             new LandingPageLoadedEvent($page$context$request)
  51.         );
  52.         return $page;
  53.     }
  54. }