0

I want to change the below function,

function user_block_view($delta = '') {         // Line 1 //
  global $user;                                 // Line 2 //
  $block = array();                             // Line 3 //
  switch ($delta) {                             // Line 4 //
    case 'login':                               // Line 5 //
      if (!$user->uid && !(arg(0) == 'user' && !is_numeric(arg(1)))) {
        $block['subject'] = t('User login');    // Line 7 //
        $block['content'] = drupal_get_form('user_login_block');
      }                                         // Line 9 //
    return $block; // Line 10
  ...
} // Line n

I actually want to add

else if($user -> uid){
  $block['subject'] = t('Subject'); 
  $block['content'] = someotherfunction();
}

after the line 9 of the above code.

How can I implement that in my template.php (custom theme)

I tried a lot and didn't succeed yet.

Muhammad Reda
  • 26,379
  • 14
  • 93
  • 105

2 Answers2

2
<?php
function phptemplate_preprocess_block(&$vars) {    
    if (isset($vars['block'])) {
        if($vars['block']->module == 'user') {
            global $user;
            if (!$user->uid && !(arg(0) == 'user' && !is_numeric(arg(1)))) {
                $vars['block']->subject = t('User login');
                $vars['block']->content = drupal_get_form('user_login_block');
            }
            else if($user->uid){
                $vars['block']->subject = t('Subject');
                $vars['block']->content = someotherfunction();
            }
        }
    }
}

That should work.

Here is more info: how to override $block->content in drupal?

Community
  • 1
  • 1
Michal
  • 1,010
  • 2
  • 8
  • 18
  • Please explain a bit more how I can add the else if condition. Because if the user is not logged in it will show the login form. I want to add a else if ( user logged in ) condition to show some other block in the same region – Gokul Gopala Krishnan Sep 10 '13 at 09:20
  • Did this help you? If so, accept is as answer so other can benefit from it. – Michal Sep 13 '13 at 17:57
0
  switch ($delta) {                             // Line 4 //
    case 'login':                               // Line 5 //
      if (!$user->uid && !(arg(0) == 'user' && !is_numeric(arg(1)))) {
        $block['subject'] = t('User login');    // Line 7 //
        $block['content'] = drupal_get_form('user_login_block');
      }  
     else if($user->uid){  // Line 9 //
       $block['subject'] = t('Subject'); 
       $block['content'] = someotherfunction();
      }                                     
    return $block; // 

But remove all the spaces between $user -> uid.

Bere
  • 1,627
  • 2
  • 16
  • 22
  • I don't appreciate this. This is what we have in the user module. I don't want to touch it. As my title saying I want to know about hook_block_view_alter not to edit the user.module – Gokul Gopala Krishnan Sep 10 '13 at 09:16