function money_widget_settings in Money field 6
Implementation of hook_widget_settings().
File
- ./
money.module, line 129 - This module defines the Money CCK field.
Code
function money_widget_settings($op, $widget) {
switch ($op) {
case 'form':
$form = array();
$options = array(
'code' => t('Currency code'),
'name' => t('Currency name'),
);
$form['currency_select_mode'] = array(
'#type' => 'radios',
'#title' => t('Currency selection mode'),
'#options' => $options,
'#default_value' => isset($widget['currency_select_mode']) && isset($options[$widget['currency_select_mode']]) ? $widget['currency_select_mode'] : 'name',
'#required' => TRUE,
'#description' => t('Choose the format of the label that will be displayed for options of the currency select list.'),
);
$options = money_get_display_modes();
$form['currency_display_mode'] = array(
'#type' => 'select',
'#title' => t('Currency display mode'),
'#options' => $options,
'#default_value' => isset($widget['currency_display_mode']) && isset($options[$widget['currency_display_mode']]) ? $widget['currency_display_mode'] : 'a|+|c',
'#required' => TRUE,
'#description' => t('Choose the format that will be used to display this money field when a node is rendered.'),
);
if (function_exists('currency_api_get_currencies')) {
$options = array(
'field' => t('Field precision'),
'currency' => t('Currency precision'),
);
$form['decimals_display_mode'] = array(
'#type' => 'radios',
'#title' => t('Decimals display mode'),
'#options' => $options,
'#default_value' => isset($widget['decimals_display_mode']) && isset($options[$widget['decimals_display_mode']]) ? $widget['decimals_display_mode'] : 'field',
'#required' => TRUE,
'#description' => t('Choose the method to select the number of decimals used to display the field. The standard precision for each currency is displayed in the <em>Available currencies</em> list.'),
);
$currency_options = array();
foreach (currency_api_get_currencies() as $code => $currency) {
$currency_options[$code] = $currency['name'] . ' [' . $currency['decimals'] . ']';
}
}
else {
$currency_options = currency_api_get_list();
}
$form['currencies'] = array(
'#type' => 'fieldset',
'#title' => t('Available currencies'),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
'#description' => t('Choose the currencies that you want to enable for this field. Do not select any currency to enable them all.'),
);
if (function_exists('currency_api_get_currencies')) {
$form['currencies']['#description'] .= ' ' . t('The number between square brakets indicates the standard precision for each currency.');
}
if (isset($widget['allowed_currencies']) && is_array($widget['allowed_currencies'])) {
// Get filtered array.
$allowed_currencies = array_filter($widget['allowed_currencies']);
// If not empty, create array for the form element values.
if (!empty($allowed_currencies)) {
$allowed_currencies = array_keys($allowed_currencies);
$allowed_currencies = array_combine($allowed_currencies, $allowed_currencies);
}
}
else {
$allowed_currencies = array();
}
$form['currencies']['allowed_currencies'] = array(
'#type' => 'checkboxes',
'#options' => $currency_options,
'#default_value' => $allowed_currencies,
'#checkall' => TRUE,
'#prefix' => '<div class="money-field-currency-checkboxes">',
'#suffix' => '</div>',
);
drupal_add_css(drupal_get_path('module', 'money') . '/money.css');
return $form;
case 'save':
return array(
'currency_select_mode',
'currency_display_mode',
'decimals_display_mode',
'allowed_currencies',
);
}
}