diff --git a/src/RemoteMenuLink.php b/src/RemoteMenuLink.php index 6d92976553de626b68a699e34104647e4a8e43ff..e17a513110617875c7c54f9e2fbbf267ab370be4 100644 --- a/src/RemoteMenuLink.php +++ b/src/RemoteMenuLink.php @@ -34,7 +34,7 @@ class RemoteMenuLink extends MenuLinkBase { [ 'menu_name' => 'remote', 'parent' => '', - 'url' => 'https://cancer.ddev.site' . $link, + 'url' => $link, 'options' => [], 'title' => $title, 'class' => MenuLinkDefault::class, diff --git a/src/RemoteMenuParser.php b/src/RemoteMenuParser.php index 4f6238c964fb2924f0122c79834e296fc5bcd33a..5b4633c3bd588b30dbdc46dcb5f6dc01fcaeb5b3 100644 --- a/src/RemoteMenuParser.php +++ b/src/RemoteMenuParser.php @@ -86,7 +86,9 @@ class RemoteMenuParser { $data = static::insertLink($item->{'drupal-menu-hierarchy'}[0], $item->href, $item->title, $data); } // Convert the tree array into a tree of RemoteMenuLink objects. - static::convertToObjects($data); + $base_url = parse_url($url,PHP_URL_SCHEME) . '://' . parse_url($url,PHP_URL_HOST); + $base_url = trim($base_url,'/'); + static::convertToObjects($data, $base_url); $expire_time_config = $this->config->get('cache_expire') ?? 24 * 60 * 60; $expire_time_config = (int) $expire_time_config; @@ -105,17 +107,20 @@ class RemoteMenuParser { * * @param array $input * The tree of links. + * @param string $base_url + * The base site url of the remote links. */ - protected static function convertToObjects(array &$input): void { + protected static function convertToObjects(array &$input, string $base_url): void { foreach ($input as &$item) { $weight = 0; if (array_key_exists('subtree', $item)) { - static::convertToObjects($item['subtree']); + static::convertToObjects($item['subtree'], $base_url); } else { $item['subtree'] = []; } - $link = RemoteMenuLink::fromLink($item['link'], $item['title'], $weight, $item['location']); + $full_link = $base_url . $item['link']; + $link = RemoteMenuLink::fromLink($full_link, $item['title'], $weight, $item['location']); $has_children = !empty($item['subtree']); $depth = mb_substr_count($item['location'], '.'); $item = new MenuLinkTreeElement($link, $has_children, $depth, FALSE, $item['subtree']); diff --git a/tests/src/Unit/ParserTest.php b/tests/src/Unit/ParserTest.php index 7367f1abae03a8b10f839de37c23852b074c82d8..55d57b81ec79260f6192963f0b47da3d3ffe4e00 100644 --- a/tests/src/Unit/ParserTest.php +++ b/tests/src/Unit/ParserTest.php @@ -131,7 +131,7 @@ class ParserTest extends UnitTestCase { $class = new \ReflectionClass(RemoteMenuParser::class); $method = $class->getMethod('convertToObjects'); $method->setAccessible(TRUE); - $method->invokeArgs(NULL, [&$data]); + $method->invokeArgs(NULL, [&$data, 'https://site.com']); // Check the top level items. static::assertArrayHasKey('000', $data);