Removing the view tab from embedded profiles on user pages
Solution:
How to remove view/edit tabs?
nodeprofile remove embedded view and edit links from profile
http://api.drupal.org/api/function/theme_menu_local_tasks/5
Note the approach:
function theme_menu_local_tasks() {
$output = '';
if ($primary = menu_primary_local_tasks()) {
$output .= "<ul class=\"tabs primary\">\n". $primary ."</ul>\n";
}
if ($secondary = menu_secondary_local_tasks()) {
$output .= "<ul class=\"tabs secondary\">\n". $secondary ."</ul>\n";
}
return $output;
}
get rid of view/edit links for profiles. TODO: redirect all profile node links to the appropriate user account.
Ironically, this did the opposite of what I'd hoped: on the user/123 page the embedded profile node still has the unwanted view and edit links, while when looking at the profile node on its own, the view and edit links (local task tabs in Drupal-speak) are neatly and unnecessarily removed.
So we thought we'd give hook_menu_alter a try. Too bad it only pretends to exist in Drupal 5.
File this with unicorns, the Loch Ness monster, and George W. Bush's legitimacy. There's no there, there:
/**
* Implementation of hook_menu_alter
*
* http://api.drupal.org/api/function/hook_menu_alter/5
*/
function wsf_action_hook_menu_alter(&$callbacks) {
drupal_set_message('.');
if (isset($shortcircuit)) {
print_r($callbacks);
global $shortcircuit;
$shortcircuit = TRUE;
}
Nodeprofile module itself, however, has a checkbox on its per-content type settings page to "Include an edit link to the display" or not-- that gets rid of the edit link but there's still a View link in the inimitable form of Drupal's local menu tasks.
Still, if nodeprofile can turn off the edit link...
And here we are, in an implementation of hook_user in nodeprofile.module! Note that Agaric has edited out the parts we aren't interested in here.
/**
* Implementation of hook_user():
* Delete the profile node when the user is deleted.
*/
function nodeprofile_user($op, &$edit, &$account, $category = NULL) {
global $user;...
case 'view':
$fields = array();
foreach (nodeprofile_get_types('names') as $type => $type_name) {
if ($style = nodeprofile_get_settings('user_display', $type)) {
$output = array(
'#type' => 'nodeprofile_display_'. nodeprofile_get_settings('user_display', $type),
'#tabs' => nodeprofile_get_settings('edit_link', $type) ? array('view', 'edit') : array('view'),
'#uid' => $account->uid,
'#content_type' => $type,
);
$title = $style != 'link' ? check_plain($type_name) : '';
if ($content = drupal_render($output)) {
$fields[$title][$type] = array(
'title' => NULL,
'value' => $content,
'class' => 'nodeprofile-display',
'weight' => nodeprofile_get_settings('weight', $type),
);
$fields[$title]['weight'] = nodeprofile_get_settings('weight', $type);
}
else if ($account->uid == $user->uid && nodeprofile_get_settings('add_link', $type) && user_access('create '. $type .' content')) {
$fields[$type_name]['profile']['value'] = l(t("Create your @profile_node.", array('@profile_node' => $type_name)), nodeprofile_get_add_path($type), array(), drupal_get_destination());
}
}
}
if (isset($fields['']) && count($fields['']) > 1) {
uasort($fields[''], '_user_sort'); //sorts the links if there are multiple links
}
uasort($fields, '_user_sort');
//remove the weights we used for sorting, because user module can't display them..
foreach ($fields as $key => $category) {
$fields[$key] = array_filter($category, 'is_array');
}
return $fields;
...
}
Unfortunately, there is no hook_user_alter to mess with this stuff after nodeprofile's implementation of hook_alter creates it. In fact, I can't even see what it's doing when I print out the variables in my own hook_alter-- the view modifications must go directly to being shown. (See attached file-- all you can get is a dump of the user account variable.)
I don't think Agaric doing our own identical implementation would override in any way, so the only approach I think is to patch the module.
Like so:
This is as above, with the #tab line cut out:
<
pre>
$output = array(
'#type' => 'nodeprofile_display_'. nodeprofile_get_settings('user_display', $type),
'#uid' => $account->uid,
'#content_type' => $type,
);
/* ben-agaric todo: turn this into a patch, with a button rather than checkbox choice among view, view & edit, or no tabs
'#tabs' => array(), // nodeprofile_get_settings('edit_link', $type) ? array('view', 'edit') : array('view'),
*/
</pre>
Comments
So two important additions
So two important additions to this:
First, a minimal profile looks really, really weird with no title, and no tabs (or even with a title no edit tab when you're the super-user is disconcerting, I thought it was junk content). So privileged users should get the edit tab.
And/or second, the profile page should redirect to the user page which has the profile embedded.
So this is marked @TODO ben-agaric!
I thoroughly confused myself because of this:
Post new comment