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