Follow-up of #2977107: Use more specific entity.manager services in module .services.yml files.
Feedback from @alexpott there:
+++ b/core/modules/system/src/SystemManager.php @@ -79,8 +81,14 @@ class SystemManager { + public function __construct(ModuleHandlerInterface $module_handler, $request_stack, $menu_tree, $menu_active_trail) { $this->moduleHandler = $module_handler; + if ($request_stack instanceof EntityManagerInterface) { + @trigger_error('Passing the entity.manager service to SystemManager::__construct() is deprecated in Drupal 8.7.0 and will be removed before Drupal 9.0.0.. See https://www.drupal.org/node/2549139.', E_USER_DEPRECATED); + $request_stack = \Drupal::service('request_stack'); + $menu_tree = \Drupal::menuTree(); + $menu_active_trail = \Drupal::service('menu.active_trail'); + }
We need assert on the interfaces here or we lose type safety. I think the thing to do here is to remove the entity manager type hint and pass a NULL in via the .services file and then file a follow-up for Drupal 9 to fix this. Because then we can make a breaking change... or maybe we have auto-wiring at that point.
I'm not really convinced by that, I'd prefer either this approach (with assert() then for the interface check until we can add the type hints back) or then just removing it. We've done that before, for example in #3001309: Replace usages of UrlGeneratorTrait in non-api classes, which removed an argument from the CommentManager service.
Doing the suggested change in 9.x is IMHO an unnecessary hard break, even though it is very unlikely that this service was subclassed by anyone.. but then we could also just remove it now :)