Issue #1002734 by pillarsdotnet, yched: Fixed Multiple 'Undefined index' notices in modules/field/modules/number/number.module.
parent
a545c30809
commit
0710e3cd5e
|
@ -181,11 +181,18 @@ function number_field_is_empty($item, $field) {
|
|||
*/
|
||||
function number_field_formatter_info() {
|
||||
return array(
|
||||
// The 'Default' formatter is different for integer fields on the one hand,
|
||||
// and for decimal and float fields on the other hand, in order to be able
|
||||
// to use different default values for the settings.
|
||||
'number_integer' => array(
|
||||
'label' => t('Default'),
|
||||
'field types' => array('number_integer'),
|
||||
'settings' => array(
|
||||
'thousand_separator' => ' ',
|
||||
// The 'decimal_separator' and 'scale' settings are not configurable
|
||||
// through the UI, and will therefore keep their default values. They
|
||||
// are only present so that the 'number_integer' and 'number_decimal'
|
||||
// formatters can use the same code.
|
||||
'decimal_separator' => '.',
|
||||
'scale' => 0,
|
||||
'prefix_suffix' => TRUE,
|
||||
|
@ -215,41 +222,43 @@ function number_field_formatter_settings_form($field, $instance, $view_mode, $fo
|
|||
$display = $instance['display'][$view_mode];
|
||||
$settings = $display['settings'];
|
||||
|
||||
$options = array(
|
||||
'' => t('<none>'),
|
||||
'.' => t('Decimal point'),
|
||||
',' => t('Comma'),
|
||||
' ' => t('Space'),
|
||||
);
|
||||
$element['thousand_separator'] = array(
|
||||
'#type' => 'select',
|
||||
'#title' => t('Thousand marker'),
|
||||
'#options' => $options,
|
||||
'#default_value' => $settings['thousand_separator'],
|
||||
);
|
||||
|
||||
if ($display['type'] == 'number_decimal' || $display['type'] == 'number_float') {
|
||||
$element['decimal_separator'] = array(
|
||||
'#type' => 'select',
|
||||
'#title' => t('Decimal marker'),
|
||||
'#options' => array('.' => t('Decimal point'), ',' => t('Comma')),
|
||||
'#default_value' => $settings['decimal_separator'],
|
||||
if ($display['type'] == 'number_decimal' || $display['type'] == 'number_integer') {
|
||||
$options = array(
|
||||
'' => t('<none>'),
|
||||
'.' => t('Decimal point'),
|
||||
',' => t('Comma'),
|
||||
' ' => t('Space'),
|
||||
);
|
||||
$element['scale'] = array(
|
||||
$element['thousand_separator'] = array(
|
||||
'#type' => 'select',
|
||||
'#title' => t('Scale'),
|
||||
'#options' => drupal_map_assoc(range(0, 10)),
|
||||
'#default_value' => $settings['scale'],
|
||||
'#description' => t('The number of digits to the right of the decimal.'),
|
||||
'#title' => t('Thousand marker'),
|
||||
'#options' => $options,
|
||||
'#default_value' => $settings['thousand_separator'],
|
||||
);
|
||||
|
||||
if ($display['type'] == 'number_decimal') {
|
||||
$element['decimal_separator'] = array(
|
||||
'#type' => 'select',
|
||||
'#title' => t('Decimal marker'),
|
||||
'#options' => array('.' => t('Decimal point'), ',' => t('Comma')),
|
||||
'#default_value' => $settings['decimal_separator'],
|
||||
);
|
||||
$element['scale'] = array(
|
||||
'#type' => 'select',
|
||||
'#title' => t('Scale'),
|
||||
'#options' => drupal_map_assoc(range(0, 10)),
|
||||
'#default_value' => $settings['scale'],
|
||||
'#description' => t('The number of digits to the right of the decimal.'),
|
||||
);
|
||||
}
|
||||
|
||||
$element['prefix_suffix'] = array(
|
||||
'#type' => 'checkbox',
|
||||
'#title' => t('Display prefix and suffix.'),
|
||||
'#default_value' => $settings['prefix_suffix'],
|
||||
);
|
||||
}
|
||||
|
||||
$element['prefix_suffix'] = array(
|
||||
'#type' => 'checkbox',
|
||||
'#title' => t('Display prefix and suffix.'),
|
||||
'#default_value' => $settings['prefix_suffix'],
|
||||
);
|
||||
|
||||
return $element;
|
||||
}
|
||||
|
||||
|
@ -261,9 +270,11 @@ function number_field_formatter_settings_summary($field, $instance, $view_mode)
|
|||
$settings = $display['settings'];
|
||||
|
||||
$summary = array();
|
||||
$summary[] = number_format(1234.1234567890, $settings['scale'], $settings['decimal_separator'], $settings['thousand_separator']);
|
||||
if ($settings['prefix_suffix']) {
|
||||
$summary[] = t('Display with prefix and suffix.');
|
||||
if ($display['type'] == 'number_decimal' || $display['type'] == 'number_integer') {
|
||||
$summary[] = number_format(1234.1234567890, $settings['scale'], $settings['decimal_separator'], $settings['thousand_separator']);
|
||||
if ($settings['prefix_suffix']) {
|
||||
$summary[] = t('Display with prefix and suffix.');
|
||||
}
|
||||
}
|
||||
|
||||
return implode('<br />', $summary);
|
||||
|
|
|
@ -23,7 +23,7 @@ class NumberFieldTestCase extends DrupalWebTestCase {
|
|||
|
||||
function setUp() {
|
||||
parent::setUp('field_test');
|
||||
$this->web_user = $this->drupalCreateUser(array('access field_test content', 'administer field_test content'));
|
||||
$this->web_user = $this->drupalCreateUser(array('access field_test content', 'administer field_test content', 'administer content types'));
|
||||
$this->drupalLogin($this->web_user);
|
||||
}
|
||||
|
||||
|
@ -93,4 +93,41 @@ class NumberFieldTestCase extends DrupalWebTestCase {
|
|||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Test number_integer field.
|
||||
*/
|
||||
function testNumberIntegerField() {
|
||||
// Display the "Add content type" form.
|
||||
$this->drupalGet('admin/structure/types/add');
|
||||
|
||||
// Add a content type.
|
||||
$name = $this->randomName();
|
||||
$type = drupal_strtolower($name);
|
||||
$edit = array('name' => $name, 'type' => $type);
|
||||
$this->drupalPost(NULL, $edit, t('Save and add fields'));
|
||||
|
||||
// Add an integer field to the newly-created type.
|
||||
$label = $this->randomName();
|
||||
$field_name = drupal_strtolower($label);
|
||||
$edit = array(
|
||||
'fields[_add_new_field][label]'=> $label,
|
||||
'fields[_add_new_field][field_name]' => $field_name,
|
||||
'fields[_add_new_field][type]' => 'number_integer',
|
||||
'fields[_add_new_field][widget_type]' => 'number',
|
||||
);
|
||||
$this->drupalPost(NULL, $edit, t('Save'));
|
||||
|
||||
// Set the formatter to "number_integer" and to "unformatted", and just
|
||||
// check that the settings summary does not generate warnings.
|
||||
$this->drupalGet("admin/structure/types/manage/$type/display");
|
||||
$edit = array(
|
||||
"fields[field_$field_name][type]" => 'number_integer',
|
||||
);
|
||||
$this->drupalPost(NULL, $edit, t('Save'));
|
||||
$edit = array(
|
||||
"fields[field_$field_name][type]" => 'number_unformatted',
|
||||
);
|
||||
$this->drupalPost(NULL, $edit, t('Save'));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue