Index: includes/ajax.inc
===================================================================
RCS file: /cvs/drupal/drupal/includes/ajax.inc,v
retrieving revision 1.31
diff -u -p -r1.31 ajax.inc
--- includes/ajax.inc	30 Apr 2010 08:07:54 -0000	1.31
+++ includes/ajax.inc	6 Sep 2010 17:02:31 -0000
@@ -413,10 +413,10 @@ function ajax_footer() {
  *   None. Additional code is added to the header of the page using
  *   drupal_add_js().
  */
-function ajax_process_form($element, &$form_state) {
+function ajax_process_form(&$element, &$form_state) {
   // Nothing to do if there is neither a callback nor a path.
   if (!(isset($element['#ajax']['callback']) || isset($element['#ajax']['path']))) {
-    return $element;
+    return;
   }
 
   // Add a reasonable default event handler if none was specified.
@@ -447,7 +447,7 @@ function ajax_process_form($element, &$f
         break;
 
       default:
-        return $element;
+        return;
     }
   }
 
@@ -526,7 +526,6 @@ function ajax_process_form($element, &$f
 
     $form_state['cache'] = TRUE;
   }
-  return $element;
 }
 
 /**
Index: includes/form.inc
===================================================================
RCS file: /cvs/drupal/drupal/includes/form.inc,v
retrieving revision 1.487
diff -u -p -r1.487 form.inc
--- includes/form.inc	30 Aug 2010 17:07:49 -0000	1.487
+++ includes/form.inc	6 Sep 2010 18:06:27 -0000
@@ -1078,7 +1078,11 @@ function _form_validate(&$elements, &$fo
     if (isset($elements['#needs_validation'])) {
       // Verify that the value is not longer than #maxlength.
       if (isset($elements['#maxlength']) && drupal_strlen($elements['#value']) > $elements['#maxlength']) {
-        form_error($elements, $t('!name cannot be longer than %max characters but is currently %length characters long.', array('!name' => empty($elements['#title']) ? $elements['#parents'][0] : $elements['#title'], '%max' => $elements['#maxlength'], '%length' => drupal_strlen($elements['#value']))));
+        form_error($elements, $t('!name cannot be longer than %max characters but is currently %length characters long.', array(
+          '!name' => empty($elements['#title']) ? $elements['#parents'][0] : $elements['#title'],
+          '%max' => $elements['#maxlength'],
+          '%length' => drupal_strlen($elements['#value']),
+        )));
       }
 
       if (isset($elements['#options']) && isset($elements['#value'])) {
@@ -1480,7 +1484,7 @@ function form_error(&$element, $message 
  *   was clicked when the form was submitted, as well as the sanitized
  *   $_POST data.
  */
-function form_builder($form_id, $element, &$form_state) {
+function form_builder($form_id, &$element, &$form_state) {
   // Initialize as unprocessed.
   $element['#processed'] = FALSE;
 
@@ -1507,8 +1511,11 @@ function form_builder($form_id, $element
       $element['#action'] = str_replace('http://', 'https://', $base_root) . $element['#action'];
     }
 
-    // Store a complete copy of the form in form_state prior to building the form.
-    $form_state['complete form'] = $element;
+    // Store a reference to the complete form in $form_state prior to building
+    // the form. This allows advanced #process and #after_build callbacks to
+    // perform changes elsewhere in the form.
+    $form_state['complete form'] = &$element;
+
     // Set a flag if we have a correct form submission. This is always TRUE for
     // programmed forms coming from drupal_form_submit(), or if the form_id coming
     // from the POST data is set and matches the current form_id.
@@ -1531,7 +1538,12 @@ function form_builder($form_id, $element
   // checkboxes and files.
   if (isset($element['#process']) && !$element['#processed']) {
     foreach ($element['#process'] as $process) {
-      $element = $process($element, $form_state, $form_state['complete form']);
+      // Processing elements by reference is preferred to returning a new copy.
+      // @todo D8: Always pass by reference only.
+      $result = $process($element, $form_state, $form_state['complete form']);
+      if (isset($result)) {
+        $element = &$result;
+      }
     }
     $element['#processed'] = TRUE;
   }
@@ -1595,7 +1607,12 @@ function form_builder($form_id, $element
   // after normal input parsing has been completed.
   if (isset($element['#after_build']) && !isset($element['#after_build_done'])) {
     foreach ($element['#after_build'] as $function) {
-      $element = $function($element, $form_state);
+      // Processing elements by reference is preferred to returning a new copy.
+      // @todo D8: Always pass by reference only.
+      $result = $function($element, $form_state);
+      if (isset($result)) {
+        $element = &$result;
+      }
     }
     $element['#after_build_done'] = TRUE;
   }
@@ -1654,9 +1671,6 @@ function form_builder($form_id, $element
       // @todo Legacy support. Remove in Drupal 8.
       $form_state['clicked_button'] = $form_state['triggering_element'];
     }
-
-    // Update the copy of the complete form for usage in validation handlers.
-    $form_state['complete form'] = $element;
   }
   return $element;
 }
@@ -2400,7 +2414,7 @@ function theme_radios($variables) {
 /**
  * Expand a password_confirm field into two text boxes.
  */
-function form_process_password_confirm($element) {
+function form_process_password_confirm(&$element) {
   $element['pass1'] =  array(
     '#type' => 'password',
     '#title' => t('Password'),
@@ -2421,8 +2435,6 @@ function form_process_password_confirm($
   if (isset($element['#size'])) {
     $element['pass1']['#size'] = $element['pass2']['#size'] = $element['#size'];
   }
-
-  return $element;
 }
 
 /**
@@ -2469,7 +2481,7 @@ function theme_date($variables) {
 /**
  * Roll out a single date element.
  */
-function form_process_date($element) {
+function form_process_date(&$element) {
   // Default to current date
   if (empty($element['#value'])) {
     $element['#value'] = array('day' => format_date(REQUEST_TIME, 'custom', 'j'),
@@ -2509,8 +2521,6 @@ function form_process_date($element) {
       '#options' => $options,
     );
   }
-
-  return $element;
 }
 
 /**
@@ -2559,7 +2569,7 @@ function weight_value(&$form) {
  * Roll out a single radios element to a list of radios,
  * using the options array as index.
  */
-function form_process_radios($element) {
+function form_process_radios(&$element) {
   if (count($element['#options']) > 0) {
     foreach ($element['#options'] as $key => $choice) {
       if (!isset($element[$key])) {
@@ -2579,7 +2589,6 @@ function form_process_radios($element) {
       }
     }
   }
-  return $element;
 }
 
 /**
@@ -2653,7 +2662,7 @@ function form_pre_render_conditional_for
   return $element;
 }
 
-function form_process_checkboxes($element) {
+function form_process_checkboxes(&$element) {
   $value = is_array($element['#value']) ? $element['#value'] : array();
   $element['#tree'] = TRUE;
   if (count($element['#options']) > 0) {
@@ -2674,7 +2683,6 @@ function form_process_checkboxes($elemen
       }
     }
   }
-  return $element;
 }
 
 /**
@@ -2689,9 +2697,8 @@ function form_process_checkboxes($elemen
  * @return
  *   The processed element.
  */
-function form_process_actions($element, &$form_state) {
+function form_process_actions(&$element, &$form_state) {
   $element['#attributes']['class'][] = 'form-actions';
-  return $element;
 }
 
 /**
@@ -2705,12 +2712,11 @@ function form_process_actions($element, 
  * @return
  *   The processed element.
  */
-function form_process_container($element, &$form_state) {
+function form_process_container(&$element, &$form_state) {
   // Generate the ID of the element if it's not explicitly given.
   if (!isset($element['#id'])) {
     $element['#id'] = drupal_html_id(implode('-', $element['#parents']) . '-wrapper');
   }
-  return $element;
 }
 
 /**
@@ -2809,8 +2815,7 @@ function theme_tableselect($variables) {
  * @return
  *   The processed element.
  */
-function form_process_tableselect($element) {
-
+function form_process_tableselect(&$element) {
   if ($element['#multiple']) {
     $value = is_array($element['#value']) ? $element['#value'] : array();
   }
@@ -2864,7 +2869,105 @@ function form_process_tableselect($eleme
   else {
     $element['#value'] = array();
   }
-  return $element;
+}
+
+/**
+ * Processes a machine-readable name form element.
+ *
+ * @param $element
+ *   The form element to process. Properties used:
+ *   - #machine_name_exists: A function name to invoke for checking whether a
+ *     submitted machine name value already exists. The submitted value is
+ *     passed as argument. In most cases, an existing API or menu argument
+ *     loader function can be re-used. The callback is only invoked, if the
+ *     submitted value differs from the element's #default_value.
+ *   - #disabled: (optional) Should be TRUE if a machine name cannot be changed.
+ *   - #machine_name_source: (optional) The #array_parents of the form element
+ *     containing the human-readable name to use as source for the
+ *     machine-readable name. Defaults to array('name').
+ *   - #machine_name_label: (optional) A text to display as label for the
+ *     machine-readable name value (as suffix after the human-readable name
+ *     form element). Defaults to 'Machine name'.
+ *   - #machine_name_pattern: (optional) A regular expression without delimiters
+ *     that denotes valid characters for the machine name. Defaults to
+ *     '[^a-z0-9_]+'.
+ *   - #machine_name_replace: (optional) A replacement string character to use
+ *     for invalid characters in the machine name. Defaults to '_'. When using
+ *     a different character, #machine_name_pattern needs to be changed
+ *     accordingly.
+ */
+function form_process_machine_name(&$element, &$form_state) {
+  // Apply default form element properties.
+  $element += array(
+    '#title' => t('Machine-readable name'),
+    '#description' => t('A unique machine-readable name. Can only contain lowercase letters, numbers, and underscores.'),
+    '#machine_name_source' => array('name'),
+    '#machine_name_label' => t('Machine name'),
+    '#machine_name_pattern' => '[^a-z0-9_]+',
+    '#machine_name_replace' => '_',
+  );
+
+  // #machine_name_source defaults to array('name'), but may be overidden.
+  if (empty($element['#machine_name_source'])) {
+    return;
+  }
+
+  // Retrieve the form element containing the human-readable name from the
+  // complete form in $form_state. By reference, because we need to append
+  // a #field_suffix that will hold the live preview.
+  list($source, $exists) = drupal_array_get_nested_value($form_state['complete form'], $element['#machine_name_source']);
+
+  $suffix_id = $source['#id'] . '-machine-name-suffix';
+  $suffix = ' <small id="' . $suffix_id . '">&nbsp;</small>';
+  if (!isset($source['#field_suffix'])) {
+    $source['#field_suffix'] = '';
+  }
+  $source['#field_suffix'] .= $suffix;
+
+  $parents = array_merge($element['#machine_name_source'], array('#field_suffix'));
+  drupal_array_set_nested_value($form_state['complete form'], $parents, $suffix);
+
+  $js_settings = array(
+    'type' => 'setting',
+    'data' => array(
+      'machineName' => array(
+        '#' . $source['#id'] => array(
+          'text' => $element['#machine_name_label'],
+          'target' => '#' . $element['#id'],
+          'pattern' => $element['#machine_name_pattern'],
+          'replace' => $element['#machine_name_replace'],
+          'suffix' => '#' . $suffix_id,
+        ),
+      ),
+    ),
+  );
+
+  $element['#attached']['js'][] = 'misc/machine_name.js';
+  $element['#attached']['js'][] = $js_settings;
+}
+
+/**
+ * Form element validation handler for #type 'machine_name'.
+ */
+function form_validate_machine_name(&$element, &$form_state) {
+  // Restrict machine names to appropriate characters.
+  if (preg_match('@' . $element['#machine_name_pattern'] . '@', $element['#value'])) {
+    if (!isset($element['#machine_name_error'])) {
+      form_error($element, t('The machine-readable name must contain only lowercase letters, numbers, and underscores.'));
+    }
+    else {
+      form_error($element, $element['#machine_name_error']);
+    }
+  }
+  // #maxlength is validated by _form_validate() already.
+
+  // Prevent duplicate machine names.
+  if ($element['#default_value'] !== $element['#value']) {
+    $function = $element['#machine_name_exists'];
+    if ($function($element['#value'])) {
+      form_error($element, t('This machine-readable name is already in use. It must be unique.'));
+    }
+  }
 }
 
 /**
@@ -2914,8 +3017,6 @@ function form_process_fieldset(&$element
     }
   }
   $element['#attributes']['id'] = $element['#id'];
-
-  return $element;
 }
 
 /**
@@ -2981,7 +3082,7 @@ function form_pre_render_fieldset($eleme
  * @return
  *   The processed element.
  */
-function form_process_vertical_tabs($element, &$form_state) {
+function form_process_vertical_tabs(&$element, &$form_state) {
   // Inject a new fieldset as child, so that form_process_fieldset() processes
   // this fieldset like any other fieldset.
   $element['group'] = array(
@@ -3003,8 +3104,6 @@ function form_process_vertical_tabs($ele
     '#default_value' => $element['#default_tab'],
     '#attributes' => array('class' => array('vertical-tabs-active-tab')),
   );
-
-  return $element;
 }
 
 /**
@@ -3253,7 +3352,7 @@ function theme_password($variables) {
 /**
  * Expand weight elements into selects.
  */
-function form_process_weight($element) {
+function form_process_weight(&$element) {
   for ($n = (-1 * $element['#delta']); $n <= $element['#delta']; $n++) {
     $weights[$n] = $n;
   }
@@ -3261,7 +3360,6 @@ function form_process_weight($element) {
   $element['#type'] = 'select';
   $element['#is_weight'] = TRUE;
   $element += element_info('select');
-  return $element;
 }
 
 /**
Index: misc/machine_name.js
===================================================================
RCS file: misc/machine_name.js
diff -N misc/machine_name.js
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ misc/machine_name.js	5 Sep 2010 18:32:58 -0000
@@ -0,0 +1,104 @@
+// $Id$
+(function ($) {
+
+/**
+ * Attach the auto machine readable name behavior.
+ *
+ * Settings are expected to be an object of elements to process, where the key
+ * is the HTML ID of the source element in the form and the value is an object
+ * defining the following properties:
+ * - target: The HTML ID of the machine name form element.
+ * - suffix: The HTML ID of the machine name preview form element suffix.
+ * - text: The label to display for the machine name preview.
+ * - pattern: A regular expression (without modifiers) matching disallowed
+ *   characters in the machine readable name; e.g., '[^a-z0-9]+'.
+ * - replace: A replacement string to replace disallowed characters; e.g.,
+ *   '-' or '_'.
+ */
+Drupal.behaviors.machineName = {
+  attach: function (context, settings) {
+    var self = this;
+    $.each(settings.machineName, function (source_id, options) {
+      var $source = $(source_id, context).addClass('machine-name-source');
+      var $target = $(options.target, context).addClass('machine-name-target');
+      var $suffix = $(options.suffix, context);
+      var $wrapper = $target.parents('.form-item:first');
+      // All elements are required to exist.
+      if (!$source.length || !$target.length || !$suffix.length || !$wrapper.length) {
+        return;
+      }
+      // Skip processing upon a form validation error on the machine name.
+      if ($target.hasClass('error')) {
+        return;
+      }
+      // Hide wrapper element.
+      $wrapper.hide();
+      // Append the machine name to the source field.
+      if ($target.is(':disabled')) {
+        var machine = $target.val();
+      }
+      else {
+        var machine = self.transliterate($source.val(), options);
+      }
+      var $preview = $('<span class="machine-name-value">' + machine + '</span>');
+      $suffix.empty()
+        .append(' ').append('<span class="machine-name-label">' + options.text + ':</span>')
+        .append(' ').append($preview);
+
+      // Append a link to edit it, if it is editable. But only if
+      // - the machine name is empty.
+      // - the human-readable name and transliterated machine name are equal.
+      if (!$target.is(':disabled') && ($target.val() == '' || $target.val() == machine)) {
+        var $link = $('<span class="admin-link"><a href="#">' + Drupal.t('Edit') + '</a></span>')
+          .click(function () {
+            $wrapper.show();
+            $target.focus();
+            $suffix.hide();
+            $source.unbind('keyup.machineName');
+            return false;
+          });
+        $suffix.append(' ').append($link);
+
+        // Process machine name in realtime when typed characters change.
+        $source.bind('keyup.machineName', function () {
+          machine = self.transliterate($(this).val(), options);
+          // Set machine readable name to the user entered value.
+          if (machine != '_' && machine != '') {
+            $target.val(machine);
+            $preview.text(machine);
+            $suffix.show();
+          }
+          else {
+            $suffix.hide();
+            $target.val(machine);
+            $preview.empty();
+          }
+        });
+        // Call keyup event on source element.
+        $source.keyup();
+      }
+    });
+  },
+
+  /**
+   * Transliterate a human-readable name to a machine name.
+   *
+   * @param source
+   *   The to be transliterated source string.
+   * @param settings
+   *   The machine name settings for the corresponding field, containing:
+   *   - pattern: A regular expression (without modifiers) matching
+   *     disallowed characters in the machine readable name; e.g., '[^a-z0-9]+'.
+   *   - replace: A replacement string to replace disallowed characters;
+   *     e.g., '-' or '_'.
+   *
+   * @return
+   *   The transliterated source string.
+   */
+  transliterate: function (source, settings) {
+    var rx = new RegExp(settings.pattern, 'g');
+    return source.toLowerCase().replace(rx, settings.replace);
+  }
+};
+
+})(jQuery);
Index: modules/field/field.form.inc
===================================================================
RCS file: /cvs/drupal/drupal/modules/field/field.form.inc,v
retrieving revision 1.50
diff -u -p -r1.50 field.form.inc
--- modules/field/field.form.inc	17 Jun 2010 13:44:45 -0000	1.50
+++ modules/field/field.form.inc	6 Sep 2010 18:07:21 -0000
@@ -305,12 +305,10 @@ function theme_field_multiple_value_form
  * @see field_default_form_errors()
  * @see field_add_more_js()
  */
-function field_form_element_after_build($element, &$form_state) {
+function field_form_element_after_build(&$element, &$form_state) {
   $field_name = $element['#field_name'];
   $langcode = $element['#language'];
   $form_state['field'][$field_name][$langcode]['array_parents'] = $element['#array_parents'];
-
-  return $element;
 }
 
 /**
Index: modules/file/file.field.inc
===================================================================
RCS file: /cvs/drupal/drupal/modules/file/file.field.inc,v
retrieving revision 1.33
diff -u -p -r1.33 file.field.inc
--- modules/file/file.field.inc	4 Sep 2010 15:40:51 -0000	1.33
+++ modules/file/file.field.inc	6 Sep 2010 18:01:06 -0000
@@ -608,7 +608,7 @@ function file_field_widget_value($elemen
  *
  * Expands the file_generic type to include the description and display fields.
  */
-function file_field_widget_process($element, &$form_state, $form) {
+function file_field_widget_process(&$element, &$form_state, $form) {
   $item = $element['#value'];
   $item['fid'] = $element['fid']['#value'];
 
@@ -659,8 +659,6 @@ function file_field_widget_process($elem
     }
     unset($element['#prefix'], $element['#suffix']);
   }
-
-  return $element;
 }
 
 /**
@@ -669,7 +667,7 @@ function file_field_widget_process($elem
  * Adds the weight field to each row so it can be ordered and adds a new AJAX
  * wrapper around the entire group so it can be replaced all at once.
  */
-function file_field_widget_process_multiple($element, &$form_state, $form) {
+function file_field_widget_process_multiple(&$element, &$form_state, $form) {
   $element_children = element_children($element, TRUE);
   $count = count($element_children);
 
@@ -695,8 +693,6 @@ function file_field_widget_process_multi
   // Add a new wrapper around all the elements for AJAX replacement.
   $element['#prefix'] = '<div id="' . $element['#id'] . '-ajax-wrapper">';
   $element['#suffix'] = '</div>';
-
-  return $element;
 }
 
 /**
Index: modules/file/file.module
===================================================================
RCS file: /cvs/drupal/drupal/modules/file/file.module,v
retrieving revision 1.37
diff -u -p -r1.37 file.module
--- modules/file/file.module	27 Aug 2010 11:54:32 -0000	1.37
+++ modules/file/file.module	6 Sep 2010 18:01:34 -0000
@@ -363,7 +363,7 @@ function file_file_delete($file) {
  * Expands the file type to include Upload and Remove buttons, as well as
  * support for a default value.
  */
-function file_managed_file_process($element, &$form_state, $form) {
+function file_managed_file_process(&$element, &$form_state, $form) {
   $fid = isset($element['#value']['fid']) ? $element['#value']['fid'] : 0;
 
   // Set some default element properties.
@@ -461,8 +461,6 @@ function file_managed_file_process($elem
   // Prefix and suffix used for AJAX replacement.
   $element['#prefix'] = '<div id="' . $element['#id'] . '-ajax-wrapper">';
   $element['#suffix'] = '</div>';
-
-  return $element;
 }
 
 /**
Index: modules/filter/filter.module
===================================================================
RCS file: /cvs/drupal/drupal/modules/filter/filter.module,v
retrieving revision 1.342
diff -u -p -r1.342 filter.module
--- modules/filter/filter.module	4 Sep 2010 17:55:43 -0000	1.342
+++ modules/filter/filter.module	6 Sep 2010 18:02:49 -0000
@@ -758,7 +758,7 @@ function check_markup($text, $format_id 
  * @return
  *   The expanded element.
  */
-function filter_process_format($element) {
+function filter_process_format(&$element) {
   global $user;
 
   // Ensure that children appear as subkeys of this element.
@@ -873,8 +873,6 @@ function filter_process_format($element)
       }
     }
   }
-
-  return $element;
 }
 
 /**
Index: modules/image/image.field.inc
===================================================================
RCS file: /cvs/drupal/drupal/modules/image/image.field.inc,v
retrieving revision 1.26
diff -u -p -r1.26 image.field.inc
--- modules/image/image.field.inc	4 Sep 2010 15:40:51 -0000	1.26
+++ modules/image/image.field.inc	6 Sep 2010 18:03:05 -0000
@@ -322,7 +322,7 @@ function image_field_widget_form(&$form,
  *
  * Expands the image_image type to include the alt and title fields.
  */
-function image_field_widget_process($element, &$form_state, $form) {
+function image_field_widget_process(&$element, &$form_state, $form) {
   $item = $element['#value'];
   $item['fid'] = $element['fid']['#value'];
 
@@ -361,8 +361,6 @@ function image_field_widget_process($ele
     '#weight' => -1,
     '#access' => (bool) $item['fid'] && $settings['title_field'],
   );
-
-  return $element;
 }
 
 /**
Index: modules/menu/menu.admin.inc
===================================================================
RCS file: /cvs/drupal/drupal/modules/menu/menu.admin.inc,v
retrieving revision 1.83
diff -u -p -r1.83 menu.admin.inc
--- modules/menu/menu.admin.inc	1 Aug 2010 23:33:18 -0000	1.83
+++ modules/menu/menu.admin.inc	6 Sep 2010 16:52:24 -0000
@@ -435,41 +435,24 @@ function menu_edit_menu($form, &$form_st
       '#title' => t('Title'),
       '#default_value' => $menu['title'],
       '#required' => TRUE,
-      '#field_suffix' => ' <small id="edit-title-suffix">&nbsp;</small>',
     );
   }
 
   // The internal menu name can only be defined during initial menu creation.
-  if (!empty($menu['old_name'])) {
-    $form['#insert'] = FALSE;
-    $form['menu_name'] = array('#type' => 'value', '#value' => $menu['menu_name']);
-  }
-  else {
-    $form['#insert'] = TRUE;
-    $js_settings = array(
-      'type' => 'setting',
-      'data' => array(
-        'machineReadableValue' => array(
-          'title' => array(
-            'text' => t('URL path'),
-            'target' => 'menu-name',
-            'searchPattern' => '[^a-z0-9]+',
-            'replaceToken' => '-',
-          ),
-        ),
-      ),
-    );
-    $form['menu_name'] = array(
-      '#type' => 'textfield',
-      '#title' => t('Menu name'),
-      '#maxsize' => MENU_MAX_MENU_NAME_LENGTH_UI,
-      '#description' => t('This text will be used to construct the URL for the menu. The name must contain only lowercase letters, numbers and hyphens, and must be unique.'),
-      '#required' => TRUE,
-      '#attached' => array(
-        'js' => array(drupal_get_path('module', 'system') . '/system.js', $js_settings),
-      ),
-    );
-  }
+  $form['#insert'] = empty($menu['old_name']);
+  $form['menu_name'] = array(
+    '#type' => 'machine_name',
+    '#title' => t('Menu name'),
+    '#default_value' => $menu['menu_name'],
+    '#maxlength' => MENU_MAX_MENU_NAME_LENGTH_UI,
+    '#description' => t('This text will be used to construct the URL for the menu. The name must contain only lowercase letters, numbers and hyphens, and must be unique.'),
+    '#machine_name_source' => array('title'),
+    '#machine_name_label' => t('URL path'),
+    '#machine_name_pattern' => '[^a-z0-9-]+',
+    '#machine_name_replace' => '-',
+    '#machine_name_exists' => 'menu_edit_menu_name_exists',
+    '#disabled' => !empty($menu['old_name']) || isset($system_menus[$menu['menu_name']]),
+  );
 
   $form['description'] = array(
     '#type' => 'textarea',
@@ -560,26 +543,18 @@ function menu_delete_menu_confirm_submit
 }
 
 /**
- * Validates the human and machine-readable names when adding or editing a menu.
- */
-function menu_edit_menu_validate($form, &$form_state) {
-  $item = $form_state['values'];
-  if (preg_match('/[^a-z0-9-]/', $item['menu_name'])) {
-    form_set_error('menu_name', t('The menu name may only consist of lowercase letters, numbers, and hyphens.'));
-  }
-  if ($form['#insert']) {
-    if (strlen($item['menu_name']) > MENU_MAX_MENU_NAME_LENGTH_UI) {
-      form_set_error('menu_name', format_plural(MENU_MAX_MENU_NAME_LENGTH_UI, "The menu name can't be longer than 1 character.", "The menu name can't be longer than @count characters."));
-    }
+ * Returns whether a menu name already exists.
+ *
+ * @see menu_edit_menu()
+ * @see form_validate_machine_name()
+ */
+function menu_edit_menu_name_exists($value) {
+  // 'menu-' is added to the menu name to avoid name-space conflicts.
+  $value = 'menu-' . $value;
+  $custom_exists = db_query_range('SELECT 1 FROM {menu_custom} WHERE menu_name = :menu', 0, 1, array(':menu' => $value))->fetchField();
+  $link_exists = db_query_range("SELECT 1 FROM {menu_links} WHERE menu_name = :menu", 0, 1, array(':menu' => $value))->fetchField();
 
-    // We will add 'menu-' to the menu name to help avoid name-space conflicts.
-    $item['menu_name'] = 'menu-' . $item['menu_name'];
-    $custom_exists = db_query_range('SELECT 1 FROM {menu_custom} WHERE menu_name = :menu', 0, 1, array(':menu' => $item['menu_name']))->fetchField();
-    $link_exists = db_query_range("SELECT 1 FROM {menu_links} WHERE menu_name = :menu", 0, 1, array(':menu' => $item['menu_name']))->fetchField();
-    if ($custom_exists || $link_exists) {
-      form_set_error('menu_name', t('The menu already exists.'));
-    }
-  }
+  return $custom_exists || $link_exists;
 }
 
 /**
Index: modules/menu/menu.test
===================================================================
RCS file: /cvs/drupal/drupal/modules/menu/menu.test,v
retrieving revision 1.40
diff -u -p -r1.40 menu.test
--- modules/menu/menu.test	30 Aug 2010 00:22:03 -0000	1.40
+++ modules/menu/menu.test	6 Sep 2010 16:52:24 -0000
@@ -140,7 +140,11 @@ class MenuTestCase extends DrupalWebTest
     $this->drupalPost('admin/structure/menu/add', $edit, t('Save'));
 
     // Verify that using a menu_name that is too long results in a validation message.
-    $this->assertText(format_plural(MENU_MAX_MENU_NAME_LENGTH_UI, "The menu name can't be longer than 1 character.", "The menu name can't be longer than @count characters."), t('Validation failed when menu name is too long.'));
+    $this->assertRaw(t('!name cannot be longer than %max characters but is currently %length characters long.', array(
+      '!name' => t('Menu name'),
+      '%max' => MENU_MAX_MENU_NAME_LENGTH_UI,
+      '%length' => drupal_strlen($menu_name),
+    )));
 
     // Change the menu_name so it no longer exceeds the maximum length.
     $menu_name = substr(hash('sha256', $this->randomName(16)), 0, MENU_MAX_MENU_NAME_LENGTH_UI);
@@ -148,7 +152,11 @@ class MenuTestCase extends DrupalWebTest
     $this->drupalPost('admin/structure/menu/add', $edit, t('Save'));
 
     // Verify that no validation error is given for menu_name length.
-    $this->assertNoText(format_plural(MENU_MAX_MENU_NAME_LENGTH_UI, "The menu name can't be longer than 1 character.", "The menu name can't be longer than @count characters."), t('Validation failed when menu name is too long.'));
+    $this->assertNoRaw(t('!name cannot be longer than %max characters but is currently %length characters long.', array(
+      '!name' => t('Menu name'),
+      '%max' => MENU_MAX_MENU_NAME_LENGTH_UI,
+      '%length' => drupal_strlen($menu_name),
+    )));
     // Unlike most other modules, there is no confirmation message displayed.
 
     $this->drupalGet('admin/structure/menu');
Index: modules/node/content_types.inc
===================================================================
RCS file: /cvs/drupal/drupal/modules/node/content_types.inc,v
retrieving revision 1.117
diff -u -p -r1.117 content_types.inc
--- modules/node/content_types.inc	3 Sep 2010 17:47:20 -0000	1.117
+++ modules/node/content_types.inc	6 Sep 2010 16:52:24 -0000
@@ -94,41 +94,16 @@ function node_type_form($form, &$form_st
     '#description' => t('The human-readable name of this content type. This text will be displayed as part of the list on the <em>Add new content</em> page. It is recommended that this name begin with a capital letter and contain only letters, numbers, and spaces. This name must be unique.'),
     '#required' => TRUE,
     '#size' => 30,
-    '#field_suffix' => ' <small id="edit-name-suffix">' . ($type->locked ? t('Machine name: @name', array('@name' => $type->type)) : '&nbsp;') . '</small>',
   );
 
-  if (!$type->locked) {
-    $js_settings = array(
-      'type' => 'setting',
-      'data' => array(
-        'machineReadableValue' => array(
-          'name' => array(
-            'text' => t('Machine name'),
-            'target' => 'type',
-            'searchPattern' => '[^a-z0-9]+',
-            'replaceToken' => '_',
-          ),
-        ),
-      ),
-    );
-    $form['type'] = array(
-      '#title' => t('Machine name'),
-      '#type' => 'textfield',
-      '#default_value' => $type->type,
-      '#maxlength' => 32,
-      '#required' => TRUE,
-      '#description' => t('The machine-readable name of this content type. This text will be used for constructing the URL of the <em>add new content</em> page for this content type. This name must contain only lowercase letters, numbers, and underscores. Underscores will be converted into hyphens when constructing the URL of the <em>add new content</em> page. This name must be unique.'),
-      '#attached' => array(
-        'js' => array(drupal_get_path('module', 'system') . '/system.js', $js_settings),
-      ),
-    );
-  }
-  else {
-    $form['type'] = array(
-      '#type' => 'value',
-      '#value' => $type->type,
-    );
-  }
+  $form['type'] = array(
+    '#type' => 'machine_name',
+    '#default_value' => $type->type,
+    '#maxlength' => 32,
+    '#disabled' => $type->locked,
+    '#machine_name_exists' => 'node_type_load',
+    '#description' => t('The machine-readable name of this content type. This text will be used for constructing the URL of the <em>add new content</em> page for this content type. This name must contain only lowercase letters, numbers, and underscores. Underscores will be converted into hyphens when constructing the URL of the <em>add new content</em> page. This name must be unique.'),
+  );
 
   $form['description'] = array(
     '#title' => t('Description'),
@@ -276,12 +251,6 @@ function node_type_form_validate($form, 
   $types = node_type_get_names();
 
   if (!$form_state['values']['locked']) {
-    if (isset($types[$type->type]) && $type->type != $old_type) {
-      form_set_error('type', t('The machine-readable name %type is already taken.', array('%type' => $type->type)));
-    }
-    if (!preg_match('!^[a-z0-9_]+$!', $type->type)) {
-      form_set_error('type', t('The machine-readable name must contain only lowercase letters, numbers, and underscores.'));
-    }
     // 'theme' conflicts with theme_node_form().
     // '0' is invalid, since elsewhere we check it using empty().
     if (in_array($type->type, array('0', 'theme'))) {
Index: modules/system/system.admin.inc
===================================================================
RCS file: /cvs/drupal/drupal/modules/system/system.admin.inc,v
retrieving revision 1.301
diff -u -p -r1.301 system.admin.inc
--- modules/system/system.admin.inc	5 Sep 2010 15:38:16 -0000	1.301
+++ modules/system/system.admin.inc	6 Sep 2010 16:52:24 -0000
@@ -2130,29 +2130,11 @@ function system_add_date_format_type_for
     '#title' => t('Date type'),
     '#type' => 'textfield',
     '#required' => TRUE,
-    '#field_suffix' => ' <small id="edit-date-type-suffix">&nbsp;</small>',
-  );
-  $js_settings = array(
-    'type' => 'setting',
-    'data' => array(
-      'machineReadableValue' => array(
-        'date-type' => array(
-          'text' => t('Machine name'),
-          'target' => 'machine-name',
-          'searchPattern' => '[^a-z0-9]+',
-          'replaceToken' => '_',
-        ),
-      ),
-    ),
   );
   $form['machine_name'] = array(
-    '#title' => t('Machine readable name'),
-    '#description' => t('The unique machine readable name for this date type, can only contain lowercase letters, numbers and underscores.'),
-    '#type' => 'textfield',
-    '#required' => TRUE,
-    '#attached' => array(
-      'js' => array(drupal_get_path('module', 'system') . '/system.js', $js_settings),
-    ),
+    '#type' => 'machine_name',
+    '#machine_name_source' => array('date_type'),
+    '#machine_name_exists' => 'system_get_date_types',
   );
 
   // Get list of all available date formats.
Index: modules/system/system.css
===================================================================
RCS file: /cvs/drupal/drupal/modules/system/system.css,v
retrieving revision 1.78
diff -u -p -r1.78 system.css
--- modules/system/system.css	2 Aug 2010 11:22:22 -0000	1.78
+++ modules/system/system.css	6 Sep 2010 16:52:24 -0000
@@ -395,6 +395,16 @@ table.sticky-header {
   clear: left;
 }
 
+/**
+ * Quick inline admin links.
+ */
+small .admin-link:before {
+  content: '[';
+}
+small .admin-link:after {
+  content: ']';
+}
+
 /*
 ** Markup free clearing
 ** Details: http://perishablepress.com/press/2009/12/06/new-clearfix-hack
Index: modules/system/system.js
===================================================================
RCS file: /cvs/drupal/drupal/modules/system/system.js,v
retrieving revision 1.40
diff -u -p -r1.40 system.js
--- modules/system/system.js	30 Jan 2010 00:29:10 -0000	1.40
+++ modules/system/system.js	6 Sep 2010 16:52:24 -0000
@@ -148,78 +148,4 @@ Drupal.behaviors.pageCache = {
   }
 };
 
-/**
- * Attach the auto machine readable name behavior.
- *
- * Settings are expected to be an object of elements to process, where the key
- * defines the source element in the form and the value is an object defining
- * the following properties:
- * - text: The label to display before the auto-generated value.
- * - target: The target form element name.
- * - searchPattern: A regular expression (without modifiers) matching disallowed
- *   characters in the machine readable name, f.e. '[^a-z0-9]+'.
- * - replaceToken: A replacement string to replace disallowed characters, f.e.
- *   '-' or '_'.
- *
- * @see menu_edit_menu()
- */
-Drupal.behaviors.machineReadableValue = {
-  attach: function () {
-    var self = this;
-
-    for (var value in Drupal.settings.machineReadableValue) {
-      var settings = Drupal.settings.machineReadableValue[value];
-
-      // Build selector for the source name entered by a user.
-      var source = '#edit-' + value;
-      var suffix = source + '-suffix';
-      // Build selector for the machine readable name.
-      var target = '#edit-' + settings.target;
-      // Build selector for the wrapper element around the target field.
-      var wrapper = '.form-item-' + settings.target;
-
-      // Do not process the element if we got an error or the given name and the
-      // machine readable name are identical or the machine readable name is
-      // empty.
-      if (!$(target).hasClass('error') && ($(target).val() == '' || $(target).val() == self.transliterate($(source).val(), settings))) {
-        // Hide wrapper element.
-        $(wrapper).hide();
-        // Bind keyup event to source element.
-        $(source).keyup(function () {
-          var machine = self.transliterate($(this).val(), settings);
-          if (machine != '_' && machine != '') {
-            // Set machine readable name to the user entered value.
-            $(target).val(machine);
-            // Append the machine readable name and a link to edit it to the source field.
-            $(suffix).empty().append(' ' + settings.text + ': ' + machine + ' [').append($('<a href="#">' + Drupal.t('Edit') + '</a>').click(function () {
-              $(wrapper).show();
-              $(target).focus();
-              $(suffix).hide();
-              $(source).unbind('keyup');
-              return false;
-            })).append(']');
-          }
-          else {
-            $(target).val(machine);
-            $(suffix).text('');
-          }
-        });
-        // Call keyup event on source element.
-        $(source).keyup();
-      }
-    }
-  },
-
-  /**
-   * Transliterate a human-readable name to a machine name.
-   *
-   * The result should not contain any character matching settings.searchPattern,
-   * invalid characters are typically replaced with settings.replaceToken.
-   */
-  transliterate: function (source, settings) {
-    var searchPattern = new RegExp(settings.searchPattern, 'g');
-    return source.toLowerCase().replace(searchPattern, settings.replaceToken);
-  }
-};
-
 })(jQuery);
Index: modules/system/system.module
===================================================================
RCS file: /cvs/drupal/drupal/modules/system/system.module,v
retrieving revision 1.959
diff -u -p -r1.959 system.module
--- modules/system/system.module	5 Sep 2010 02:21:38 -0000	1.959
+++ modules/system/system.module	6 Sep 2010 18:08:10 -0000
@@ -346,6 +346,19 @@ function system_element_info() {
     '#theme' => 'textfield',
     '#theme_wrappers' => array('form_element'),
   );
+  // @see form_process_machine_name()
+  $types['machine_name'] = array(
+    '#input' => TRUE,
+    '#default_value' => NULL,
+    '#required' => TRUE,
+    '#maxlength' => 64,
+    '#size' => 60,
+    '#autocomplete_path' => FALSE,
+    '#process' => array('form_process_machine_name', 'ajax_process_form'),
+    '#element_validate' => array('form_validate_machine_name'),
+    '#theme' => 'textfield',
+    '#theme_wrappers' => array('form_element'),
+  );
   $types['password'] = array(
     '#input' => TRUE,
     '#size' => 60,
@@ -2099,10 +2112,10 @@ function system_admin_menu_block($item) 
  * @param $form_element
  *   The form element containing the name of the directory to check.
  */
-function system_check_directory($form_element) {
+function system_check_directory(&$form_element) {
   $directory = $form_element['#value'];
   if (strlen($directory) == 0) {
-    return $form_element;
+    return;
   }
 
   if (!is_dir($directory) && !drupal_mkdir($directory, NULL, TRUE)) {
@@ -2126,8 +2139,6 @@ function system_check_directory($form_el
       file_create_htaccess($directory);
     }
   }
-
-  return $form_element;
 }
 
 /**
Index: modules/system/system.test
===================================================================
RCS file: /cvs/drupal/drupal/modules/system/system.test,v
retrieving revision 1.141
diff -u -p -r1.141 system.test
--- modules/system/system.test	30 Aug 2010 00:22:03 -0000	1.141
+++ modules/system/system.test	6 Sep 2010 16:52:24 -0000
@@ -918,7 +918,7 @@ class DateTimeFunctionalTest extends Dru
 
     // Add custom date type.
     $this->clickLink(t('Add date type'));
-    $date_type = $this->randomName(8);
+    $date_type = strtolower($this->randomName(8));
     $machine_name = 'machine_' . $date_type;
     $date_format = 'd.m.Y - H:i';
     $edit = array(
Index: modules/taxonomy/taxonomy.admin.inc
===================================================================
RCS file: /cvs/drupal/drupal/modules/taxonomy/taxonomy.admin.inc,v
retrieving revision 1.107
diff -u -p -r1.107 taxonomy.admin.inc
--- modules/taxonomy/taxonomy.admin.inc	31 Jul 2010 13:01:50 -0000	1.107
+++ modules/taxonomy/taxonomy.admin.inc	6 Sep 2010 16:52:24 -0000
@@ -137,31 +137,12 @@ function taxonomy_form_vocabulary($form,
     '#default_value' => $vocabulary->name,
     '#maxlength' => 255,
     '#required' => TRUE,
-    '#field_suffix' => ' <small id="edit-name-suffix">&nbsp;</small>',
-  );
-  $js_settings = array(
-    'type' => 'setting',
-    'data' => array(
-      'machineReadableValue' => array(
-        'name' => array(
-          'text' => t('Machine name'),
-          'target' => 'machine-name',
-          'searchPattern' => '[^a-z0-9]+',
-          'replaceToken' => '_',
-        ),
-      ),
-    ),
   );
   $form['machine_name'] = array(
-    '#type' => 'textfield',
-    '#title' => t('Machine-readable name'),
+    '#type' => 'machine_name',
     '#default_value' => $vocabulary->machine_name,
     '#maxlength' => 255,
-    '#description' => t('The unique machine-readable name for this vocabulary, used for theme templates. Can only contain lowercase letters, numbers, and underscores.'),
-    '#required' => TRUE,
-    '#attached' => array(
-      'js' => array(drupal_get_path('module', 'system') . '/system.js', $js_settings),
-    ),
+    '#machine_name_exists' => 'taxonomy_vocabulary_machine_name_load',
   );
   $form['description'] = array(
     '#type' => 'textfield',
@@ -186,34 +167,6 @@ function taxonomy_form_vocabulary($form,
 }
 
 /**
- * Validation handler for the vocabulary form.
- *
- * @see taxonomy_form_vocabulary()
- */
-function taxonomy_form_vocabulary_validate($form, &$form_state) {
-  if ($form_state['clicked_button']['#value'] != t('Delete') && isset($form_state['values']['machine_name'])) {
-
-    // Restrict machine names to appropriate characters.
-    $machine_name = $form_state['values']['machine_name'];
-    if (!preg_match('!^[a-z0-9_]+$!', $form_state['values']['machine_name'])) {
-      form_set_error('machine_name', t('The machine-readable name must contain only lowercase letters, numbers, and underscores.'));
-    }
-    // Restrict machine names to 21 characters to avoid exceeding the limit
-    // for field names.
-    if (drupal_strlen($machine_name) > 21) {
-      form_set_error('machine_name', t('The machine-readable name must not exceed 21 characters.'));
-    }
-
-    // Do not allow duplicate machine names.
-    $vocabularies = taxonomy_get_vocabularies();
-    foreach ($vocabularies as $vocabulary) {
-      if ($machine_name == $vocabulary->machine_name && (!isset($form_state['values']['vid']) || $vocabulary->vid != $form_state['values']['vid'])) {
-        form_set_error('machine_name', t('This machine-readable name is already in use by another vocabulary and must be unique.'));
-      }
-    }
-  }
-}
-/**
  * Accept the form submission for a vocabulary and save the results.
  */
 function taxonomy_form_vocabulary_submit($form, &$form_state) {
Index: modules/taxonomy/taxonomy.test
===================================================================
RCS file: /cvs/drupal/drupal/modules/taxonomy/taxonomy.test,v
retrieving revision 1.90
diff -u -p -r1.90 taxonomy.test
--- modules/taxonomy/taxonomy.test	22 Aug 2010 15:45:03 -0000	1.90
+++ modules/taxonomy/taxonomy.test	6 Sep 2010 16:52:24 -0000
@@ -90,7 +90,7 @@ class TaxonomyVocabularyFunctionalTest e
     // Try to submit a vocabulary with a duplicate machine name.
     $edit['machine_name'] = $machine_name;
     $this->drupalPost('admin/structure/taxonomy/add', $edit, t('Save'));
-    $this->assertText(t('This machine-readable name is already in use by another vocabulary and must be unique.'), t('Duplicate machine name validation was successful'));
+    $this->assertText(t('This machine-readable name is already in use. It must be unique.'), t('Duplicate machine name validation was successful'));
 
     // Try to submit an invalid machine name.
     $edit['machine_name'] = '!&^%';
Index: modules/user/user.module
===================================================================
RCS file: /cvs/drupal/drupal/modules/user/user.module,v
retrieving revision 1.1198
diff -u -p -r1.1198 user.module
--- modules/user/user.module	5 Sep 2010 02:21:38 -0000	1.1198
+++ modules/user/user.module	6 Sep 2010 18:04:13 -0000
@@ -3347,7 +3347,7 @@ function _user_mail_notify($op, $account
  *
  * @see system_element_info()
  */
-function user_form_process_password_confirm($element) {
+function user_form_process_password_confirm(&$element) {
   global $user;
 
   $js_settings = array(
@@ -3378,8 +3378,6 @@ function user_form_process_password_conf
     $already_added = TRUE;
     $element['#attached']['js'][] = array('data' => $js_settings, 'type' => 'setting');
   }
-
-  return $element;
 }
 
 /**
