Score:1

How to hide the tabs on the user account if it is not his account?

ly flag

My users have permission to view other users' accounts. Only the "View" tab page. This is exactly what I want.

On the user account, by default, there are three tabs:

  • View

  • Shortcuts

  • Edit

If I am user A and I go to my account, I see the tabs. If I'm user A and I go to user B's account, I don't go to his tab (it makes sense).

Now if I create a page view (e.g. bookmarks) with a menu tab, for user accounts. If I'm User A and go to User B's account, I can see the "Bookmarks" tab.

How to hide tabs on user accounts except current user account?

There is no permission to do this.

apaderno avatar
us flag
Instead of deleting a question to re-ask the same question again, you should have edited the question to make it on-topic. Asking again the same question has only the effect to make the new question be closed as duplicate.
Score:1
in flag

You can add a RouteSubscriber with a custom access check to accomplish this. Something like:

class RouteSubscriber extends RouteSubscriberBase {

  /**
   * {@inheritdoc}
   */
  protected function alterRoutes(RouteCollection $collection) {
    if ($route = $collection->get('entity.user.canonical')) {
      $route->setRequirement('_profile_access', '\Drupal\mymodule\Access\ProfileAccessCheck::access');
    }

    if ($route = $collection->get('entity.user.edit_form')) {
      $route->setRequirement('_user_edit_access', '\Drupal\mymodule\Access\AccountEditCheck::access');
    }

    if ($route = $collection->get('entity.user.delete_form')) {
      $route->setRequirement('_user_delete_access', '\Drupal\mymodule\Access\AccountDeleteCheck::access');
    }

    // more entries...
  }

}

and so on, and so forth.

In the access classes you can implement custom logic that should dictate visibility.

eric55 avatar
ly flag
Thanks, but I don't want to code. What is the solution ? It's something that should be part of Drupal to limit access to user account tabs
Kevin avatar
in flag
You've added a View that adds tabs to the User routes. There is no out of the box function that dynamically creates new permissions to Views routes. Even if it did, a permission only checks access to the route itself, not that you _specifically_ have access. This is especially true since you have given access to view user profiles, so as far as the application is concerned, user/*/(tab) is permitted. This is where access checks come in.
eric55 avatar
ly flag
Is there anything in the UI to do this without having to create some code? Or a contrib module that does this from Drupal?
Mario Steinitz avatar
id flag
This is the second time you asked about this issue and you keep asking for module suggestions. Please understand that Drupal and the many contributed modules are a huge and versatile toolbox provided by the Drupal community. BUT it won't necessarily fit for all thinkable use cases out of the box. I've worked on hundreds of Drupal sites. None of them didn't require at least a little bit of custom programming. Unfortunately, we can't and won't do this work for you here. This Q&A site is for pointing out solutions to narrowly scoped questions. You can search for contrib modules on drupal.org.
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.