/** * {@inheritdoc} */ public function isApplicable() { // Remove on Admin routes. $is_admin_route = $this->adminContext->isAdminRoute(); // Remove on Block Demo page. $is_admin_demo_route = $this->routeMatch->getRouteName() === 'block.admin_demo'; // @todo Check if there is actually a different admin theme. // https://www.drupal.org/node/2784853 return $this->account->hasPermission('administer blocks') && !$is_admin_route && !$is_admin_demo_route; }
/** * {@inheritdoc} */ public function applies($definition, $name, Route $route) { if (parent::applies($definition, $name, $route)) { // As we only want to override EntityConverter for ConfigEntities, find // out whether the current entity is a ConfigEntity. $entity_type_id = substr($definition['type'], strlen('entity:')); $entity_type = $this->entityManager->getDefinition($entity_type_id); if ($entity_type->isSubclassOf('\\Drupal\\Core\\Config\\Entity\\ConfigEntityInterface')) { return $this->adminContext->isAdminRoute($route); } } return FALSE; }
/** * Checks whether the given path is an administrative one. * * @param \Symfony\Component\HttpFoundation\Request $request * The request object. * * @return bool * TRUE if the path is administrative, FALSE otherwise. */ protected function isAdminPath(Request $request) { $result = FALSE; if ($request && $this->adminContext) { // If called from an event subscriber, the request may not have the route // object yet (it is still being built), so use the router to look up // based on the path. $route_match = $this->stackedRouteMatch->getRouteMatchFromRequest($request); if ($route_match && !($route_object = $route_match->getRouteObject())) { try { // Process the path as an inbound path. This will remove any language // prefixes and other path components that inbound processing would // clear out, so we can attempt to load the route clearly. $path = $this->pathProcessorManager->processInbound(urldecode(rtrim($request->getPathInfo(), '/')), $request); $attributes = $this->router->match($path); } catch (ResourceNotFoundException $e) { return FALSE; } catch (AccessDeniedHttpException $e) { return FALSE; } $route_object = $attributes[RouteObjectInterface::ROUTE_OBJECT]; } $result = $this->adminContext->isAdminRoute($route_object); } return $result; }
/** * Checks whether a give path matches the ng-lightbox path rules. * This function checks both internal paths and aliased paths. * * @param \Drupal\Core\Url $url * The Url object. * * @return bool * TRUE if it matches the given rules. */ public function isNgLightboxEnabledPath(Url $url) { // No lightbox on external Urls. if ($url->isExternal()) { return FALSE; } // If we don't want to enable the Lightbox on admin pages. if ($this->config->get('skip_admin_paths') && $this->adminContext->isAdminRoute()) { return FALSE; } // @TODO, decide whether we want to try and support paths or to adopt routes // like core is trying to force us into. $path = strtolower($url->toString()); // We filter out empty paths because some modules (such as Media) use // theme_link() to generate links with empty paths. if (empty($path)) { return FALSE; } // Remove the base path. if ($base_path = \Drupal::request()->getBasePath()) { $path = substr($path, strlen($base_path)); } // Check the cache, see if we've handled this before. if (isset($this->matches[$path])) { return $this->matches[$path]; } // Normalise the patterns as well so they match the normalised paths. $patterns = strtolower($this->config->get('patterns')); // Check for internal paths first which is much quicker than the alias lookup. if ($this->pathMatcher->matchPath($path, $patterns)) { $this->matches[$path] = TRUE; } else { // Now check for aliases paths. $aliased_path = strtolower($this->aliasManager->getAliasByPath($path)); if ($path != $aliased_path && $this->pathMatcher->matchPath($aliased_path, $patterns)) { $this->matches[$path] = TRUE; } else { // No match. $this->matches[$path] = FALSE; } } return $this->matches[$path]; }
/** * Checks whether the given path is an administrative one. * * @param \Symfony\Component\HttpFoundation\Request $request * The request object. * * @return bool * TRUE if the path is administrative, FALSE otherwise. */ public function isAdminPath(Request $request) { $result = FALSE; if ($request && $this->adminContext) { // If called from an event subscriber, the request may not the route info // yet, so use the router to look up the path first. if (!($route_object = $request->attributes->get(RouteObjectInterface::ROUTE_OBJECT))) { $attributes = $this->router->match('/' . urldecode(trim($request->getPathInfo(), '/'))); $route_object = $attributes[RouteObjectInterface::ROUTE_OBJECT]; } $result = $this->adminContext->isAdminRoute($route_object); } return $result; }
/** * {@inheritdoc} */ public function applies($definition, $name, Route $route) { if (parent::applies($definition, $name, $route)) { $entity_type_id = substr($definition['type'], strlen('entity:')); // If the entity type is dynamic, defer checking to self::convert(). if (strpos($entity_type_id, '{') === 0) { return TRUE; } // As we only want to override EntityConverter for ConfigEntities, find // out whether the current entity is a ConfigEntity. $entity_type = $this->entityManager->getDefinition($entity_type_id); if ($entity_type->isSubclassOf('\\Drupal\\Core\\Config\\Entity\\ConfigEntityInterface')) { return $this->adminContext->isAdminRoute($route); } } return FALSE; }
/** * {@inheritdoc} */ public function applies(RouteMatchInterface $route_match) { return $this->entityManager->hasHandler('user_role', 'storage') && $this->user->hasPermission('view the administration theme') && $this->adminContext->isAdminRoute($route_match->getRouteObject()); }