Return value from view op of hook_order_pane() form builder

Posts: 67
Joined: 02/20/2008

I'm working on adding some custom data to the order process for a site. I've been going through the Developer's Guide and the Lead Tracker module, since it is offered as an example, and I keep seeing discrepancies between the documentation and the sample module (for instance, see here). A case of this is regarding the view op in the form builder function for hook_order_pane. According to the documentation, it is "expected to return a pane object with the attribute fields set to be an array of form elements." However, in the module, I see no field attribute at all:

function uc_lead_order_pane() {
  $panes[] = array(
    'id' => 'lead',
    'callback' => 'uc_order_pane_lead',
    'title' => t('Sales Tracking'),
    'desc' => t('See how the customer found out about your site.'),
    'class' => 'abs-left',
    'weight' => 7,
    'show' => array('view'),
  );

  return $panes;
}

function uc_order_pane_lead($op, $arg1) {
  switch ($op) {
    case 'view':
      if (empty($arg1->lead['source'])) {
        $lead = t('None specified');
      }
      elseif ($arg1->lead['source'] == t('Other source')) {
        $lead = $arg1->lead['other'];
      }
      else {
        $lead = $arg1->lead['source'];
      }
      return t('Sales lead: @lead', array('@lead' => $lead));
  }
}

Another question is, how do I format the return from the form builder with multiple fields (I have 9)? I've tried a few different configurations, but I can't seem to get it right.

Thanks.

Posts: 5617
Joined: 08/07/2007
AdministratorHead Code Monkey - I eat bugs.

It sounds like the docs might have switched up the view and edit $op. I'm looking at uc_order_order_pane.inc for core examples and see the similar return of a string of HTML for the core panes' view $op. I'm not sure where the pane object language is coming from. Puzzled

Posts: 67
Joined: 02/20/2008

OK, thanks. But since the array listed in the lead module works:

return t('Sales lead: @lead', array('@lead' => $lead));

how would I do that for multiple items?

Posts: 5617
Joined: 08/07/2007
AdministratorHead Code Monkey - I eat bugs.

Notice that that's actually a standard usage of the t() function in Drupal core. The array there just defines replacement values for the tokens in the first string argument.

Posts: 67
Joined: 02/20/2008

Yeah, I got it figured out. I just defined an $output variable and appended a line using t() and an array for each variable, and returned that variable.

Thanks.