Incorrect title displayed

2 replies [Last post]
frostmar
Offline
Last seen: 6 years 29 weeks ago
Joined: 2011-06-11

I am having a problem with the following piece of code:

$items['sts-user/%user'] = array(
'title' => 'STS User Details',
'type' => MENU_CALLBACK,
'page callback' => 'drupal_get_form',
'page arguments' => array('user_profile_form', 1),
'access arguments' => array('administer sts user'),
'theme callback' => 'variable_get',
'theme arguments' => array('admin_theme'),
'file' => 'user.pages.inc',
'file path' => '/modules/user',
);
$items['sts-user/%user/default'] = array(
'title' => 'User Details',
'type' => MENU_DEFAULT_LOCAL_TASK,
'weight' => -10,
);
$items['sts-user/%user/notes-comms'] = array(
'title' => 'Notes and Communications',
'page callback' => 'sts_user_communications_notes',
'page arguments' => array(1),
'access arguments' => array('administer sts user'),
'type' => MENU_LOCAL_TASK,
'file' => 'sts_user.forms.inc',
);
$items['sts-user/%user/courses'] = array(
'title' => 'Courses',
'page callback' => 'sts_user_courses',
'page arguments' => array(1),
'access arguments' => array('administer sts user'),
'type' => MENU_LOCAL_TASK,
'file' => 'sts_user.forms.inc',
);

The first (default) item displays correctly with the title "STS Users Details" but the other two have the incorrect title "Home".

Issue 965272 (http://drupal.org/node/965272) seems to address this issue with a patch. It has multiple versions and I cannot apply it. When i look at includes/menu.inc, it appears that the patch has already been applied. Furthermore, it is marked as being a Drupal 8 issue and closed.

I find these Drupal issues very hard to get my head around and, I appear not to be the only one as the last comment asks if there is a solution?

How can I get my titles to show correctly?

Drave Robber
Offline
Last seen: 9 years 6 weeks ago
Joined: 2012-08-07
-

This might be a little confusing, but 'title' here refers to the title of the tab itself, not the title of the page when the said tab is active.
See, for example, node_menu():

  $items['node/%node/edit'] = array(
    'title' => 'Edit',
    'page callback' => 'node_page_edit',
    'page arguments' => array(1),
    'access callback' => 'node_access',
    'access arguments' => array('update', 1),
    'weight' => 0,
    'type' => MENU_LOCAL_TASK,
    'context' => MENU_CONTEXT_PAGE | MENU_CONTEXT_INLINE,
    'file' => 'node.pages.inc',
  );

The tab is named simply 'Edit', but the page callback, node_page_edit(), explicitly sets different (and more infomative) page title:
function node_page_edit($node) {
  $type_name = node_type_get_name($node);
  drupal_set_title(t('<em>Edit @type</em> @title', array('@type' => $type_name, '@title' => $node->title)), PASS_THROUGH);
  return drupal_get_form($node->type . '_node_form', $node);
}

That's what you have to do, too - use drupal_set_title() in your page callback.

P.S. <code></code> tags rock! ;)

frostmar
Offline
Last seen: 6 years 29 weeks ago
Joined: 2011-06-11
Thanks

Thanks Drave Robber (I nearly called you Dave!). I'll take a look when the kids are in bed and I can think straight.

Point taken about html tags. I did not realize I could do that.

Add to playlist

Add to , or

Add to new playlist:

Add to playlist
This is a member-only feature
But, it's easy to become a member

Add to cart:


Loading...
Contact us

Below are the supported keyboard shortcuts for our video player.

space
Start / stop video
shift
Go to next video
shift
Go to previous video
Increase or decrease player speed by 20%
Skip ahead or go back by 15 seconds
1...9
Jump to a percentage (2 is 20%, for example)
f
Toggle full screen
Videos Pricing More Search
BuildAModule Logo Icon BuildAModule Logo Icon
Become a member!
$29
1 month
$156
6 months
10% off
$276
12 months
20% off
All memberships come with the following:
24 / 7 access to the entire 1800+ video library
An innovative video player with a rolling transcript
Extensive Drupal and cross-platform training
A thorough and thoughtful training style
Progress tracking
Take notes on specific video sections
Intuitive multi-user management
How many users?
user
Go solo with a single user, or give multiple team members access through one account and get discounts by bundling multiple users into a single membership.