1

I would like to have a block that contains basic profile of authenticated user so that they can see their username, photo, email and log out link.

Any help will be appreciated.

7

You can use Author Pane module to display a block of user information.

Author Pane is a block of information about a given user, like those typically found on a forum post, but can be used in other places as well. From core, it collects the user picture, name, join date, online status, contact link, and profile information. In addition, any module or theme can feed it more information via the preprocess system. All of this information is then gathered and displayed using a template file.

If you do not want to use this module, then you can create a views to display user information.

  • Go to Administration -> Structure -> Views
  • Click on "Add new view" link
  • Set name for views in "View name" field and select "users" from "show" drop down.
  • Click on "Continue and Edit" button
  • Create a block display for the views.
  • Add "User: Picture", "User: E-mail", "User: Name" and "Global: Custom text (Custom text)".
  • Check check-box "Output this field as a link" under "Rewrite results" section for "Global: Custom text" and set "user/logout" as Link path for the field.
  • Save the views
0

Hope this will help you...

<?php
/**
 * Implementation of hook_block_info().
 */
function mymodule_block_info() {
  $blocks['my-block-id'] = array(
    'info' => t('User Summary'),
  );
  return $blocks;
}

 /**
 * Implementation of hook_block_view().
 */
function mymodule_block_view($delta='') {
  $block = array();
  switch ($delta) {
    case 'my-block-id':
     // $block['subject'] = t('Block Name');
      $block['content'] = user_contents();
      break;
  }
  return $block;
}
function user_contents() {
global $user;
//kpr($user);
$mstr = '';
$mstr .='<div id="first_block" >';
    $mstr .='<fieldset><legend>My Personal Details</legend><div style="margin-top:15px;"><b>User Name.</b></div><div style="">&nbsp;</div><div class="user_name">'.$user->name.'</div>';
    $mstr .='<div style=""><b>User Id:</b> </div><div style="">&nbsp;</div><div id="editme2" class="name1">'.$user->uid.'</div>';
    $mstr .='<div style=""><b>Mail id </b></div><div style="">&nbsp;</div><div class="">'.$user->mail.'</div>';
    $mstr .='<div style=""><b>Timezone </b></div><div style="">&nbsp;</div><div class="">'.$user->timezone.'</div>';
    $mstr .='</div>';

return $mstr;

}

this will create a block namely "user summary"

1
  • I got it. Thanks everyone so much! Thank Jayendra Kainthola! This's very helpful, I followed your tut by creating a view to get the block.
    – user23677
    Nov 14 '13 at 9:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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