src/Controller/BigPipeController.php | 53 +++++------------------------------- 1 file changed, 7 insertions(+), 46 deletions(-) diff --git a/src/Controller/BigPipeController.php b/src/Controller/BigPipeController.php index 6b6587d..a20925a 100644 --- a/src/Controller/BigPipeController.php +++ b/src/Controller/BigPipeController.php @@ -7,56 +7,16 @@ namespace Drupal\big_pipe\Controller; -use Drupal\Core\DependencyInjection\ContainerInjectionInterface; use Drupal\Core\Routing\LocalRedirectResponse; -use Drupal\Core\Routing\RedirectDestinationInterface; -use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\HttpFoundation\Cookie; -use Symfony\Component\HttpFoundation\RequestStack; +use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException; use Symfony\Component\HttpKernel\Exception\HttpException; /** * Returns responses for BigPipe module routes. */ -class BigPipeController implements ContainerInjectionInterface { - - /** - * The request stack. - * - * @var \Symfony\Component\HttpFoundation\RequestStack - */ - protected $requestStack; - - /** - * The redirect destination service. - * - * @var \Drupal\Core\Routing\RedirectDestinationInterface - */ - protected $redirectDestination; - - /** - * Constructs a new BigPipeController. - * - * @param \Symfony\Component\HttpFoundation\RequestStack - * The request stack. - * @param \Drupal\Core\Routing\RedirectDestinationInterface $redirect_destination - * The redirect destination service. - */ - public function __construct(RequestStack $request_stack, RedirectDestinationInterface $redirect_destination) { - $this->requestStack = $request_stack; - $this->redirectDestination = $redirect_destination; - } - - /** - * {@inheritdoc} - */ - public static function create(ContainerInterface $container) { - return new static( - $container->get('request_stack'), - $container->get('redirect.destination') - ); - } +class BigPipeController { /** * Sets a 'big_pipe_nojs' cookie if there is a session. @@ -65,6 +25,9 @@ class BigPipeController implements ContainerInjectionInterface { * accessed automatically when that's the case thanks to * big_pipe_page_attachments(). * + * @param \Symfony\Component\HttpFoundation\Request $request + * The current request. + * * @return \Drupal\Core\Routing\LocalRedirectResponse * A response that sets the 'big_pipe_nojs' cookie and redirects back to the * original location. @@ -73,15 +36,13 @@ class BigPipeController implements ContainerInjectionInterface { * Thrown when the big_pipe_nojs cookie is already set (to prevent a * redirect loop) or when there is no session (in which case BigPipe is not * enabled anyway). - * * @throws \Symfony\Component\HttpKernel\Exception\HttpException * Thrown when the original location is missing, i.e. when no 'destination' * query argument is set. * * @see \Drupal\big_pipe\Render\Placeholder\BigPipeStrategy */ - public function setNoJsCookie() { - $request = $this->requestStack->getCurrentRequest(); + public function setNoJsCookie(Request $request) { if ($request->cookies->has('big_pipe_nojs') || $request->getSession() === NULL) { throw new AccessDeniedHttpException(); } @@ -90,7 +51,7 @@ class BigPipeController implements ContainerInjectionInterface { throw new HttpException(500, 'The original location is missing.'); } - $response = new LocalRedirectResponse($this->redirectDestination->get()); + $response = new LocalRedirectResponse($request->query->get('destination')); $response->headers->setCookie(new Cookie('big_pipe_nojs', TRUE)); return $response; }