function template_preprocess_pay_cc_form in Pay 7
Same name and namespace in other branches
- 6 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 125 - 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) {
if (empty($card)) {
continue;
}
$variables['element']['cc_type_image'][$card] = array(
'#type' => 'markup',
'#markup' => theme('image', array(
'path' => $path . $card . '.png',
'width' => $label,
)),
);
}
}
// Elements that will be specifically included by the theme template.
$expected = array(
'cc_type_image',
'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();
$printed = FALSE;
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'] = $variables['pay'];
}