Mercurial > hg > isophonics-drupal-site
annotate core/lib/Drupal/Core/Theme/ThemeAccessCheck.php @ 13:5fb285c0d0e3
Update Drupal core to 8.4.7 via Composer. Security update; I *think* we've
been lucky to get away with this so far, as we don't support self-registration
which seems to be used by the so-called "drupalgeddon 2" attack that 8.4.5
was vulnerable to.
author | Chris Cannam |
---|---|
date | Mon, 23 Apr 2018 09:33:26 +0100 |
parents | 4c8ae668cc8c |
children | 129ea1e6d783 |
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@0 | 30 /** |
Chris@0 | 31 * Checks access to the theme for routing. |
Chris@0 | 32 * |
Chris@0 | 33 * @param string $theme |
Chris@0 | 34 * The name of a theme. |
Chris@0 | 35 * |
Chris@0 | 36 * @return \Drupal\Core\Access\AccessResultInterface |
Chris@0 | 37 * The access result. |
Chris@0 | 38 */ |
Chris@0 | 39 public function access($theme) { |
Chris@0 | 40 // Cacheable until the theme settings are modified. |
Chris@0 | 41 return AccessResult::allowedIf($this->checkAccess($theme))->addCacheTags(['config:' . $theme . '.settings']); |
Chris@0 | 42 } |
Chris@0 | 43 |
Chris@0 | 44 /** |
Chris@0 | 45 * Indicates whether the theme is accessible based on whether it is installed. |
Chris@0 | 46 * |
Chris@0 | 47 * @param string $theme |
Chris@0 | 48 * The name of a theme. |
Chris@0 | 49 * |
Chris@0 | 50 * @return bool |
Chris@0 | 51 * TRUE if the theme is installed, FALSE otherwise. |
Chris@0 | 52 */ |
Chris@0 | 53 public function checkAccess($theme) { |
Chris@0 | 54 $themes = $this->themeHandler->listInfo(); |
Chris@0 | 55 return !empty($themes[$theme]->status); |
Chris@0 | 56 } |
Chris@0 | 57 |
Chris@0 | 58 } |