You are here

function template_preprocess_pay_cc_form in Pay 6

Same name and namespace in other branches
  1. 7 theme/pay.theme.inc \template_preprocess_pay_cc_form()

A preprocess function for theme('pay_cc_form').

The $variables array initially contains the following arguments:

File

theme/pay.theme.inc, line 119
Theme hooks and callbacks for the Payment API.

Code

function template_preprocess_pay_cc_form(&$variables) {
  static $first_time = TRUE;
  $variables['pay'] = array();
  if ($variables['element']['cc_type']) {
    $path = drupal_get_path('module', 'pay') . '/theme/images/';
    foreach ($variables['element']['cc_type']['#options'] as $card => $label) {
      $variables['element']['cc_type'][$card]['#title'] = theme('image', $path . $card . '.png', $label);
    }
  }

  // Elements that will be specifically included by the theme template.
  $expected = array(
    'cc_type',
    'first_name',
    'last_name',
    'mail',
    'billto',
    'cc_number',
    'cc_ccv2',
    'cc_exp_month',
    'cc_exp_year',
  );
  $variables['pay']['prefix'] = $variables['pay']['suffix'] = array();
  foreach (element_children($variables['element']) as $item) {
    if (in_array($item, $expected)) {
      $variables['pay'][$item] = drupal_render($variables['element'][$item]);
      $printed = TRUE;
    }
    else {

      // Add unrecognized items to either the 'prefix' or 'suffix' array.
      // If we've seen any 'expected' elements, use suffix: else use prefix.
      $key = $printed ? 'suffix' : 'prefix';
      $variables['pay'][$key][] = drupal_render($variables['element'][$item]);
    }
  }
  if ($first_time) {
    $variables['setup'] = $first_time;
    $first_time = FALSE;
  }
  else {
    $variables['setup'] = FALSE;
  }
  $variables['pay_form'] = join('', $variables['pay']);
}