$links =
[ 1 => MenuLinkMock::
create(['id' => 'test.example1', 'route_name' => 'example1', 'title' => 'foo', 'parent' => ''
]),
2 => MenuLinkMock::
create(['id' => 'test.example2', 'route_name' => 'example2', 'title' => 'bar', 'parent' => 'test.example1', 'route_parameters' =>
['foo' => 'bar'
]]),
3 => MenuLinkMock::
create(['id' => 'test.example3', 'route_name' => 'example3', 'title' => 'baz', 'parent' => 'test.example2', 'route_parameters' =>
['baz' => 'qux'
]]),
4 => MenuLinkMock::
create(['id' => 'test.example4', 'route_name' => 'example4', 'title' => 'qux', 'parent' => 'test.example3'
]),
5 => MenuLinkMock::
create(['id' => 'test.example5', 'route_name' => 'example5', 'title' => 'foofoo', 'parent' => ''
]),
6 => MenuLinkMock::
create(['id' => 'test.example6', 'route_name' => '', 'url' => 'https://www.drupal.org/', 'title' => 'barbar', 'parent' => ''
]),
7 => MenuLinkMock::
create(['id' => 'test.example7', 'route_name' => 'example7', 'title' => 'bazbaz', 'parent' => ''
]),
8 => MenuLinkMock::
create(['id' => 'test.example8', 'route_name' => 'example8', 'title' => 'quxqux', 'parent' => ''
]),
];
foreach ($links as $instance) { $this->menuLinkManager->
addDefinition($instance->
getPluginId(),
$instance->
getPluginDefinition());
} $parameters =
new MenuTreeParameters();
$tree =
$this->linkTree->
load('mock',
$parameters);
$count =
function Darray
$tree) { $sum =
function D
$carry, MenuLinkTreeElement
$item) { return $carry +
$item->
count();
};
return array_reduce($tree,
$sum);
};