Loading src/Controller/CoffeeController.php +21 −5 Original line number Diff line number Diff line Loading @@ -8,6 +8,7 @@ use Drupal\Core\Controller\ControllerBase; use Drupal\Core\Menu\LocalTaskManagerInterface; use Drupal\Core\Menu\MenuLinkTreeInterface; use Drupal\Core\Menu\MenuTreeParameters; use Drupal\Core\Routing\RouteMatchInterface; use Drupal\Core\Routing\UrlGeneratorInterface; use Drupal\Core\Url; use Symfony\Component\DependencyInjection\ContainerInterface; Loading Loading @@ -46,6 +47,20 @@ class CoffeeController extends ControllerBase { */ protected $accessManager; /** * The url generator service. * * @var \Drupal\Core\Routing\UrlGeneratorInterface */ protected $urlGenerator; /** * The current route match. * * @var \Drupal\Core\Routing\RouteMatchInterface */ protected $routeMatch; /** * Constructs a new CoffeeController object. * Loading @@ -58,12 +73,13 @@ class CoffeeController extends ControllerBase { * @param \Drupal\Core\Access\AccessManagerInterface $access_manager * The access manager service. */ public function __construct(ConfigFactoryInterface $config_factory, MenuLinkTreeInterface $menu_link_tree, LocalTaskManagerInterface $local_task_manager, AccessManagerInterface $access_manager, UrlGeneratorInterface $url_generator) { public function __construct(ConfigFactoryInterface $config_factory, MenuLinkTreeInterface $menu_link_tree, LocalTaskManagerInterface $local_task_manager, AccessManagerInterface $access_manager, UrlGeneratorInterface $url_generator, RouteMatchInterface $route_match) { $this->config = $config_factory->get('coffee.configuration'); $this->menuLinkTree = $menu_link_tree; $this->localTaskManager = $local_task_manager; $this->accessManager = $access_manager; $this->urlGenerator = $url_generator; $this->routeMatch = $route_match; } /** Loading @@ -75,7 +91,8 @@ class CoffeeController extends ControllerBase { $container->get('menu.link_tree'), $container->get('plugin.manager.menu.local_task'), $container->get('access_manager'), $container->get('coffee.url_generator') $container->get('coffee.url_generator'), $container->get('current_route_match') ); } Loading Loading @@ -184,7 +201,6 @@ class CoffeeController extends ControllerBase { $links = []; $tree = $this->localTaskManager->getLocalTasksForRoute($route_name); $route_match = \Drupal::routeMatch(); foreach ($tree as $instances) { /* @var $instances \Drupal\Core\Menu\LocalTaskInterface[] */ Loading @@ -192,13 +208,13 @@ class CoffeeController extends ControllerBase { $child_route_name = $child->getRouteName(); // Merges the parent's route parameter with the child ones since you // calculate the local tasks outside of parent route context. $child_route_parameters = $child->getRouteParameters($route_match) + $route_parameters; $child_route_parameters = $child->getRouteParameters($this->routeMatch) + $route_parameters; if (strpos($child_route_name, 'config_translate') !== FALSE && $this->accessManager->checkNamedRoute($child_route_name, $child_route_parameters)) { $links[$child_route_name] = [ 'title' => $child->getTitle(), 'url' => Url::fromRoute($child_route_name, $child_route_parameters), 'localized_options' => $child->getOptions($route_match), 'localized_options' => $child->getOptions($this->routeMatch), ]; } } Loading Loading
src/Controller/CoffeeController.php +21 −5 Original line number Diff line number Diff line Loading @@ -8,6 +8,7 @@ use Drupal\Core\Controller\ControllerBase; use Drupal\Core\Menu\LocalTaskManagerInterface; use Drupal\Core\Menu\MenuLinkTreeInterface; use Drupal\Core\Menu\MenuTreeParameters; use Drupal\Core\Routing\RouteMatchInterface; use Drupal\Core\Routing\UrlGeneratorInterface; use Drupal\Core\Url; use Symfony\Component\DependencyInjection\ContainerInterface; Loading Loading @@ -46,6 +47,20 @@ class CoffeeController extends ControllerBase { */ protected $accessManager; /** * The url generator service. * * @var \Drupal\Core\Routing\UrlGeneratorInterface */ protected $urlGenerator; /** * The current route match. * * @var \Drupal\Core\Routing\RouteMatchInterface */ protected $routeMatch; /** * Constructs a new CoffeeController object. * Loading @@ -58,12 +73,13 @@ class CoffeeController extends ControllerBase { * @param \Drupal\Core\Access\AccessManagerInterface $access_manager * The access manager service. */ public function __construct(ConfigFactoryInterface $config_factory, MenuLinkTreeInterface $menu_link_tree, LocalTaskManagerInterface $local_task_manager, AccessManagerInterface $access_manager, UrlGeneratorInterface $url_generator) { public function __construct(ConfigFactoryInterface $config_factory, MenuLinkTreeInterface $menu_link_tree, LocalTaskManagerInterface $local_task_manager, AccessManagerInterface $access_manager, UrlGeneratorInterface $url_generator, RouteMatchInterface $route_match) { $this->config = $config_factory->get('coffee.configuration'); $this->menuLinkTree = $menu_link_tree; $this->localTaskManager = $local_task_manager; $this->accessManager = $access_manager; $this->urlGenerator = $url_generator; $this->routeMatch = $route_match; } /** Loading @@ -75,7 +91,8 @@ class CoffeeController extends ControllerBase { $container->get('menu.link_tree'), $container->get('plugin.manager.menu.local_task'), $container->get('access_manager'), $container->get('coffee.url_generator') $container->get('coffee.url_generator'), $container->get('current_route_match') ); } Loading Loading @@ -184,7 +201,6 @@ class CoffeeController extends ControllerBase { $links = []; $tree = $this->localTaskManager->getLocalTasksForRoute($route_name); $route_match = \Drupal::routeMatch(); foreach ($tree as $instances) { /* @var $instances \Drupal\Core\Menu\LocalTaskInterface[] */ Loading @@ -192,13 +208,13 @@ class CoffeeController extends ControllerBase { $child_route_name = $child->getRouteName(); // Merges the parent's route parameter with the child ones since you // calculate the local tasks outside of parent route context. $child_route_parameters = $child->getRouteParameters($route_match) + $route_parameters; $child_route_parameters = $child->getRouteParameters($this->routeMatch) + $route_parameters; if (strpos($child_route_name, 'config_translate') !== FALSE && $this->accessManager->checkNamedRoute($child_route_name, $child_route_parameters)) { $links[$child_route_name] = [ 'title' => $child->getTitle(), 'url' => Url::fromRoute($child_route_name, $child_route_parameters), 'localized_options' => $child->getOptions($route_match), 'localized_options' => $child->getOptions($this->routeMatch), ]; } } Loading