Mercurial > hg > isophonics-drupal-site
comparison core/lib/Drupal/Core/Theme/ThemeAccessCheck.php @ 0:4c8ae668cc8c
Initial import (non-working)
author | Chris Cannam |
---|---|
date | Wed, 29 Nov 2017 16:09:58 +0000 |
parents | |
children | 129ea1e6d783 |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:4c8ae668cc8c |
---|---|
1 <?php | |
2 | |
3 namespace Drupal\Core\Theme; | |
4 | |
5 use Drupal\Core\Access\AccessResult; | |
6 use Drupal\Core\Extension\ThemeHandlerInterface; | |
7 use Drupal\Core\Routing\Access\AccessInterface; | |
8 | |
9 /** | |
10 * Provides access checking for themes for routing and theme negotiation. | |
11 */ | |
12 class ThemeAccessCheck implements AccessInterface { | |
13 | |
14 /** | |
15 * The theme handler. | |
16 * | |
17 * @var \Drupal\Core\Extension\ThemeHandlerInterface | |
18 */ | |
19 protected $themeHandler; | |
20 | |
21 /** | |
22 * Constructs a \Drupal\Core\Theme\Registry object. | |
23 * | |
24 * @param \Drupal\Core\Extension\ThemeHandlerInterface $theme_handler | |
25 * The theme handler. | |
26 */ | |
27 public function __construct(ThemeHandlerInterface $theme_handler) { | |
28 $this->themeHandler = $theme_handler; | |
29 } | |
30 /** | |
31 * Checks access to the theme for routing. | |
32 * | |
33 * @param string $theme | |
34 * The name of a theme. | |
35 * | |
36 * @return \Drupal\Core\Access\AccessResultInterface | |
37 * The access result. | |
38 */ | |
39 public function access($theme) { | |
40 // Cacheable until the theme settings are modified. | |
41 return AccessResult::allowedIf($this->checkAccess($theme))->addCacheTags(['config:' . $theme . '.settings']); | |
42 } | |
43 | |
44 /** | |
45 * Indicates whether the theme is accessible based on whether it is installed. | |
46 * | |
47 * @param string $theme | |
48 * The name of a theme. | |
49 * | |
50 * @return bool | |
51 * TRUE if the theme is installed, FALSE otherwise. | |
52 */ | |
53 public function checkAccess($theme) { | |
54 $themes = $this->themeHandler->listInfo(); | |
55 return !empty($themes[$theme]->status); | |
56 } | |
57 | |
58 } |