User login

Removing the view tab from embedded profiles on user pages

Solution:

How to remove view/edit tabs?

http://drupal.org/node/83090

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>

Resolution

Searched words: 
tabs edit drupal menu_primary_local_tasks nodeprofile remove embedded view and edit links from profile

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:

I3IVIIVI (1:19:12 PM): For other utter weirdness, check out, say, http://dev.wsf2008.net/eng/node/277
Dan Hak (1:20:03 PM): should I report it as inappropriate?
Dan Hak (1:20:05 PM): :P
I3IVIIVI (1:21:37 PM): yeah... along with usernodes 24, 159, 92, 98, and 274.
I3IVIIVI (1:24:59 PM): urgh. Apparently content without a title doesn't have tags.
I3IVIIVI (1:25:07 PM): err, tabs I mean
I3IVIIVI (1:26:06 PM): No, apparently *profiles in general* don't have tabs. What did I do?
Dan Hak (1:26:19 PM): no idea
I3IVIIVI (1:26:30 PM): oh... I removed the tabs
I3IVIIVI (1:26:39 PM): so the profile page would look better
I3IVIIVI (1:26:48 PM): that is, the user page which has an embedded profile
I3IVIIVI (1:26:55 PM): I'm sure I documented this....

Post new comment

The content of this field is kept private and will not be shown publicly.
  • You may post code using <code>...</code> (generic) or <?php ... ?> (highlighted PHP) tags.
  • You can use Markdown syntax to format and style the text. Also see Markdown Extra for tables, footnotes, and more.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <img> <blockquote> <small> <h2> <h3> <h4> <h5> <h6> <sub> <sup> <p> <br> <strike> <table> <tr> <td> <thead> <th> <tbody> <tt> <output>
  • Lines and paragraphs break automatically.

More information about formatting options

By submitting this form, you accept the Mollom privacy policy.