Skip to content

Commit

Permalink
Merge pull request #41 from City-of-Helsinki/UHF-8738_activetrail_sub…
Browse files Browse the repository at this point in the history
…domain

UHF-8738: prevent showing active trail on menuitem for link pointing to subdomain
  • Loading branch information
rpnykanen authored Sep 13, 2023
2 parents f81ea16 + c97664e commit c2497e8
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 1 deletion.
16 changes: 16 additions & 0 deletions fixtures/api-v1-global-menu-en.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,22 @@
"attributes": {},
"weight": 0,
"sub_tree": [
{
"url": "https://paatokset.hel.fi/en/urban-environment-and-traffic/cycling",
"id": "menu_link_content:df660188-d56f-4cb4-9539-32945792da18",
"name": "Decisions",
"parentId": "base:health_and_social_services",
"attributes": {},
"external": true,
"hasItems": false,
"expanded": false,
"parents": [
"menu_link_content:df660188-d56f-4cb4-9539-32945792da18",
"base:health_and_social_services"
],
"weight": -49,
"sub_tree": []
},
{
"url": "https://helfi-kymp.docker.so/en/urban-environment-and-traffic/parking",
"id": "menu_link_content:7c9ddcc2-4d07-4785-8940-046b4cb85fb4",
Expand Down
6 changes: 5 additions & 1 deletion src/ExternalMenuTreeBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,11 @@ private function createLink(
* Returns true or false.
*/
private function inActiveTrail(object $item): bool {
if ($item->url->isRouted() && $item->url->getRouteName() === '<nolink>') {
if (
$item->url->isRouted() &&
$item->url->getRouteName() === '<nolink>' ||
$item->external
) {
return FALSE;
}
if (!$request = $this->requestStack->getCurrentRequest()) {
Expand Down
11 changes: 11 additions & 0 deletions tests/src/Kernel/ExternalMenuTreeBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace Drupal\Tests\helfi_navigation\Kernel;

use Drupal\Core\DependencyInjection\ContainerBuilder;
use Drupal\helfi_navigation\ExternalMenuTreeBuilder;
use Prophecy\PhpUnit\ProphecyTrait;
use Prophecy\Prophecy\ObjectProphecy;
Expand All @@ -20,6 +21,16 @@ class ExternalMenuTreeBuilderTest extends MenuTreeBuilderTestBase {

use ProphecyTrait;

/**
* {@inheritdoc}
*/
public function register(ContainerBuilder $container) : void {
$container->setParameter('helfi_api_base.internal_domains', [
'localhost',
]);
parent::register($container);
}

/**
* Constructs a new external menu tree.
*
Expand Down

0 comments on commit c2497e8

Please sign in to comment.