Commit e68af255 authored by catch's avatar catch

Issue #2787107 by bc, raman.b, mradcliffe, pwolanin, klausi, dawehner: Menu...

Issue #2787107 by bc, raman.b, mradcliffe, pwolanin, klausi, dawehner: Menu tree storage does not populate route names for a definition

(cherry picked from commit 0762491d)
parent 3917a3f8
......@@ -6,6 +6,7 @@
use Drupal\Core\Access\AccessResultInterface;
use Drupal\Core\Cache\CacheableMetadata;
use Drupal\Core\Controller\ControllerResolverInterface;
use Drupal\Core\Routing\PreloadableRouteProviderInterface;
use Drupal\Core\Routing\RouteProviderInterface;
use Drupal\Core\Template\Attribute;
......@@ -95,7 +96,7 @@ public function getCurrentRouteMenuTreeParameters($menu_name) {
public function load($menu_name, MenuTreeParameters $parameters) {
$data = $this->treeStorage->loadTreeData($menu_name, $parameters);
// Pre-load all the route objects in the tree for access checks.
if ($data['route_names']) {
if ($data['route_names'] && $this->routeProvider instanceof PreloadableRouteProviderInterface) {
$this->routeProvider->getRoutesByNames($data['route_names']);
}
return $this->createInstances($data['tree']);
......
......@@ -1002,8 +1002,8 @@ protected function doCollectRoutesAndDefinitions(array $tree, array &$definition
$route_names = [];
foreach (array_keys($tree) as $id) {
$definitions[$id] = $this->definitions[$id];
if (!empty($definition['route_name'])) {
$route_names[$definition['route_name']] = $definition['route_name'];
if (!empty($definitions[$id]['route_name'])) {
$route_names[$definitions[$id]['route_name']] = $definitions[$id]['route_name'];
}
if ($tree[$id]['subtree']) {
$route_names += $this->doCollectRoutesAndDefinitions($tree[$id]['subtree'], $definitions);
......
......@@ -226,11 +226,11 @@ public function testMenuDisabledChildLinks() {
* Tests the loadTreeData method.
*/
public function testLoadTree() {
$this->addMenuLink('test1', '');
$this->addMenuLink('test2', 'test1');
$this->addMenuLink('test3', 'test2');
$this->addMenuLink('test4');
$this->addMenuLink('test5', 'test4');
$this->addMenuLink('test1', '', 'test1');
$this->addMenuLink('test2', 'test1', 'test2');
$this->addMenuLink('test3', 'test2', 'test3');
$this->addMenuLink('test4', '', 'test4');
$this->addMenuLink('test5', 'test4', NULL);
$data = $this->treeStorage->loadTreeData('tools', new MenuTreeParameters());
$tree = $data['tree'];
......@@ -240,6 +240,13 @@ public function testLoadTree() {
$this->assertCount(1, $tree['test4']['subtree']);
$this->assertCount(0, $tree['test4']['subtree']['test5']['subtree']);
// Ensure that route names element exists.
$this->assertNotEmpty($data['route_names']);
// Ensure that the actual route names are set.
$this->assertContains('test1', $data['route_names']);
$this->assertNotContains('test5', $data['route_names']);
$parameters = new MenuTreeParameters();
$parameters->setActiveTrail(['test4', 'test5']);
$data = $this->treeStorage->loadTreeData('tools', $parameters);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment