diff --git a/core/includes/form.inc b/core/includes/form.inc index 27f450e..118b945 100644 --- a/core/includes/form.inc +++ b/core/includes/form.inc @@ -4304,14 +4304,14 @@ function form_pre_render_tel($element) { * @param array $element * An associative array containing the properties of the element. * Properties used: #title, #value, #description, #min, #max, #placeholder, - * #required, #attributes, #step. + * #required, #attributes, #step, #size. * * @return array * The $element with prepared variables ready for theme_input(). */ function form_pre_render_number($element) { $element['#attributes']['type'] = 'number'; - element_set_attributes($element, array('id', 'name', 'value', 'step', 'min', 'max', 'placeholder')); + element_set_attributes($element, array('id', 'name', 'value', 'step', 'min', 'max', 'placeholder', 'size')); _form_set_attributes($element, array('form-number')); return $element; diff --git a/core/modules/field_ui/field_ui.admin.inc b/core/modules/field_ui/field_ui.admin.inc index 566959b..1abdb3e 100644 --- a/core/modules/field_ui/field_ui.admin.inc +++ b/core/modules/field_ui/field_ui.admin.inc @@ -521,38 +521,39 @@ function field_ui_field_settings_form($form, &$form_state, $instance) { // Build the configurable field values. $cardinality = $field['cardinality']; - $form['field']['container'] = array( - // We can't use the container element because it doesn't support the title - // or description properties. - '#type' => 'item', + $form['field']['cardinality_container'] = array( + // We can't use the container element because it doesn't support the title + // or description properties. + '#type' => 'item', + // Reset #parents to 'field', so the additional container does not appear. + '#parents' => array('field'), '#field_prefix' => '
', '#field_suffix' => '
', - '#title' => t('Maximum number of values users can enter'), + '#title' => t('Allowed number of values'), ); - $form['field']['container']['cardinality'] = array( + $form['field']['cardinality_container']['cardinality'] = array( '#type' => 'select', - '#options' => drupal_map_assoc(range(1, 5)) + array(FIELD_CARDINALITY_UNLIMITED => t('Unlimited')) + array('other' => t('More')), - '#default_value' => ($cardinality < 6) ? $cardinality : 'other', + '#options' => array( + 'number' => t('Limited'), + FIELD_CARDINALITY_UNLIMITED => t('Unlimited'), + ), + '#prefix' => '
', + '#default_value' => ($cardinality == FIELD_CARDINALITY_UNLIMITED) ? FIELD_CARDINALITY_UNLIMITED : 'number', ); - // @todo Convert when http://drupal.org/node/1207060 gets in. - $form['field']['container']['cardinality_other'] = array( + $form['field']['cardinality_container']['cardinality_number'] = array( '#type' => 'number', - '#default_value' => $cardinality > 5 ? $cardinality : 6, + '#default_value' => $cardinality != FIELD_CARDINALITY_UNLIMITED ? $cardinality : 1, '#min' => 1, - '#title' => t('Custom value'), + '#title' => t('Number'), '#title_display' => 'invisible', + '#size' => 5, + '#suffix' => '
', '#states' => array( 'visible' => array( - ':input[name="field[container][cardinality]"]' => array('value' => 'other'), + ':input[name="field[cardinality]"]' => array('value' => 'number'), ), ), ); - if (field_behaviors_widget('multiple values', $instance) == FIELD_BEHAVIOR_DEFAULT) { - $form['field']['container']['#description'] = t('%unlimited will provide an %add-more button so users can add as many values as they like.', array( - '%unlimited' => t('Unlimited'), - '%add-more' => t('Add another item'), - )); - } // Build the non-configurable field values. $form['field']['field_name'] = array('#type' => 'value', '#value' => $field['field_name']); @@ -577,20 +578,6 @@ function field_ui_field_settings_form($form, &$form_state, $instance) { } /** - * Form validation handler for field_ui_field_edit_form(). - * - * @see field_ui_field_settings_form_submit(). - */ -function field_ui_field_settings_form_validate($form, &$form_state) { - // Validate field cardinality. - $cardinality = $form_state['values']['field']['container']['cardinality']; - $cardinality_other = $form_state['values']['field']['container']['cardinality_other']; - if ($cardinality == 'other' && empty($cardinality_other)) { - form_error($form['field']['container']['cardinality_other'], t('Number of values is required.')); - } -} - -/** * Form submission handler for field_ui_field_settings_form(). */ function field_ui_field_settings_form_submit($form, &$form_state) { @@ -598,14 +585,12 @@ function field_ui_field_settings_form_submit($form, &$form_state) { $field_values = $form_values['field']; // Save field cardinality. - $cardinality = $field_values['container']['cardinality']; - $cardinality_other = $field_values['container']['cardinality_other']; - $cardinality_other = $form_state['values']['field']['container']['cardinality_other']; - if ($cardinality == 'other') { - $cardinality = $cardinality_other; + $cardinality = $field_values['cardinality']; + $cardinality_number = $field_values['cardinality_number']; + if ($cardinality == 'number') { + $cardinality = $cardinality_number; } $field_values['cardinality'] = $cardinality; - unset($field_values['container']); // Merge incoming form values into the existing field. $field = field_info_field($field_values['field_name']); diff --git a/core/modules/field_ui/lib/Drupal/field_ui/Tests/ManageFieldsTest.php b/core/modules/field_ui/lib/Drupal/field_ui/Tests/ManageFieldsTest.php index cbc132f..c32f218 100644 --- a/core/modules/field_ui/lib/Drupal/field_ui/Tests/ManageFieldsTest.php +++ b/core/modules/field_ui/lib/Drupal/field_ui/Tests/ManageFieldsTest.php @@ -178,38 +178,27 @@ function addExistingField() { function cardinalitySettings() { $field_edit_path = 'admin/structure/types/manage/article/fields/body/field-settings'; - // Assert the cardinality other field cannot be empty when cardinality is - // set to other. + // Submit a custom number. $edit = array( - 'field[container][cardinality]' => 'other', - 'field[container][cardinality_other]' => '', - ); - $this->drupalPost($field_edit_path, $edit, t('Save field settings')); - $this->assertText('Number of values is required.'); - - // Assert the cardinality field is set to 'Other' when the value is greater - // than 5. - $edit = array( - 'field[container][cardinality]' => 'other', - 'field[container][cardinality_other]' => 16, + 'field[cardinality]' => 'number', + 'field[cardinality_number]' => 6, ); $this->drupalPost($field_edit_path, $edit, t('Save field settings')); $this->assertText('Updated field Body field settings.'); $this->drupalGet($field_edit_path); - $this->assertFieldByXPath("//select[@name='field[container][cardinality]']", 'other'); - $this->assertFieldByXPath("//input[@name='field[container][cardinality_other]']", 16); + $this->assertFieldByXPath("//select[@name='field[cardinality]']", 'number'); + $this->assertFieldByXPath("//input[@name='field[cardinality_number]']", 6); - // Assert the cardinality other field is set back to 6 after changing the - // cardinality to less than 6. + // Set to unlimited. $edit = array( - 'field[container][cardinality]' => 3, - 'field[container][cardinality_other]' => 16, + 'field[cardinality]' => FIELD_CARDINALITY_UNLIMITED, ); $this->drupalPost($field_edit_path, $edit, t('Save field settings')); $this->assertText('Updated field Body field settings.'); $this->drupalGet($field_edit_path); - $this->assertFieldByXPath("//select[@name='field[container][cardinality]']", 3); - $this->assertFieldByXPath("//input[@name='field[container][cardinality_other]']", 6); + $this->drupalGet($field_edit_path); + $this->assertFieldByXPath("//select[@name='field[cardinality]']", FIELD_CARDINALITY_UNLIMITED); + $this->assertFieldByXPath("//input[@name='field[cardinality_number]']", 1); } /** diff --git a/core/modules/text/lib/Drupal/text/Tests/TextTranslationTest.php b/core/modules/text/lib/Drupal/text/Tests/TextTranslationTest.php index 9aff558..3f55435 100644 --- a/core/modules/text/lib/Drupal/text/Tests/TextTranslationTest.php +++ b/core/modules/text/lib/Drupal/text/Tests/TextTranslationTest.php @@ -91,7 +91,7 @@ function testTextField() { */ function testTextFieldFormatted() { // Make node body multiple. - $edit = array('field[container][cardinality]' => -1); + $edit = array('field[cardinality]' => FIELD_CARDINALITY_UNLIMITED); $this->drupalPost('admin/structure/types/manage/article/fields/body/field-settings', $edit, t('Save field settings')); $this->drupalGet('node/add/article'); $this->assertFieldByXPath("//input[@name='body_add_more']", t('Add another item'), 'Body field cardinality set to multiple.');