Currently, title callbacks are used in at least three other contexts besides page titles -- menu links, contextual links, and local tasks. However, there is no way to return different titles for any of these situations.

I'd like to introduce a feature allowing access/title callbacks to take a '%context' argument, having a value of 'page', 'link', 'contextual link', 'local task', and NULL if the context is ambiguous, such as when menu_get_item() is used on an arbitrary path. user_page_title() then could determine whether it should return 'My account' based on $account->uid == $user->uid && $context == 'link'.

I could also see this being useful in other cases, such as reducing UI clutter. A context-aware title callback could keep the title short for local tasks or contextual links, while rendering a longer title in a page context.

CommentFileSizeAuthor
menu-callback-context.patch7.02 KBcarlos8f

Comments

sun’s picture

+++ includes/menu.inc	29 Dec 2009 21:52:02 -0000
@@ -411,7 +416,8 @@
+      $callback_context = ($path == $_GET['q']) ? 'page' : NULL;

@@ -794,11 +806,11 @@
+      _menu_check_access($item, $map, 'link');

@@ -1680,7 +1692,7 @@
+      _menu_translate($item, $map, TRUE, 'local task');

@@ -1899,7 +1911,7 @@
+    _menu_translate($item, $map, TRUE, 'contextual link');

We already have (most of) the required constants for this:

MENU_CONTEXT_NONE
MENU_CONTEXT_PAGE
MENU_CONTEXT_INLINE

Apparently, no context love for links in menu trees yet. ;)

I'm on crack. Are you, too?

damien tournoud’s picture

Version: 7.x-dev » 8.x-dev

That's a no go for Drupal 7 at this point. Let's discuss for Drupal 8.

klausi’s picture

Status: Needs review » Needs work

does not apply anymore.

carlos8f’s picture

Assigned: carlos8f » Unassigned

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.

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.

klausi’s picture

Issue summary: View changes
Status: Needs work » Closed (works as designed)

Drupal has split up routing and menus, so I think this is no longer relevant. Feel free to reopen!