Unverified Commit 4cb745d6 authored by alexpott's avatar alexpott
Browse files

Issue #3123210 by nitesh624, Hardik_Patel_12, jameszhang023, sanjayk, jungle,...

Issue #3123210 by nitesh624, Hardik_Patel_12, jameszhang023, sanjayk, jungle, alexpott: Replace non-test usages of \Drupal::theme() with IoC injection
parent ec711906
......@@ -1083,7 +1083,7 @@ services:
- { name: event_subscriber }
main_content_renderer.html:
class: Drupal\Core\Render\MainContent\HtmlRenderer
arguments: ['@title_resolver', '@plugin.manager.display_variant', '@event_dispatcher', '@module_handler', '@renderer', '@render_cache', '%renderer.config%']
arguments: ['@title_resolver', '@plugin.manager.display_variant', '@event_dispatcher', '@module_handler', '@renderer', '@render_cache', '%renderer.config%', '@theme.manager']
tags:
- { name: render.main_content_renderer, format: html }
main_content_renderer.ajax:
......
......@@ -15,6 +15,7 @@
use Drupal\Core\Render\RendererInterface;
use Drupal\Core\Render\RenderEvents;
use Drupal\Core\Routing\RouteMatchInterface;
use Drupal\Core\Theme\ThemeManagerInterface;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\HttpFoundation\Request;
......@@ -80,6 +81,13 @@ class HtmlRenderer implements MainContentRendererInterface {
*/
protected $rendererConfig;
/**
* The theme manager.
*
* @var \Drupal\Core\Theme\ThemeManagerInterface
*/
protected $themeManager;
/**
* Constructs a new HtmlRenderer.
*
......@@ -97,8 +105,10 @@ class HtmlRenderer implements MainContentRendererInterface {
* The render cache service.
* @param array $renderer_config
* The renderer configuration array.
* @param \Drupal\Core\Theme\ThemeManagerInterface $theme_manager
* The theme manager.
*/
public function __construct(TitleResolverInterface $title_resolver, PluginManagerInterface $display_variant_manager, EventDispatcherInterface $event_dispatcher, ModuleHandlerInterface $module_handler, RendererInterface $renderer, RenderCacheInterface $render_cache, array $renderer_config) {
public function __construct(TitleResolverInterface $title_resolver, PluginManagerInterface $display_variant_manager, EventDispatcherInterface $event_dispatcher, ModuleHandlerInterface $module_handler, RendererInterface $renderer, RenderCacheInterface $render_cache, array $renderer_config, ThemeManagerInterface $theme_manager = NULL) {
$this->titleResolver = $title_resolver;
$this->displayVariantManager = $display_variant_manager;
$this->eventDispatcher = $event_dispatcher;
......@@ -106,6 +116,11 @@ public function __construct(TitleResolverInterface $title_resolver, PluginManage
$this->renderer = $renderer;
$this->renderCache = $render_cache;
$this->rendererConfig = $renderer_config;
if ($theme_manager === NULL) {
@trigger_error('Calling ' . __METHOD__ . ' without the $theme_manager argument is deprecated in drupal:9.1.0 and will be required in drupal:10.0.0. See https://www.drupal.org/node/3159762', E_USER_DEPRECATED);
$theme_manager = \Drupal::service('theme.manager');
}
$this->themeManager = $theme_manager;
}
/**
......@@ -261,7 +276,7 @@ protected function prepare(array $main_content, Request $request, RouteMatchInte
// $page is now fully built. Find all non-empty page regions, and add a
// theme wrapper function that allows them to be consistently themed.
$regions = \Drupal::theme()->getActiveTheme()->getRegions();
$regions = $this->themeManager->getActiveTheme()->getRegions();
foreach ($regions as $region) {
if (!empty($page[$region])) {
$page[$region]['#theme_wrappers'][] = 'region';
......@@ -302,7 +317,7 @@ public function invokePageAttachmentHooks(array &$page) {
// Modules and themes can alter page attachments.
$this->moduleHandler->alter('page_attachments', $attachments);
\Drupal::theme()->alter('page_attachments', $attachments);
$this->themeManager->alter('page_attachments', $attachments);
if (array_diff(array_keys($attachments), ['#attached', '#cache']) !== []) {
throw new \LogicException('Only #attached and #cache may be set in hook_page_attachments_alter().');
}
......
......@@ -11,8 +11,9 @@
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Link;
use Drupal\Core\Render\ElementInfoManagerInterface;
use Drupal\Core\Url;
use Drupal\Core\TempStore\SharedTempStoreFactory;
use Drupal\Core\Theme\ThemeManagerInterface;
use Drupal\Core\Url;
use Drupal\views\Views;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\HttpFoundation\RequestStack;
......@@ -53,6 +54,13 @@ class ViewEditForm extends ViewFormBase {
*/
protected $elementInfo;
/**
* The theme manager.
*
* @var \Drupal\Core\Theme\ThemeManagerInterface
*/
protected $themeManager;
/**
* Constructs a new ViewEditForm object.
*
......@@ -64,12 +72,19 @@ class ViewEditForm extends ViewFormBase {
* The date Formatter service.
* @param \Drupal\Core\Render\ElementInfoManagerInterface $element_info
* The element info manager.
* @param \Drupal\Core\Theme\ThemeManagerInterface $theme_manager
* The theme manager.
*/
public function __construct(SharedTempStoreFactory $temp_store_factory, RequestStack $requestStack, DateFormatterInterface $date_formatter, ElementInfoManagerInterface $element_info) {
public function __construct(SharedTempStoreFactory $temp_store_factory, RequestStack $requestStack, DateFormatterInterface $date_formatter, ElementInfoManagerInterface $element_info, ThemeManagerInterface $theme_manager = NULL) {
$this->tempStore = $temp_store_factory->get('views');
$this->requestStack = $requestStack;
$this->dateFormatter = $date_formatter;
$this->elementInfo = $element_info;
if ($theme_manager === NULL) {
@trigger_error('Calling ' . __METHOD__ . ' without the $theme_manager argument is deprecated in drupal:9.1.0 and will be required in drupal:10.0.0. See https://www.drupal.org/node/3159506', E_USER_DEPRECATED);
$theme_manager = \Drupal::service('theme.manager');
}
$this->themeManager = $theme_manager;
}
/**
......@@ -80,7 +95,8 @@ public static function create(ContainerInterface $container) {
$container->get('tempstore.shared'),
$container->get('request_stack'),
$container->get('date.formatter'),
$container->get('element_info')
$container->get('element_info'),
$container->get('theme.manager')
);
}
......@@ -368,7 +384,7 @@ public function getDisplayTab($view) {
// also invoke this on themes.
// @todo remove this after
// https://www.drupal.org/project/drupal/issues/3087455 has been resolved.
\Drupal::theme()->alter('views_ui_display_tab', $build, $view, $display_id);
$this->themeManager->alter('views_ui_display_tab', $build, $view, $display_id);
return $build;
}
......@@ -792,7 +808,7 @@ public function renderDisplayTop(ViewUI $view) {
// also invoke this on themes.
// @todo remove this after
// https://www.drupal.org/project/drupal/issues/3087455 has been resolved.
\Drupal::theme()->alter('views_ui_display_top', $element, $view, $display_id);
$this->themeManager->alter('views_ui_display_top', $element, $view, $display_id);
return $element;
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment