diff --git a/core/lib/Drupal/Core/Controller/ControllerBase.php b/core/lib/Drupal/Core/Controller/ControllerBase.php index 51c9501..3af41f5 100644 --- a/core/lib/Drupal/Core/Controller/ControllerBase.php +++ b/core/lib/Drupal/Core/Controller/ControllerBase.php @@ -110,11 +110,6 @@ protected $formBuilder; /** - * @var - */ - protected $themeHandler; - - /** * {@inheritdoc} */ public static function create(ContainerInterface $container) { diff --git a/core/lib/Drupal/Core/Extension/ThemeHandler.php b/core/lib/Drupal/Core/Extension/ThemeHandler.php index a0110b3..207959a 100644 --- a/core/lib/Drupal/Core/Extension/ThemeHandler.php +++ b/core/lib/Drupal/Core/Extension/ThemeHandler.php @@ -461,6 +461,9 @@ protected function resetSystem() { */ public function getName($theme) { $themes = $this->listInfo(); + if (!isset($themes[$theme])) { + throw new \InvalidArgumentException(String::format('Requested the name of a non-existing theme @theme', array('@theme' => $theme))); + } return String::checkPlain($themes[$theme]->info['name']); } diff --git a/core/modules/block/lib/Drupal/block/Controller/BlockController.php b/core/modules/block/lib/Drupal/block/Controller/BlockController.php index 41401f1..a4e7952 100644 --- a/core/modules/block/lib/Drupal/block/Controller/BlockController.php +++ b/core/modules/block/lib/Drupal/block/Controller/BlockController.php @@ -9,6 +9,9 @@ use Drupal\Component\Utility\String; use Drupal\Core\Controller\ControllerBase; +use Drupal\Core\Extension\ThemeHandler; +use Drupal\Core\Extension\ThemeHandlerInterface; +use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\HttpFoundation\Request; /** @@ -17,6 +20,32 @@ class BlockController extends ControllerBase { /** + * The theme handler. + * + * @var \Drupal\Core\Extension\ThemeHandlerInterface + */ + protected $themeHandler; + + /** + * Constructs a new BlockController instance. + * + * @param \Drupal\Core\Extension\ThemeHandlerInterface $theme_handler + * The theme handler. + */ + public function __construct(ThemeHandlerInterface $theme_handler) { + $this->themeHandler = $theme_handler; + } + + /** + * {@inheritdoc} + */ + public static function create(ContainerInterface $container) { + return new static( + $container->get('theme_handler') + ); + } + + /** * Returns a block theme demo page. * * @param string $theme @@ -26,9 +55,8 @@ class BlockController extends ControllerBase { * A render array containing the CSS and title for the block region demo. */ public function demo($theme) { - $themes = list_themes(); return array( - '#title' => String::checkPlain($themes[$theme]->info['name']), + '#title' => String::checkPlain($this->themeHandler->getName($theme)), '#attached' => array( 'js' => array( array( @@ -47,18 +75,4 @@ public function demo($theme) { ); } - /** - * Get the title. - * - * @param string $theme - * The configured theme. - * - * @return string - * The human readable name of the theme. - */ - public function getTitle($theme) { - $themes = $this->themeHandler->listInfo(); - return String::checkPlain($themes[$theme]->info['name']); - } - }