Skip to content
Snippets Groups Projects
Commit c739b137 authored by Alec Smrekar's avatar Alec Smrekar
Browse files

Add support for 10.1 location structure

parent 4e7703f0
No related branches found
No related tags found
No related merge requests found
......@@ -84,7 +84,8 @@ class RemoteMenuParser {
$data = [];
// Convert a flat JSON into a tree array.
foreach ($json_parsed->linkset[0]->item as $item) {
$data = static::insertLink($item->{'drupal-menu-hierarchy'}[0], $item->href, $item->title, $data);
$location = static::parseLocation($item);
$data = static::insertLink($location, $item->href, $item->title, $data);
}
// Convert the tree array into a tree of RemoteMenuLink objects.
$base_url = parse_url($url, PHP_URL_SCHEME) . '://' . parse_url($url, PHP_URL_HOST);
......@@ -145,7 +146,7 @@ class RemoteMenuParser {
*/
protected static function insertLink(string $location, string $link, string $title, array $data): array {
$pointer = &$data;
$fragments = array_filter(explode('.', $location));
$fragments = array_filter(explode('.', $location), 'strlen');
// Traverse the tree.
while (TRUE) {
if (count($fragments) === 1) {
......@@ -165,4 +166,24 @@ class RemoteMenuParser {
return $data;
}
/**
* Parses the location string.
*
* @param object $item
* The menu item object.
*
* @return string
* The location string.
*/
protected static function parseLocation(object $item): string {
if (property_exists($item, 'drupal-menu-hierarchy')) {
// This is the behaviour in contrib module decoupled_menus.
return $item->{'drupal-menu-hierarchy'}[0];
}
// This is the behaviour in 10.1 and onwards.
assert(property_exists($item, 'hierarchy'));
$hierarchy_array = $item->hierarchy;
return '.' . implode('.', $hierarchy_array);
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment