Upgraded drupal core with security updates
[yaffs-website] / web / core / lib / Drupal / Core / Routing / AdminContext.php
1 <?php
2
3 namespace Drupal\Core\Routing;
4
5 use Symfony\Component\Routing\Route;
6
7 /**
8  * Provides a helper class to determine whether the route is an admin one.
9  */
10 class AdminContext {
11
12   /**
13    * The route match.
14    *
15    * @var \Drupal\Core\Routing\RouteMatchInterface
16    */
17   protected $routeMatch;
18
19   /**
20    * Construct a new admin context helper instance.
21    *
22    * @param \Drupal\Core\Routing\RouteMatchInterface $route_match
23    *   The route match.
24    */
25   public function __construct(RouteMatchInterface $route_match) {
26     $this->routeMatch = $route_match;
27   }
28
29   /**
30    * Determines whether the active route is an admin one.
31    *
32    * @param \Symfony\Component\Routing\Route $route
33    *   (optional) The route to determine whether it is an admin one. Per default
34    *   this falls back to the route object on the active request.
35    *
36    * @return bool
37    *   Returns TRUE if the route is an admin one, otherwise FALSE.
38    */
39   public function isAdminRoute(Route $route = NULL) {
40     if (!$route) {
41       $route = $this->routeMatch->getRouteObject();
42       if (!$route) {
43         return FALSE;
44       }
45     }
46     return (bool) $route->getOption('_admin_route');
47   }
48
49 }