diff --git a/core/modules/user/src/Theme/AdminNegotiator.php b/core/modules/user/src/Theme/AdminNegotiator.php index 398acbd2013845f701aab299c26b5e9b86585c43..d8c495d2350ead62d44f0b6a3422f877b39a4197 100644 --- a/core/modules/user/src/Theme/AdminNegotiator.php +++ b/core/modules/user/src/Theme/AdminNegotiator.php @@ -3,6 +3,7 @@ namespace Drupal\user\Theme; use Drupal\Core\Config\ConfigFactoryInterface; +use Drupal\Core\DependencyInjection\DeprecatedServicePropertyTrait; use Drupal\Core\Entity\EntityTypeManagerInterface; use Drupal\Core\Routing\AdminContext; use Drupal\Core\Routing\RouteMatchInterface; @@ -13,6 +14,12 @@ * Sets the active theme on admin pages. */ class AdminNegotiator implements ThemeNegotiatorInterface { + use DeprecatedServicePropertyTrait; + + /** + * The service properties that should raise a deprecation error. + */ + private array $deprecatedProperties = ['entityTypeManager' => 'entity_type.manager']; /** * The current user. @@ -28,13 +35,6 @@ class AdminNegotiator implements ThemeNegotiatorInterface { */ protected $configFactory; - /** - * The entity type manager. - * - * @var \Drupal\Core\Entity\EntityTypeManagerInterface - */ - protected $entityTypeManager; - /** * The route admin context to determine whether a route is an admin one. * @@ -49,23 +49,29 @@ class AdminNegotiator implements ThemeNegotiatorInterface { * The current user. * @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory * The config factory. - * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager - * The entity type manager. - * @param \Drupal\Core\Routing\AdminContext $admin_context + * @param \Drupal\Core\Routing\AdminContext|EntityTypeManagerInterface $admin_context * The route admin context to determine whether the route is an admin one. */ - public function __construct(AccountInterface $user, ConfigFactoryInterface $config_factory, EntityTypeManagerInterface $entity_type_manager, AdminContext $admin_context) { + public function __construct(AccountInterface $user, ConfigFactoryInterface $config_factory, AdminContext|EntityTypeManagerInterface $admin_context) { $this->user = $user; $this->configFactory = $config_factory; - $this->entityTypeManager = $entity_type_manager; - $this->adminContext = $admin_context; + + if ($admin_context instanceof EntityTypeManagerInterface) { + $deprecated_service_name = EntityTypeManagerInterface::class; + @trigger_error("Passing the $deprecated_service_name (entity_type.manager service) to AdminNegotiator is deprecated in drupal:11.2.0 and will be removed in drupal:12.0.0. There is no replacement for this service, as it is not used. See https://www.drupal.org/project/drupal/issues/3501727", E_USER_DEPRECATED); + $this->adminContext = \Drupal::service('router.admin_context'); + } + else { + $this->adminContext = $admin_context; + } } /** * {@inheritdoc} */ public function applies(RouteMatchInterface $route_match) { - return ($this->entityTypeManager->hasHandler('user_role', 'storage') && $this->user->hasPermission('view the administration theme') && $this->adminContext->isAdminRoute($route_match->getRouteObject())); + $is_admin_route = $this->adminContext->isAdminRoute($route_match->getRouteObject()); + return $is_admin_route && $this->user->hasPermission('view the administration theme'); } /** diff --git a/core/modules/user/tests/src/Unit/Theme/AdminNegotiatorTest.php b/core/modules/user/tests/src/Unit/Theme/AdminNegotiatorTest.php index cb95afcd05c7360288e9dd930b93a9e7f6f165ae..7a34a967e4786829014dd22da0188ed8ead5ee9e 100644 --- a/core/modules/user/tests/src/Unit/Theme/AdminNegotiatorTest.php +++ b/core/modules/user/tests/src/Unit/Theme/AdminNegotiatorTest.php @@ -4,7 +4,6 @@ namespace Drupal\Tests\user\Unit\Theme; -use Drupal\Core\Entity\EntityTypeManagerInterface; use Drupal\Core\Routing\AdminContext; use Drupal\Core\Routing\RouteMatch; use Drupal\Core\Session\AccountInterface; @@ -25,9 +24,8 @@ class AdminNegotiatorTest extends UnitTestCase { public function testDetermineActiveTheme($admin_theme, $expected): void { $user = $this->prophesize(AccountInterface::class); $config_factory = $this->getConfigFactoryStub(['system.theme' => ['admin' => $admin_theme]]); - $entity_type_manager = $this->prophesize(EntityTypeManagerInterface::class); $admin_context = $this->prophesize(AdminContext::class); - $negotiator = new AdminNegotiator($user->reveal(), $config_factory, $entity_type_manager->reveal(), $admin_context->reveal()); + $negotiator = new AdminNegotiator($user->reveal(), $config_factory, $admin_context->reveal()); $route_match = $this->prophesize(RouteMatch::class); $this->assertSame($expected, $negotiator->determineActiveTheme($route_match->reveal())); } diff --git a/core/modules/user/user.services.yml b/core/modules/user/user.services.yml index ec34738d992ea00d41bef37149cb1db7419777b6..d7ad70852f6ed1d957227fb9572b8af9b48f81ee 100644 --- a/core/modules/user/user.services.yml +++ b/core/modules/user/user.services.yml @@ -39,7 +39,7 @@ services: arguments: ['@current_user', '@entity_type.manager', '@datetime.time'] theme.negotiator.admin_theme: class: Drupal\user\Theme\AdminNegotiator - arguments: ['@current_user', '@config.factory', '@entity_type.manager', '@router.admin_context'] + arguments: ['@current_user', '@config.factory', '@router.admin_context'] tags: - { name: theme_negotiator, priority: -40 } user.auth: diff --git a/core/profiles/standard/tests/src/FunctionalJavascript/StandardPerformanceTest.php b/core/profiles/standard/tests/src/FunctionalJavascript/StandardPerformanceTest.php index a43ba4a03db8af79c58e0f9ef7157cb8fd6cdb3d..3c045918b6af246df2a314906183db590643c4a4 100644 --- a/core/profiles/standard/tests/src/FunctionalJavascript/StandardPerformanceTest.php +++ b/core/profiles/standard/tests/src/FunctionalJavascript/StandardPerformanceTest.php @@ -335,7 +335,7 @@ protected function testLogin(): void { $this->assertSame($expected_queries, $recorded_queries); $expected = [ 'QueryCount' => 17, - 'CacheGetCount' => 85, + 'CacheGetCount' => 84, 'CacheSetCount' => 1, 'CacheDeleteCount' => 1, 'CacheTagChecksumCount' => 1,