public function MongodbMenuTreeStorage::loadByRoute in MongoDB 8
Loads multiple plugin definitions from the storage based on route.
Parameters
string $route_name: The route name.
array $route_parameters: (optional) The route parameters. Defaults to an empty array.
string $menu_name: (optional) Restricts the found links to just those in the named menu.
Return value
array An array of menu link definitions keyed by ID and ordered by depth.
Overrides MenuTreeStorage::loadByRoute
File
- src/
MongodbMenuTreeStorage.php, line 29 - Contains \Drupal\mongodb\MongodbMenuTreeStorage .
Class
Namespace
Drupal\mongodbCode
public function loadByRoute($route_name, array $route_parameters = array(), $menu_name = NULL) {
// Sort the route parameters so that the query string will be the same.
asort($route_parameters);
// Since this will be urlencoded, it's safe to store and match against a
// text field.
// @todo Standardize an efficient way to load by route name and parameters
// in place of system path. https://www.drupal.org/node/2302139
$param_key = $route_parameters ? UrlHelper::buildQuery($route_parameters) : '';
$fields = array_map(function ($x) {
return "value.{$x}";
}, $this
->definitionFields());
$query = [
'value.route_name' => $route_name,
'value.route_param_key' => $param_key,
];
if ($menu_name) {
$query['value.menu_name'] = $menu_name;
}
// Make the ordering deterministic.
$sort = [
'value.depth' => 1,
'value.weight' => 1,
'value.id' => 1,
];
$loaded = [];
foreach ($this
->mongoCollection()
->find($query, $fields)
->sort($sort) as $link) {
$loaded[$link['value']['id']] = $this
->prepareLink($link['value']);
}
return $loaded;
}