1

There is function used in Ubercart module :

function theme_uc_recurring_user_table($variables) {
    ........
}

I want to override result of this function and did by below method in template.php file of my theme:

function MYTHEME_preprocess_table(&$variables) {
  global $user;
  if ($user->uid) {
    if (current_path() == "user/me/recurring-fees") {
      if(!$variables['header'][7]) {
        $variables['header'][7] = "Donation";
      }
      if(!$variables['rows'][0]['data'][7]) {
        $variables['rows'][0]['data'][7] = l('Update Donation', '/donation');
      }
    }
  }
}

enter image description here

I just added table column header and data below that. But I did this by current path but I think there must be some right approach.

I am trying to find but not able to figure out how exactly we can achieve this.

Please suggest !! Thanks

4
  • Try MYTHEME_preprocess_uc_recurring_user_table() ?
    – Jimmy Ko
    Aug 3 '16 at 10:27
  • I though this is possible with only theme function and not table function. I will try this now. Thanks!
    – jas
    Aug 3 '16 at 10:29
  • In this way it does not give out put of rows and data. I think its not working this way. Output come like Array ( [uid] => 1116 [context] => Array ( ) [theme_hook_original] => uc_recurring_user_table [theme_hook_suggestions] => Array ( ) )
    – jas
    Aug 3 '16 at 10:32
  • How about overriding theme_uc_recurring_user_table() with hook_theme_registry_alter? Do you feel comfortable with altering theme registry?
    – Jimmy Ko
    Aug 3 '16 at 10:54
2

theme_uc_recurring_user_table() is a theme hook (not a table function), and its preprocess function is hook_preprocess_uc_recurring_user_table().
From the preprocess function you can just change the content of $variables which, in the case of theme_theme_uc_recurring_user_table() just contains $variables['uid'].

What you need to do is overriding the theme hook implemented from the module, which is quite easy, since you are doing it from a theme.

function MYTHEME_uc_recurring_user_table($variables) {
  $uid = $variables['uid'];
  drupal_add_css(drupal_get_path('module', 'uc_recurring') . '/uc_recurring.css');

  // Set up a header array for the table.
  $header = array(t('Order'), t('Amount'), t('Interval'), t('Next charge'), t('Status'), t('Remaining'), t('Options'));

  if ($GLOBALS['user']->uid) {
    $header[] = t('Donations');
  }

  $recurring_states = uc_recurring_fee_status_label();

  // Build an array of rows representing the user's fees.
  $rows = array();

  foreach (uc_recurring_get_user_fees($uid) as $fee) {
    // Get the user operations links for the current fee.
    $ops = uc_recurring_get_fee_ops('user', $fee);

    // Add the row to the table for display.
    $rows[] = array(
      'data' => array(
        l($fee->order_id, 'user/' . $uid . '/order/' . $fee->order_id),
        theme('uc_price', $fee->fee_amount),
        array(
          'data' => check_plain($fee->regular_interval),
          'nowrap' => 'nowrap',
        ),
        format_date($fee->next_charge, 'short'),
        '<span class="recurring-status-' . intval($fee->status) . '">' . $recurring_states[$fee->status] . '</span>',
        $fee->remaining_intervals < 0 ? t('Until cancelled') : $fee->remaining_intervals,
        array(
          'data' => implode(' | ', $ops),
          'nowrap' => 'nowrap',
        ),
      ),
    );
  }

  if (empty($rows)) {
    $rows[] = array(array(
        'data' => t('Your account has no recurring fees.'),
        'colspan' => 7,
      ));
  }
  elseif ($GLOBALS['user']->uid) {
    $rows[0]['data'][] = l('Update Donation', '/donation');
  }

  return theme('table', array('header' => $header, 'rows' => $rows));
}
3
  • quite easy becomes quite east lol
    – Jimmy Ko
    Aug 3 '16 at 10:58
  • 1
    Because t is on the western side of y.
    – apaderno
    Aug 3 '16 at 11:00
  • Thanks @kiamlaluno and jimmy Ko for helping and explaining!!
    – jas
    Aug 3 '16 at 11:08

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.