I'm trying to create something which I think should be quite fundamental to Drupal, but have been struggling with how to impliment it. I want to create a custom navigation in the menu builder and I want to add items which have a dynamic path.

i.e.

user/<?php print $user->uid ?>

or

user/<?php print $user->uid ?>/guestbook

etc.

How do I go about doing this?

More specifically I need a menu when you're on the user pages which has these items:

Profile - (user/ print $account->uid )
Blog - (blog/ print $account->uid ) will this not show if the user doesn't have a blog?
Comment wall - (user/ print $account->uid /guesbook) - Guestbook module
Edit profile - (user/ print $account->uid /edit/profile) - will this not show if the user doesn't have permissions?
Edit account - (user/ print $account->uid /edit) - will this not show if the user doesn't have permissions?

This requirement comes from a frustration with the flexibility/ ease to customise the tabs. So what I'd like to do is remove tabs entirely apart from view/ edit page content for admins, and replace it with a custom menu.

Thanks in advance.

Comments

unxposed’s picture

Okay I think the best way of doing this may be by creating a custom block which I can position relevently. Just having some issues with the following code which I'm placing in the module tpl.php file - it doesn;t print the $account->uid - any help would be much appreciated. Thanks.

<div id="block-<?php print $block->module . '-' . $block->delta; ?>" class="<?php print $classes; ?>">

<div class="block-inner">

<h2 class="title">Profile navigation</h2>

<p>This is a profile menu for user number <?php print $account->uid ?>, being viewed by user number <?php print $user->uid ?></p>

<div class="content">
<ul class="menu">
<li class="leaf"><a href="/user/<?php print $account->uid ?>" title="Profile">
<?php if ($account->uid == $user->uid) {
	echo 'My ';
} ?>
Profile</a></li>
<li class="leaf"><a href="/blog/<?php print $account->uid ?>" title="Blog">Blog</a></li>
<li class="leaf"><a href="/user/<?php print $account->uid ?>/guestbook" title="Comment wall">Comment wall</a></li>
<li class="leaf"><a href="user/<?php print $account->uid ?>/edit/profile" title="Edit profile">Edit profile</a></li>
<li class="leaf"><a href="user/<?php print $account->uid ?>/edit" title="Edit account">Edit account</a></li>
</ul>
</div>

</div></div> <!-- /block-inner, /block -->
unxposed’s picture

This is my final code that creates a user profile menu with the following links:

> Profile ('My profile' if users own profile.
> Blog (If user has posted a blog entry)
> Comment wall (guestbook module)
> Edit my profile (Link to edit custom user profile info - only available if own profile)
> Edit my account (Account details - only available if own profile)

I'm not very good at php so could probably do with a lot of sorting out. Just thought it may be useful for someone.

<?php

$profile = arg(1);
$user_id = $user->uid;

?>

<div id="block-<?php print $block->module . '-' . $block->delta; ?>" class="<?php print $classes; ?>">

<div class="block-inner">

<h2 class="title">Profile navigation</h2>

<div class="content">
<ul class="menu">
<li class="leaf
<?php
if ((arg(0) == 'user') && is_numeric(arg(1)) && ((arg(2) == '') OR (arg(2) == 'relationships'))) {
print ' active-trail';
}
?>
"><a href="/user/<?php print arg(1) ?>" title="Profile">
<?php if ($user_id == $profile) {
	echo 'My ';
} ?>
Profile</a></li>

<?php
$account->uid = $profile;
if (_blog_post_exists($account)) {
?>

<li class="leaf
<?php
if ((arg(0) == 'blog') && is_numeric(arg(1)) && (arg(2) == '')) {
print ' active-trail';
}
?>
"><a href="/blog/<?php print $profile ?>" title="Blog">Blog</a></li>

<?php
}
?>

<li class="leaf
<?php
if ((arg(0) == 'user') && is_numeric(arg(1)) && (arg(2) == 'guestbook')) {
print ' active-trail';
}
?>
"><a href="/user/<?php print $profile ?>/guestbook" title="Comment wall">Comment wall</a></li>
<?php if ($user_id == $profile) { ?>
<li class="leaf
<?php
if ((arg(0) == 'user') && is_numeric(arg(1)) && (arg(2) == 'edit') && (arg(3) == 'My profile')) {
print ' active-trail';
}
?>
"><a href="/user/<?php print $profile ?>/edit/My profile" title="Edit my profile">Edit my profile</a></li>
<li class="leaf
<?php
if ((arg(0) == 'user') && is_numeric(arg(1)) && (arg(2) == 'edit') && (arg(3) == '')) {
print ' active-trail';
}
?>
"><a href="/user/<?php print $profile ?>/edit" title="Edit my account">Edit my account</a></li>
<?php } ?>
</ul>
</div>

</div></div> <!-- /block-inner, /block -->

akolahi’s picture

Thank you for sharing.

I wonder if it is best to test whether the viewing user can edit (profile, account etc) rather than whether they are the same person as the profile. In other words, rather than test whether they are viewing their own profile page, you may want to test if they can edit that particular profile page.

JohnnyHa’s picture

I want to expand on this topic.
I am creating just the same thing as you, but where i am stuck is what if some users are admins ? They should have access to extra links like Write Content and Admin Menu.

Right now my code is:

global $user;
if ($user->uid) :
Logged in as: print l($user->name,'user/'.$user->uid); |
print l("Log out | ","logout");
print l("Admin" , "admin");

Which displays "Logged in as username Log out | Admin

Problem here is the last line where it says admin. That shouldnt show if you are just a registered user.
Is it any way i can do a if statement with only specific roles ? Like developer and writer ?
Or probably better doing it by access.

Like

 function check_access() {
if (user_access('<?php print l("Admin" , "admin"); 

Havent gotten the code to work yet but i think i am on the right track.

UPDATE!

if (user_access('print l("Admin" , "admin");')) {}

That removes the Admin link but both for users with access and without. I am an admin so it should display or am i doing something wrong ?

JohnnyHa’s picture

Anyone who can help me with this problem ? I simply need help in using the user_access function to display the Admin link if he got access or not.
Probably extremely easy but maybe i have typed it wrong or something.