diff --git a/core/includes/form.inc b/core/includes/form.inc index 8546835..b91a882 100644 --- a/core/includes/form.inc +++ b/core/includes/form.inc @@ -3335,7 +3335,7 @@ function form_process_tableselect($element) { * - error: (optional) A custom form error message string to show, if the * machine name contains disallowed characters. * - standalone: (optional) Whether the live preview should stay in it's own - * form element rather than in the prefix of the source element. Defaults + * form element rather than in the suffix of the source element. Defaults * to FALSE. * - #maxlength: (optional) Should be set to the maximum allowed length of the * machine name. Defaults to 64. @@ -3350,7 +3350,7 @@ function form_process_machine_name($element, &$form_state) { '#machine_name' => array(), '#field_prefix' => '', '#field_suffix' => '', - '#prefix' => '', + '#suffix' => '', ); // A form element that only wants to set one #machine_name property (usually // 'source' only) would leave all other properties undefined, if the defaults @@ -3379,7 +3379,7 @@ function form_process_machine_name($element, &$form_state) { } // Retrieve the form element containing the human-readable name from the - // complete form in $form_state. By reference, because we need to append + // complete form in $form_state. By reference, because we may need to append // a #field_suffix that will hold the live preview. $key_exists = NULL; $source = drupal_array_get_nested_value($form_state['complete_form'], $element['#machine_name']['source'], $key_exists); @@ -3390,7 +3390,10 @@ function form_process_machine_name($element, &$form_state) { $suffix_id = $source['#id'] . '-machine-name-suffix'; $element['#machine_name']['suffix'] = '#' . $suffix_id; - if (!$element['#machine_name']['standalone']) { + if ($element['#machine_name']['standalone']) { + $element['#suffix'] .= '  '; + } + else { // Append a field suffix to the source form element, which will contain // the live preview of the machine name. $source += array('#field_suffix' => ''); @@ -3399,9 +3402,6 @@ function form_process_machine_name($element, &$form_state) { $parents = array_merge($element['#machine_name']['source'], array('#field_suffix')); drupal_array_set_nested_value($form_state['complete_form'], $parents, $source['#field_suffix']); } - else { - $element['#prefix'] .= '  '; - } $js_settings = array( 'type' => 'setting', diff --git a/core/misc/machine-name.js b/core/misc/machine-name.js index 59db638..ddd32f7 100644 --- a/core/misc/machine-name.js +++ b/core/misc/machine-name.js @@ -20,7 +20,7 @@ Drupal.behaviors.machineName = { * - replace: A character to replace disallowed characters with; e.g., '_' * or '-'. * - standalone: Whether the preview should stay in it's own element rather - * than the prefix of the source element. + * than the suffix of the source element. * - field_prefix: The #field_prefix of the form element. * - field_suffix: The #field_suffix of the form element. */ @@ -37,17 +37,12 @@ Drupal.behaviors.machineName = { } // Skip processing upon a form validation error on the machine name. if ($target.hasClass('error')) { - $suffix.hide(); return; } // Figure out the maximum length for the machine name. options.maxlength = $target.attr('maxlength'); - // Hide the form item of the machine name form element. - $wrapper.children().hide(); - if (options.standalone) { - $wrapper.find('.description').show(); - } - + // Hide the form item container of the machine name form element. + $wrapper.hide(); // Determine the initial machine name value. Unless the machine name form // element is disabled or not empty, the initial default value is based on // the human-readable form element value. @@ -73,7 +68,7 @@ Drupal.behaviors.machineName = { // If it is editable, append an edit link. var $link = $('' + Drupal.t('Edit') + '') .click(function () { - $wrapper.children().show(); + $wrapper.show(); $target.focus(); $suffix.hide(); $source.unbind('.machineName'); diff --git a/core/modules/field_ui/field_ui.admin.inc b/core/modules/field_ui/field_ui.admin.inc index 20b7fa6..0764956 100644 --- a/core/modules/field_ui/field_ui.admin.inc +++ b/core/modules/field_ui/field_ui.admin.inc @@ -517,10 +517,9 @@ function field_ui_field_overview_form($form, &$form_state, $entity_type, $bundle // This field should stay LTR even for RTL languages. '#field_prefix' => 'field_', '#field_suffix' => '‎', - '#attributes' => array('dir' => 'ltr'), '#size' => 10, + '#description' => t('A unique machine-readable name.'), '#maxlength' => 32 - drupal_strlen('field_'), - '#description' => t('Machine name'), '#prefix' => '
 
', '#machine_name' => array( 'source' => array('fields', $name, 'label'), @@ -528,6 +527,7 @@ function field_ui_field_overview_form($form, &$form_state, $entity_type, $bundle 'standalone' => TRUE, 'label' => '', ), + '#required' => FALSE, ), 'type' => array( '#type' => 'select', diff --git a/core/modules/field_ui/field_ui.css b/core/modules/field_ui/field_ui.css index ae469e2..22ffcc8 100644 --- a/core/modules/field_ui/field_ui.css +++ b/core/modules/field_ui/field_ui.css @@ -29,6 +29,9 @@ table.field-ui-overview tr.region-populated { table.field-ui-overview tr.region-add-new-title { display: none; } +table.field-ui-overview tr.add-new td { + vertical-align: top; +} /* 'Manage display' overview */ #field-display-overview .field-formatter-summary-cell { diff --git a/core/modules/field_ui/field_ui.test b/core/modules/field_ui/field_ui.test index c2e3a98..617284e 100644 --- a/core/modules/field_ui/field_ui.test +++ b/core/modules/field_ui/field_ui.test @@ -202,7 +202,7 @@ class FieldUIManageFieldsTestCase extends FieldUITestCase { // Check all table columns. $table_headers = array( t('Label'), - t('Name'), + t('Machine name'), t('Field'), t('Widget'), t('Operations'), @@ -456,6 +456,25 @@ class FieldUIManageFieldsTestCase extends FieldUITestCase { $this->drupalGet('admin/structure/types/manage/' . $hyphen_type2 . '/fields'); } + + /** + * Tests that a duplicate field name is catched by validation. + */ + function testDuplicateFieldName() { + // field_tags already exists, so we're expecting an error when trying to + // create a new field with the same name. + $edit = array( + 'fields[_add_new_field][field_name]' => 'tags', + 'fields[_add_new_field][label]' => $this->randomName(), + 'fields[_add_new_field][type]' => 'taxonomy_term_reference', + 'fields[_add_new_field][widget_type]' => 'options_select', + ); + $url = 'admin/structure/types/manage/' . $this->hyphen_type . '/fields'; + $this->drupalPost($url, $edit, t('Save')); + + $this->assertText(t('The machine-readable name is already in use. It must be unique.')); + $this->assertUrl($url, array(), 'Stayed on the same page.'); + } } /**