Chris@0: adminContext = $admin_context; Chris@0: $this->router = $router; Chris@0: $this->pathProcessorManager = $path_processor_manager; Chris@0: $this->stackedRouteMatch = $stacked_route_match; Chris@0: } Chris@0: Chris@0: /** Chris@0: * {@inheritdoc} Chris@0: */ Chris@0: public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) { Chris@0: return new static( Chris@0: $container->get('router.admin_context'), Chris@0: $container->get('router'), Chris@0: $container->get('path_processor_manager'), Chris@0: $container->get('current_route_match') Chris@0: ); Chris@0: } Chris@0: Chris@0: /** Chris@0: * {@inheritdoc} Chris@0: */ Chris@0: public function getLangcode(Request $request = NULL) { Chris@0: $langcode = NULL; Chris@0: Chris@0: // User preference (only for administrators). Chris@0: if ($this->currentUser->hasPermission('access administration pages') && ($preferred_admin_langcode = $this->currentUser->getPreferredAdminLangcode(FALSE)) && $this->isAdminPath($request)) { Chris@0: $langcode = $preferred_admin_langcode; Chris@0: } Chris@0: Chris@0: // Not an admin, no admin language preference or not on an admin path. Chris@0: return $langcode; Chris@0: } Chris@0: Chris@0: /** Chris@0: * Checks whether the given path is an administrative one. Chris@0: * Chris@0: * @param \Symfony\Component\HttpFoundation\Request $request Chris@0: * The request object. Chris@0: * Chris@0: * @return bool Chris@0: * TRUE if the path is administrative, FALSE otherwise. Chris@0: */ Chris@0: protected function isAdminPath(Request $request) { Chris@0: $result = FALSE; Chris@0: if ($request && $this->adminContext) { Chris@0: // If called from an event subscriber, the request may not have the route Chris@0: // object yet (it is still being built), so use the router to look up Chris@0: // based on the path. Chris@0: $route_match = $this->stackedRouteMatch->getRouteMatchFromRequest($request); Chris@0: if ($route_match && !$route_object = $route_match->getRouteObject()) { Chris@0: try { Chris@17: // Some inbound path processors make changes to the request. Make a Chris@17: // copy as we're not actually routing the request so we do not want to Chris@17: // make changes. Chris@17: $cloned_request = clone $request; Chris@0: // Process the path as an inbound path. This will remove any language Chris@0: // prefixes and other path components that inbound processing would Chris@0: // clear out, so we can attempt to load the route clearly. Chris@17: $path = $this->pathProcessorManager->processInbound(urldecode(rtrim($cloned_request->getPathInfo(), '/')), $cloned_request); Chris@0: $attributes = $this->router->match($path); Chris@0: } Chris@0: catch (ResourceNotFoundException $e) { Chris@0: return FALSE; Chris@0: } Chris@0: catch (AccessDeniedHttpException $e) { Chris@0: return FALSE; Chris@0: } Chris@0: $route_object = $attributes[RouteObjectInterface::ROUTE_OBJECT]; Chris@0: } Chris@0: $result = $this->adminContext->isAdminRoute($route_object); Chris@0: } Chris@0: return $result; Chris@0: } Chris@0: Chris@0: }