Skip to content
Snippets Groups Projects

Issue #3363421: Use CallableResolver for \Drupal\Core\Menu\MenuLinkTree::transform()

Files

@@ -9,6 +9,7 @@
use Drupal\Core\Routing\PreloadableRouteProviderInterface;
use Drupal\Core\Routing\RouteProviderInterface;
use Drupal\Core\Template\Attribute;
use Drupal\Core\Utility\CallableResolver;
/**
* Implements the loading, transforming and rendering of menu link trees.
@@ -44,11 +45,11 @@ class MenuLinkTree implements MenuLinkTreeInterface {
protected $menuActiveTrail;
/**
* The controller resolver.
* The callable resolver.
*
* @var \Drupal\Core\Controller\ControllerResolverInterface
* @var \Drupal\Core\Utility\CallableResolver
*/
protected $controllerResolver;
protected CallableResolver $callableResolver;
/**
* Constructs a \Drupal\Core\Menu\MenuLinkTree object.
@@ -61,15 +62,19 @@ class MenuLinkTree implements MenuLinkTreeInterface {
* The route provider to load routes by name.
* @param \Drupal\Core\Menu\MenuActiveTrailInterface $menu_active_trail
* The active menu trail service.
* @param \Drupal\Core\Controller\ControllerResolverInterface $controller_resolver
* The controller resolver.
* @param \Drupal\Core\Utility\CallableResolver|\Drupal\Core\Controller\ControllerResolverInterface $callable_resolver
* The callable resolver.
*/
public function __construct(MenuTreeStorageInterface $tree_storage, MenuLinkManagerInterface $menu_link_manager, RouteProviderInterface $route_provider, MenuActiveTrailInterface $menu_active_trail, ControllerResolverInterface $controller_resolver) {
public function __construct(MenuTreeStorageInterface $tree_storage, MenuLinkManagerInterface $menu_link_manager, RouteProviderInterface $route_provider, MenuActiveTrailInterface $menu_active_trail, ControllerResolverInterface|CallableResolver $callable_resolver) {
$this->treeStorage = $tree_storage;
$this->menuLinkManager = $menu_link_manager;
$this->routeProvider = $route_provider;
$this->menuActiveTrail = $menu_active_trail;
$this->controllerResolver = $controller_resolver;
if ($callable_resolver instanceof ControllerResolverInterface) {
@trigger_error('Calling ' . __METHOD__ . '() with an argument of ControllerResolverInterface is deprecated in drupal:10.2.0 and is removed in drupal:11.0.0. Use \Drupal\Core\Utility\CallableResolver instead. See https://www.drupal.org/node/3395294', E_USER_DEPRECATED);
$callable_resolver = \Drupal::service('callable_resolver');
}
$this->callableResolver = $callable_resolver;
}
/**
@@ -137,8 +142,7 @@ protected function createInstances(array $data_tree) {
*/
public function transform(array $tree, array $manipulators) {
foreach ($manipulators as $manipulator) {
$callable = $manipulator['callable'];
$callable = $this->controllerResolver->getControllerFromDefinition($callable);
$callable = $this->callableResolver->getCallableFromDefinition($manipulator['callable']);
// Prepare the arguments for the menu tree manipulator callable; the first
// argument is always the menu link tree.
if (isset($manipulator['args'])) {
Loading