config = $config; $this->appState = $appState; $this->storeManager = $storeManager; $this->storeCodeMapper = $storeCodeMapper; $this->urlPathConverter = $urlPathConverter; $this->request = $request; $this->logger = $logger; } /** * @param mixed|null $routePath * @param mixed|null $routeParams */ public function afterGetUrl(Url $subject, string $result, $routePath = null, $routeParams = null): string { if (!$this->config->isEnabled() || !$this->isFrontendArea()) { return $result; } $storeCode = null; try { $storeCode = $this->storeManager->getStore()->getCode(); $language = $this->storeCodeMapper->languageFromStoreCode($storeCode); if ($language === null) { return $result; } return $this->urlPathConverter->toLanguageUrl($result, $language); } catch (\Throwable $exception) { $this->logger->error( '[LanguageUrlStoreResolver] Failed to convert generated URL.', [ 'path' => $this->request instanceof HttpRequest ? $this->request->getPathInfo() : null, 'request_uri' => $this->request instanceof HttpRequest ? $this->request->getRequestUri() : null, 'market' => null, 'store_code' => $storeCode, 'exception' => $exception, ] ); } return $result; } private function isFrontendArea(): bool { try { return $this->appState->getAreaCode() === Area::AREA_FRONTEND; } catch (\Throwable $exception) { return false; } } }