function money_field_widget_settings_form in Money field 7
Implements hook_field_widget_settings_form().
File
- ./
money.module, line 406 - This module defines the Money field.
Code
function money_field_widget_settings_form($field, $instance) {
$widget = $instance['widget'];
$settings = $widget['settings'];
$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' => $settings['currency_select_mode'],
'#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' => $settings['currency_display_mode'],
'#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' => $settings['decimals_display_mode'],
'#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_options();
}
$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($settings['currencies']['allowed_currencies']) && is_array($settings['currencies']['allowed_currencies'])) {
// Get filtered array.
$allowed_currencies = array_filter($settings['currencies']['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>',
'#attached' => array(
'css' => array(
drupal_get_path('module', 'money') . '/money.css',
),
),
);
return $form;
}