scopeConfig = $scopeConfig; $this->url = $url; } /** * Redirect newsletter routes to 404 when newsletter module is disabled. * * @param Observer $observer */ public function execute(Observer $observer) : void { if (!$this->scopeConfig->getValue( self::XML_PATH_NEWSLETTER_ACTIVE, ScopeInterface::SCOPE_STORE ) ) { $defaultNoRouteUrl = $this->scopeConfig->getValue( 'web/default/no_route', ScopeInterface::SCOPE_STORE ); $redirectUrl = $this->url->getUrl($defaultNoRouteUrl); $observer->getControllerAction() ->getResponse() ->setRedirect($redirectUrl); } } }