function commerce_userpoints_currencies_form in Commerce userpoints 7
Form builder function to add a new userpoints category.
1 string reference to 'commerce_userpoints_currencies_form'
- commerce_userpoints_menu in ./
commerce_userpoints.module - Implements hook_menu().
File
- ./
commerce_userpoints.admin.inc, line 39 - Administration page callbacks for the commerce_userpoints module.
Code
function commerce_userpoints_currencies_form($form, &$form_state, $currency = array()) {
$currency += array(
'code' => '',
'name' => '',
'tid' => NULL,
'symbol' => '',
'currencies' => array(),
);
$form_state['commerce_userpoints_currency'] = $currency;
$form['name'] = array(
'#title' => t('Currency name'),
'#type' => 'textfield',
'#size' => 10,
'#required' => TRUE,
'#default_value' => $currency['name'],
);
// Only show categories which aren't yet used for a currency.
$remaining_categories = userpoints_get_categories();
foreach (commerce_userpoints_currencies() as $existing_currency) {
if (empty($currency['code']) || $existing_currency['code'] != $currency['code']) {
unset($remaining_categories[$existing_currency['tid']]);
}
}
if (empty($remaining_categories)) {
drupal_set_message(t('You have no !points categories which are not used already as a currency.', userpoints_translation()), 'error');
}
$form['tid'] = array(
'#title' => t('!Points category', userpoints_translation()),
'#type' => 'select',
'#options' => $remaining_categories,
'#required' => TRUE,
'#default_value' => $currency['tid'],
);
$form['code'] = array(
'#title' => t('Currency code'),
'#type' => 'textfield',
'#size' => 5,
'#required' => TRUE,
'#default_value' => $currency['code'],
'#disabled' => !empty($currency['code']),
);
$form['symbol'] = array(
'#title' => t('Currency symbol'),
'#type' => 'textfield',
'#size' => 5,
'#required' => TRUE,
'#default_value' => $currency['symbol'],
);
$form['currencies']['#tree'] = TRUE;
$rows = array();
$form['conversion_rate'] = array(
'#type' => 'textfield',
'#title' => t('Exchange rate'),
'#default_value' => isset($currency['conversion_rate']) ? $currency['conversion_rate'] : 0.01,
'#size' => 5,
'#required' => TRUE,
);
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Save'),
);
return $form;
}