0

I'm very new to drupal, I've got a basic understanding of PHP and how it should be written but I think I'm still struggling with the concept of where to add code, at what point I need to jump in to edit things and make my own style do its thing

All I want to do is change my default user menu from:

User Menu

 - My Account 
 - Log out

To

Logged in as:
[username]

My Account 

Log Out (where both buttons have mybtn class applied to them rather than in a ul)

I've seen I can remove the ul function from the list that is outputted with the following code

function MYTHEME_menu_tree__user_menu(&$variables) {
 return $variables['tree'];
}

And I've also tried to add the username to the content of the username with this block

function MYTHEME_preprocess_block(&$vars){

  global $user;
  $block =& $vars['block'];

  if ($block->module == 'system' && $block->delta == 'user-menu') {
    if (user_is_logged_in()) {
      $block->content .= check_plain($user->name);
    }
  }

}

(this code was modified from someone explaining how to change the subject of the block to the username)

I'd really appreciate any help with where to go next

Kind regards

1 Answer 1

1

I ended up slowly working my way towards the result, my main issue was trying to get the dpm to show me what content I can change - but that's just because I'm, still slightly unfamiliar with how the whole process runs

function MYTHEME_menu_tree__user_menu(&$variables) {
 return '<ul>'. $variables['tree'] .'</ul>';
}

function MYTHEME_menu_link__user_menu(array $variables) {
  $element = $variables['element'];
  $sub_menu = '';

  if ($element['#below']) {
    $sub_menu = drupal_render($element['#below']);
  }

  $element['#localized_options']['attributes'] = array('class' => 'my-btn');

  $output = l($element['#title'], $element['#href'], $element['#localized_options']);
  return '<li>' . $output . $sub_menu . "</li>\n";
}

function MYTHEME_preprocess_block(&$variables){
  global $user;
  $block =& $variables['block'];

  if ($block->module == 'system' && $block->delta == 'user-menu') {
    if (user_is_logged_in()) {
      $variables['content'] = check_plain($user->name) . $variables['content'];
    }
  }

}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.