src/Action/PressSite/Product/UpcomingMoviesAction.php line 18

Open in your IDE?
  1. <?php
  2. namespace App\Action\PressSite\Product;
  3. use App\Action\PressSite\DomainAwareAction;
  4. use App\Contract\PressSite\Language\Switcher\GenericActionInterface;
  5. use App\Service\PressSite\Content\Callback\UpcomingMoviesCallback;
  6. use App\Service\PressSite\Content\MovieContentBuilder;
  7. use App\Service\PressSite\DomainAwareManager;
  8. use Symfony\Component\HttpFoundation\Request;
  9. use Symfony\Component\HttpFoundation\Response;
  10. use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
  11. use Twig\Environment;
  12. /**
  13.  * Class UpcomingMoviesAction.
  14.  */
  15. class UpcomingMoviesAction extends DomainAwareAction implements GenericActionInterface
  16. {
  17.     /**
  18.      * The custom content builder responsible for returning the list with new movies.
  19.      *
  20.      * @var \App\Service\PressSite\Content\MovieContentBuilder
  21.      */
  22.     private $contentBuilder;
  23.     public function __construct(
  24.         Environment $twig,
  25.         DomainAwareManager $domainAwareManager,
  26.         MovieContentBuilder $contentBuilder
  27.     ) {
  28.         parent::__construct($twig$domainAwareManager);
  29.         $this->contentBuilder $contentBuilder;
  30.     }
  31.     /**
  32.      * Responsible for returning a collection of products.
  33.      *
  34.      * @param \Symfony\Component\HttpFoundation\Request $request
  35.      *   The current request object
  36.      *
  37.      * @return \Symfony\Component\HttpFoundation\Response
  38.      *   The response object
  39.      */
  40.     public function __invoke(Request $request): Response
  41.     {
  42.         // Theatrical sites do not have upcoming movies content page.
  43.         if ($this->getDomainManager()->getCurrentByHostnameAndLocale()->isBroadcastType()) {
  44.             throw new NotFoundHttpException('Page not found');
  45.         }
  46.         $this->contentBuilder->addCallback(new UpcomingMoviesCallback());
  47.         return $this->render('press_site/actions/movies/upcoming_movies.html.twig', [
  48.             'collection' => $this->contentBuilder->getContent(
  49.                 100,
  50.                 MovieContentBuilder::SORT_ORDER_ASC,
  51.                 MovieContentBuilder::SORT_BY_DATE_TYPE
  52.             ),
  53.         ]);
  54.     }
  55. }