In admin/structure/menu/manage/account, the "My account" link has "(logged in users only)" appended.
The same should show for "Log out".
Also, it should show not only for menu items provided by the user module, because the same behaviour hold for manually created menu items targeting these paths.

Finally, for "user/login" and "user/register" the opposite holds, and the menu items should be appended "(anonymous users only)".

Comments

pancho’s picture

pancho’s picture

Status: Active » Needs review

Status: Needs review » Needs work

The last submitted patch, 1: loggedin_anonymous_only.2268793-1.patch, failed testing.

wuinfo - bill wu’s picture

I would suggest to remove those appended text completely. Links for anonymous user will only show up for an anonymous user. Links for authenticated user will show up on logged in users. The code here have some limitation and is not able to cover all those link. I mean the custom menu links.

wuinfo - bill wu’s picture

Issue tags: +User interface
wuinfo - bill wu’s picture

Status: Needs work » Needs review
StatusFileSize
new80.99 KB
new1003 bytes

here is the patch to remove those appended text.

appended text

dawehner’s picture

+++ b/core/modules/menu_ui/src/MenuForm.php
@@ -354,12 +354,6 @@ protected function buildOverviewTreeForm($tree, $delta) {
-        if (!$link->isEnabled()) {
-          $form[$id]['title']['#markup'] .= ' (' . $this->t('disabled') . ')';

What about replacing it with some css class, so we can style it just different?

wuinfo - bill wu’s picture

         $form[$id]['#attributes'] = $link->isEnabled() ? array('class' => array('menu-enabled')) : array('class' => array('menu-disabled'));

Thanks, @dawehner We can theme it differently now. There is a class there for it.

dawehner’s picture

Just adding a tag to ask whether its fine to remove the labels in terms of accessibility? Maybe we could just provide a hidden label by default.

Version: 8.0.x-dev » 8.1.x-dev

Drupal 8.0.6 was released on April 6 and is the final bugfix release for the Drupal 8.0.x series. Drupal 8.0.x will not receive any further development aside from security fixes. Drupal 8.1.0-rc1 is now available and sites should prepare to update to 8.1.0.

Bug reports should be targeted against the 8.1.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.2.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

drugan’s picture

StatusFileSize
new205.78 KB
new2.53 KB

I think that the idea to remove appended text to /user/% links is not a good one because even now we have a lot of questions like "Why my Log in link is not shown" or "Why it is still there after logging in" and removing text will make harder for newcomers to understand how the Drupal works.

Instead we need to extend explanation of workings of those links in an appended text to avoid disambiguation.

appended text example

pwolanin’s picture

Status: Needs review » Needs work
+++ b/core/modules/menu_ui/src/MenuForm.php
@@ -349,20 +349,23 @@ protected function buildOverviewTreeForm($tree, $delta) {
+        elseif ($route == 'user.logout' || $route == 'user.page' || $route == 'user.register') {
+          $suffix = $route != 'user.page' && $route == $link->getPluginId() ?
+            $this->t('Shown as <q>Log in</q> for anonymous users') :
+            $this->t('Shown only for authenticated users');
+          $form[$id]['title']['#suffix'] = ' (' . $suffix . ')';
         }

This long ternary doesn't make much sense to me nor restricting it to cases where the plugin ID matches

It seems like in this overall stretch of code we should have a $suffix variable that may get populated and then appended in parens if non-empty.

pwolanin’s picture

Also - we should consider string freeze? IS this really a big fix?

drugan’s picture

The purpose of the ternary is to check if $route is equal to $link->getPluginId(), which only with system provided "Log out" and "My account" are the same, and then check if it is not "My account", which just disappears for anonymous users, not toggles as "Log out" link does. I feel that these conditions might be checked in a more elegant way but for now can't figure out this.

As for the string freeze I do not agree. Just google "drupal 8 log in log out link" and see that the issue continue to appear again and again for at least 5 years long. And now has migrated to drupal 8 in an unchanged state. Let's just say to users that this link works so and so, but the others other way.

Version: 8.1.x-dev » 8.2.x-dev

Drupal 8.1.9 was released on September 7 and is the final bugfix release for the Drupal 8.1.x series. Drupal 8.1.x will not receive any further development aside from security fixes. Drupal 8.2.0-rc1 is now available and sites should prepare to upgrade to 8.2.0.

Bug reports should be targeted against the 8.2.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.3.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.2.x-dev » 8.3.x-dev

Drupal 8.2.6 was released on February 1, 2017 and is the final full bugfix release for the Drupal 8.2.x series. Drupal 8.2.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.3.0 on April 5, 2017. (Drupal 8.3.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.3.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.6 was released on August 2, 2017 and is the final full bugfix release for the Drupal 8.3.x series. Drupal 8.3.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.4.0 on October 4, 2017. (Drupal 8.4.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.4.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.4 was released on January 3, 2018 and is the final full bugfix release for the Drupal 8.4.x series. Drupal 8.4.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.5.0 on March 7, 2018. (Drupal 8.5.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.5.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.6 was released on August 1, 2018 and is the final bugfix release for the Drupal 8.5.x series. Drupal 8.5.x will not receive any further development aside from security fixes. Sites should prepare to update to 8.6.0 on September 5, 2018. (Drupal 8.6.0-rc1 is available for testing.)

Bug reports should be targeted against the 8.6.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

chris pergantis’s picture

Just from the most flexible use point of view. Why not give the admins (or others with edit menu permission) the ability to list links that are restricted from a central control UI. If someone wanted to not have a menu item show they could add that to the list and set permissions. Just before any menu item is being rendered the link contained in the list would then check the permissions of that link before it is rendered. Of course, for ease of use by newbies the list can be preloaded.

Or just add role permissions to each menu item.

In any given case it is the link that a menu item references that is the controlling data field for permitted actions. Why have specialty generated menu items? It is easier for both the development and for the end-user to have a more simple approach. More to read decipher and understand is not necessarily easier.

Version: 8.6.x-dev » 8.8.x-dev

Drupal 8.6.x will not receive any further development aside from security fixes. Bug reports should be targeted against the 8.8.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.9.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.7 was released on June 3, 2020 and is the final full bugfix release for the Drupal 8.8.x series. Drupal 8.8.x will not receive any further development aside from security fixes. Sites should prepare to update to Drupal 8.9.0 or Drupal 9.0.0 for ongoing support.

Bug reports should be targeted against the 8.9.x-dev branch from now on, and new development or disruptive changes should be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

quietone’s picture

Title: Menu links for logged in / anonymous users » Add help text to Menu links for logged in / anonymous users
Issue summary: View changes
Status: Needs work » Closed (outdated)
Issue tags: +Bug Smash Initiative
StatusFileSize
new9.64 KB

I have read the issue and I think the problem stated in the IS has become outdated. I have updated the title to reflect what I understand to be the issue being addressed.

On Drupal 9.3.x standard install admin/structure/menu/manage/account looks like this:

Both the My account and the Log out link have explanatory text in parenthesis.

The IS includes another point, changing "user/login" and "user/register". Those links do not appear on the admin page. That, to me, seems like a feature request for a separate issue.

Therefore, closing as outdated. If this is incorrect reopen the issue, by setting the status to 'Active', update the Issue Summary (use the template) add a comment explaining what still needs to be done.

Thanks!