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