0

I have upgraded my Drupal 9 site to Drupal 10.1. One of my custom module uses \Drupal::service('menu.tree_storage')->loadByProperties(); which works fine in drupal 9.5.9, but I get the following error message in Drupal 10.1.

You have requested a non-existent service "menu.tree_storage"

When I used drush dcs | grep "tree", the menu.tree_storage is missing from my Drupal 10 site. Yet it is listed as an argument in the core.services.yml file.

Is there a way to fix this?

4
  • Very little has changed in the \Drupal\Core\DependencyInjection component between Drupal 9.5 and 10.1 except, notably, the change in dependency symfony/dependency-injection from ^4.4 to ^6.3. As this is a service marked private that could be involved. What is the dcs Drush subcommand? I'm not familiar with it.
    – cilefen
    Jul 18 at 19:59
  • drush dcs is an alias of drush devel:services which gets a list of available services
    – hobbsie
    Jul 19 at 6:11
  • That’s from the Devel module I suppose.
    – cilefen
    Jul 19 at 11:06
  • This is an intentional change and it is in the 10.1.0 release notes: "A bug in Drupal's dependency injection container is fixed. The bug could allow certain private services to be accessed by $container->get() depending on code execution order. Custom or contributed module code accessing services in this way would have been fragile before the change, but will now always break. Public services are unaffected." I am not posting this as an answer because you are actually asking for a workaround.
    – cilefen
    Sep 7 at 13:17

2 Answers 2

0

In case this helps someone else: Since we only use the load method of the MenuTreeStorage class, we were able to replace it with the MenuLinkManager.

-    $container->get('menu.tree_storage'),
+    $container->get('plugin.manager.menu.link'),
-    $menu_link = $this->menuTreeStorage->load($id);
+    $menu_link = $this->menuLinkManager->getDefinition($id, FALSE);

See https://www.drupal.org/project/drupal/issues/3385730 for possible further follow up of core maintainers.

-1

Menus are config entities and can be loaded using the entity type manager instead of using menu tree storage service.

https://www.drupal.org/node/3027453

1
  • I don't believe menu content are entities so they cannot be loaded using EntityTypeManager. Only the menus themselves are configuration entities.
    – Benjen
    Aug 14 at 8:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.