Question

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.

Was it helpful?

Solution

<?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?

OTHER TIPS

  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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top