namespace Drupal\magazine_home_redirect\EventSubscriber;
use Symfony\Component\HttpKernel\KernelEvents;
use Symfony\Component\HttpKernel\Event\RequestEvent;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Drupal\Core\Path\PathMatcherInterface;
use Drupal\Core\Routing\RouteMatchInterface;
use Symfony\Component\HttpKernel\HttpKernelInterface;
class MagazineHomepageRedirectSubscriber implements EventSubscriberInterface {
protected $httpKernel;
public function __construct(HttpKernelInterface $http_kernel) {
$this->httpKernel = $http_kernel;
}
public static function getSubscribedEvents() {
return [
KernelEvents::REQUEST => ['onRequest', 50],
];
}
public function onRequest(RequestEvent $event) {
$request = $event->getRequest();
$host = $request->getHost();
$path = $request->getPathInfo();
if (preg_match('#^magazine\.nws\.engineering$#', $host) && preg_match('#^/(en|de|it)/?$#', $path, $matches)) {
$lang = $matches[1];
$sub_request = Request::create("/$lang/nws-magazine", 'GET', [], $request->cookies->all(), [], $request->server->all());
$response = $this->httpKernel->handle($sub_request, HttpKernelInterface::SUB_REQUEST);
$event->setResponse($response);
}
}
}
The website encountered an unexpected error. Try again later.
Error: Class "Drupal\magazine_home_redirect\EventSubscriber\MagazineHomepageRedirectSubscriber" not found in Drupal\Component\DependencyInjection\Container->createService() (line 259 of core/lib/Drupal/Component/DependencyInjection/Container.php).