Incorrect title displayed
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?
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.
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():
'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:
$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! ;)