Mercurial > hg > isophonics-drupal-site
annotate core/lib/Drupal/Core/Routing/AdminContext.php @ 19:fa3358dc1485 tip
Add ndrum files
author | Chris Cannam |
---|---|
date | Wed, 28 Aug 2019 13:14:47 +0100 |
parents | 4c8ae668cc8c |
children |
rev | line source |
---|---|
Chris@0 | 1 <?php |
Chris@0 | 2 |
Chris@0 | 3 namespace Drupal\Core\Routing; |
Chris@0 | 4 |
Chris@0 | 5 use Symfony\Component\Routing\Route; |
Chris@0 | 6 |
Chris@0 | 7 /** |
Chris@0 | 8 * Provides a helper class to determine whether the route is an admin one. |
Chris@0 | 9 */ |
Chris@0 | 10 class AdminContext { |
Chris@0 | 11 |
Chris@0 | 12 /** |
Chris@0 | 13 * The route match. |
Chris@0 | 14 * |
Chris@0 | 15 * @var \Drupal\Core\Routing\RouteMatchInterface |
Chris@0 | 16 */ |
Chris@0 | 17 protected $routeMatch; |
Chris@0 | 18 |
Chris@0 | 19 /** |
Chris@0 | 20 * Construct a new admin context helper instance. |
Chris@0 | 21 * |
Chris@0 | 22 * @param \Drupal\Core\Routing\RouteMatchInterface $route_match |
Chris@0 | 23 * The route match. |
Chris@0 | 24 */ |
Chris@0 | 25 public function __construct(RouteMatchInterface $route_match) { |
Chris@0 | 26 $this->routeMatch = $route_match; |
Chris@0 | 27 } |
Chris@0 | 28 |
Chris@0 | 29 /** |
Chris@0 | 30 * Determines whether the active route is an admin one. |
Chris@0 | 31 * |
Chris@0 | 32 * @param \Symfony\Component\Routing\Route $route |
Chris@0 | 33 * (optional) The route to determine whether it is an admin one. Per default |
Chris@0 | 34 * this falls back to the route object on the active request. |
Chris@0 | 35 * |
Chris@0 | 36 * @return bool |
Chris@0 | 37 * Returns TRUE if the route is an admin one, otherwise FALSE. |
Chris@0 | 38 */ |
Chris@0 | 39 public function isAdminRoute(Route $route = NULL) { |
Chris@0 | 40 if (!$route) { |
Chris@0 | 41 $route = $this->routeMatch->getRouteObject(); |
Chris@0 | 42 if (!$route) { |
Chris@0 | 43 return FALSE; |
Chris@0 | 44 } |
Chris@0 | 45 } |
Chris@0 | 46 return (bool) $route->getOption('_admin_route'); |
Chris@0 | 47 } |
Chris@0 | 48 |
Chris@0 | 49 } |