Skip to main content
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
added 953 characters in body
Source Link
Nico
  • 1
  • 1

I work on a D8 (8.6) I want to hide some item on my menu depending on route param onto this link.

When I try to access the route I get a 403 error and works as expected but the the link inside the menu is still displayed.

I create a custom Accessinterface which return an AccessResult::allowed() or denied() depending on my rules.

Is there a core solution to prevent the link to be displayed on the main menu or I have to handle it in JS ?

My CustomAccessCheck :

class CustomAccessCheck implements AccessInterface
{

  public function access(AccountInterface $account)
  {
    $isAuthenticated = $account->isAuthenticated();

    try {
      $currentGroup = TestEntity::getInstance()->currentGroup;
    } catch (InvalidPluginDefinitionException $e) {
      return AccessResult::forbidden();
    }
    if ( $isAuthenticated &&
      ( !empty($currentGroup["id"]) && isset($currentGroup["IsActive"]) && $currentGroup["IsActive"])
    ) {
      return AccessResult::allowed();
    }
    return AccessResult::forbidden();
  }
}

I configure services and routing.yml in order to run this AccessChecker. The custom menu contain some menu items which target the route configured.

My problem is even if the user don't have access to the route the menu item is displayed.

Thanks for help Nico

I work on a D8 (8.6) I want to hide some item on my menu depending on route param onto this link.

When I try to access the route I get a 403 error and works as expected but the the link inside the menu is still displayed.

Is there a core solution to prevent the link to be displayed on the main menu or I have to handle it in JS ?

Thanks for help Nico

I work on a D8 (8.6) I want to hide some item on my menu depending on route param onto this link.

When I try to access the route I get a 403 error and works as expected but the the link inside the menu is still displayed.

I create a custom Accessinterface which return an AccessResult::allowed() or denied() depending on my rules.

Is there a core solution to prevent the link to be displayed on the main menu or I have to handle it in JS ?

My CustomAccessCheck :

class CustomAccessCheck implements AccessInterface
{

  public function access(AccountInterface $account)
  {
    $isAuthenticated = $account->isAuthenticated();

    try {
      $currentGroup = TestEntity::getInstance()->currentGroup;
    } catch (InvalidPluginDefinitionException $e) {
      return AccessResult::forbidden();
    }
    if ( $isAuthenticated &&
      ( !empty($currentGroup["id"]) && isset($currentGroup["IsActive"]) && $currentGroup["IsActive"])
    ) {
      return AccessResult::allowed();
    }
    return AccessResult::forbidden();
  }
}

I configure services and routing.yml in order to run this AccessChecker. The custom menu contain some menu items which target the route configured.

My problem is even if the user don't have access to the route the menu item is displayed.

Thanks for help Nico

Source Link
Nico
  • 1
  • 1

Hiding menu item depending on specific access

I work on a D8 (8.6) I want to hide some item on my menu depending on route param onto this link.

When I try to access the route I get a 403 error and works as expected but the the link inside the menu is still displayed.

Is there a core solution to prevent the link to be displayed on the main menu or I have to handle it in JS ?

Thanks for help Nico