diff -u b/core/modules/block/src/BlockForm.php b/core/modules/block/src/BlockForm.php --- b/core/modules/block/src/BlockForm.php +++ b/core/modules/block/src/BlockForm.php @@ -12,6 +12,7 @@ use Drupal\Core\Entity\EntityForm; use Drupal\Core\Entity\EntityManagerInterface; use Drupal\Core\Executable\ExecutableManagerInterface; +use Drupal\Core\Extension\ThemeHandler; use Drupal\Core\Form\FormState; use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Language\LanguageManagerInterface; @@ -60,6 +61,13 @@ protected $language; /** + * The theme handler. + * + * @var \Drupal\Core\Extension\ThemeHandler + */ + protected $themeHandler; + + /** * Constructs a BlockForm object. * * @param \Drupal\Core\Entity\EntityManagerInterface $entity_manager @@ -70,12 +78,15 @@ * The EventDispatcher for gathering administrative contexts. * @param \Drupal\Core\Language\LanguageManagerInterface $language * The language manager. + * @param \Drupal\Core\Extension\ThemeHandler $theme_handler + * The theme handler. */ - public function __construct(EntityManagerInterface $entity_manager, ExecutableManagerInterface $manager, EventDispatcherInterface $dispatcher, LanguageManagerInterface $language) { + public function __construct(EntityManagerInterface $entity_manager, ExecutableManagerInterface $manager, EventDispatcherInterface $dispatcher, LanguageManagerInterface $language, ThemeHandler $theme_handler) { $this->storage = $entity_manager->getStorage('block'); $this->manager = $manager; $this->dispatcher = $dispatcher; $this->language = $language; + $this->themeHandler = $theme_handler; } /** @@ -86,7 +97,8 @@ $container->get('entity.manager'), $container->get('plugin.manager.condition'), $container->get('event_dispatcher'), - $container->get('language_manager') + $container->get('language_manager'), + $container->get('theme_handler') ); } @@ -134,7 +146,7 @@ } else { $theme_options = array(); - foreach (\Drupal::service('theme_handler')->listInfo() as $theme_name => $theme_info) { + foreach ($this->themeHandler->listInfo() as $theme_name => $theme_info) { if (!empty($theme_info->status)) { $theme_options[$theme_name] = $theme_info->info['name']; } diff -u b/core/modules/block_content/src/Controller/BlockContentController.php b/core/modules/block_content/src/Controller/BlockContentController.php --- b/core/modules/block_content/src/Controller/BlockContentController.php +++ b/core/modules/block_content/src/Controller/BlockContentController.php @@ -11,6 +11,7 @@ use Drupal\Core\Controller\ControllerBase; use Drupal\Core\Entity\EntityStorageInterface; use Drupal\block_content\BlockContentTypeInterface; +use Drupal\Core\Extension\ThemeHandler; use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\HttpFoundation\Request; @@ -31,13 +32,21 @@ protected $blockContentTypeStorage; /** + * The theme handler. + * + * @var \Drupal\Core\Extension\ThemeHandler + */ + protected $themeHandler; + + /** * {@inheritdoc} */ public static function create(ContainerInterface $container) { $entity_manager = $container->get('entity.manager'); return new static( $entity_manager->getStorage('block_content'), - $entity_manager->getStorage('block_content_type') + $entity_manager->getStorage('block_content_type'), + $container->get('theme_handler') ); } @@ -48,10 +57,13 @@ * The custom block storage. * @param \Drupal\Core\Entity\EntityStorageInterface $block_content_type_storage * The custom block type storage. + * @param \Drupal\Core\Extension\ThemeHandler $theme_handler + * The theme handler. */ - public function __construct(EntityStorageInterface $block_content_storage, EntityStorageInterface $block_content_type_storage) { + public function __construct(EntityStorageInterface $block_content_storage, EntityStorageInterface $block_content_type_storage, ThemeHandler $theme_handler) { $this->blockContentStorage = $block_content_storage; $this->blockContentTypeStorage = $block_content_type_storage; + $this->themeHandler = $theme_handler; } /** @@ -90,7 +102,7 @@ $block = $this->blockContentStorage->create(array( 'type' => $block_content_type->id() )); - if (($theme = $request->query->get('theme')) && in_array($theme, array_keys(\Drupal::service('theme_handler')->listInfo()))) { + if (($theme = $request->query->get('theme')) && in_array($theme, array_keys($this->themeHandler->listInfo()))) { // We have navigated to this page from the block library and will keep track // of the theme for redirecting the user to the configuration page for the // newly created block in the given theme. diff -u b/core/modules/system/src/Form/ThemeSettingsForm.php b/core/modules/system/src/Form/ThemeSettingsForm.php --- b/core/modules/system/src/Form/ThemeSettingsForm.php +++ b/core/modules/system/src/Form/ThemeSettingsForm.php @@ -7,6 +7,7 @@ namespace Drupal\system\Form; +use Drupal\Core\Extension\ThemeHandler; use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Render\Element; use Drupal\Core\StreamWrapper\PublicStream; @@ -30,17 +31,27 @@ protected $moduleHandler; /** + * The theme handler. + * + * @var \Drupal\Core\Extension\ThemeHandler + */ + protected $themeHandler; + + /** * Constructs a ThemeSettingsForm object. * * @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory * The factory for configuration objects. * @param \Drupal\Core\Extension\ModuleHandlerInterface * The module handler instance to use. + * @param \Drupal\Core\Extension\ThemeHandler $theme_handler + * The theme handler. */ - public function __construct(ConfigFactoryInterface $config_factory, ModuleHandlerInterface $module_handler) { + public function __construct(ConfigFactoryInterface $config_factory, ModuleHandlerInterface $module_handler, ThemeHandler $theme_handler) { parent::__construct($config_factory); $this->moduleHandler = $module_handler; + $this->themeHandler = $theme_handler; } /** @@ -49,7 +60,8 @@ public static function create(ContainerInterface $container) { return new static( $container->get('config.factory'), - $container->get('module_handler') + $container->get('module_handler'), + $container->get('theme_handler') ); } @@ -69,7 +81,7 @@ public function buildForm(array $form, FormStateInterface $form_state, $theme = '') { $form = parent::buildForm($form, $form_state); - $themes = \Drupal::service('theme_handler')->listInfo(); + $themes = $this->themeHandler->listInfo(); // Deny access if the theme is not installed or not found. if (!empty($theme) && (empty($themes[$theme]) || !$themes[$theme]->status)) { @@ -80,7 +92,7 @@ if ($theme) { $var = 'theme_' . $theme . '_settings'; $config_key = $theme . '.settings'; - $themes = \Drupal::service('theme_handler')->listInfo(); + $themes = $this->themeHandler->listInfo(); $features = $themes[$theme]->info['features']; } else { diff -u b/core/modules/system/src/Tests/Theme/ThemeTest.php b/core/modules/system/src/Tests/Theme/ThemeTest.php --- b/core/modules/system/src/Tests/Theme/ThemeTest.php +++ b/core/modules/system/src/Tests/Theme/ThemeTest.php @@ -215,7 +215,7 @@ $this->assertTrue(drupal_theme_access('test_theme'), 'Installed theme detected'); $this->assertTrue(drupal_theme_access('test_theme'), 'Enabled theme detected'); - // Check if ThemeHandlerIntface::listInfo() returns disabled themes. + // Check if ThemeHandlerInterface::listInfo() returns disabled themes. // Check for base theme and subtheme lists. $base_theme_list = array('test_basetheme' => 'Theme test base theme'); $sub_theme_list = array('test_subtheme' => 'Theme test subtheme'); diff -u b/core/modules/views_ui/src/Form/BasicSettingsForm.php b/core/modules/views_ui/src/Form/BasicSettingsForm.php --- b/core/modules/views_ui/src/Form/BasicSettingsForm.php +++ b/core/modules/views_ui/src/Form/BasicSettingsForm.php @@ -7,8 +7,11 @@ namespace Drupal\views_ui\Form; +use Drupal\Core\Config\ConfigFactoryInterface; +use Drupal\Core\Extension\ThemeHandler; use Drupal\Core\Form\ConfigFormBase; use Drupal\Core\Form\FormStateInterface; +use Symfony\Component\DependencyInjection\ContainerInterface; /** * Form builder for the admin display defaults page. @@ -16,6 +19,37 @@ class BasicSettingsForm extends ConfigFormBase { /** + * The theme handler. + * + * @var \Drupal\Core\Extension\ThemeHandler + */ + protected $themeHandler; + + /** + * Constructs a \Drupal\system\BasicSettingsForm object. + * + * @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory + * The factory for configuration objects. + * @param \Drupal\Core\Extension\ThemeHandler $theme_handler + * The theme handler. + */ + public function __construct(ConfigFactoryInterface $config_factory, ThemeHandler $theme_handler) { + parent::__construct($config_factory); + + $this->themeHandler = $theme_handler; + } + + /** + * {@inheritdoc} + */ + public static function create(ContainerInterface $container) { + return new static( + $container->get('config.factory'), + $container->get('theme_handler') + ); + } + + /** * {@inheritdoc} */ public function getFormId() { @@ -30,7 +64,7 @@ $config = $this->config('views.settings'); $options = array(); - foreach (\Drupal::service('theme_handler')->listInfo() as $name => $theme) { + foreach ($this->themeHandler->listInfo() as $name => $theme) { if ($theme->status) { $options[$name] = $theme->info['name']; }