? .DS_Store ? 471018_machine_readable_name-42.patch ? 471018_machine_readable_name-43.patch ? head.db ? try_not_to_break_head_next_time.patch ? modules/.DS_Store ? sites/.DS_Store ? sites/default/.DS_Store ? sites/default/files ? sites/default/settings.php Index: modules/menu/menu.admin.inc =================================================================== RCS file: /cvs/drupal/drupal/modules/menu/menu.admin.inc,v retrieving revision 1.53 diff -u -p -r1.53 menu.admin.inc --- modules/menu/menu.admin.inc 20 Jul 2009 18:51:33 -0000 1.53 +++ modules/menu/menu.admin.inc 15 Aug 2009 00:32:43 -0000 @@ -419,8 +419,25 @@ function menu_edit_menu(&$form_state, $t '#type' => 'textfield', '#title' => t('Menu name'), '#maxsize' => MENU_MAX_MENU_NAME_LENGTH_UI, - '#description' => t('The machine-readable name of this menu. This text will be used for constructing the URL of the menu overview page for this menu. This name must contain only lowercase letters, numbers, and hyphens, and must be unique.'), + '#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, + '#weight' => 1, + '#attached_js' => array( + drupal_get_path('module', 'system') . '/system.js', + array( + 'type' => 'setting', + 'data' => array( + 'machineReadableValue' => array( + 'title' => array( + 'text' => t('URL path'), + 'target' => 'menu-name', + 'searchPattern' => '[^a-z0-9]+', + 'replaceToken' => '-', + ), + ), + ), + ), + ), ); $form['#insert'] = TRUE; } @@ -437,16 +454,20 @@ function menu_edit_menu(&$form_state, $t '#title' => t('Title'), '#default_value' => $menu['title'], '#required' => TRUE, + '#field_suffix' => '  ', + '#weight' => 0, ); } $form['description'] = array( '#type' => 'textarea', '#title' => t('Description'), '#default_value' => $menu['description'], + '#weight' => 2, ); $form['submit'] = array( '#type' => 'submit', '#value' => t('Save'), + '#weight' => 10, ); return $form; Index: modules/node/content_types.inc =================================================================== RCS file: /cvs/drupal/drupal/modules/node/content_types.inc,v retrieving revision 1.87 diff -u -p -r1.87 content_types.inc --- modules/node/content_types.inc 14 Aug 2009 00:12:57 -0000 1.87 +++ modules/node/content_types.inc 15 Aug 2009 00:32:43 -0000 @@ -58,7 +58,6 @@ function theme_node_admin_overview($name * Generates the node type editing form. */ function node_type_form(&$form_state, $type = NULL) { - drupal_add_js(drupal_get_path('module', 'node') . '/content_types.js'); if (!isset($type->type)) { // This is a new type. Node module managed types are custom and unlocked. $type = node_type_set_defaults(array('custom' => 1, 'locked' => 0)); @@ -78,7 +77,7 @@ function node_type_form(&$form_state, $t '#description' => t('The human-readable name of this content type. This text will be displayed as part of the list on the add new content 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' => '  ', + '#field_suffix' => ' ' . ($type->locked ? t('Machine name: @name', array('@name' => $type->type)) : ' ') . '', ); if (!$type->locked) { @@ -89,6 +88,22 @@ function node_type_form(&$form_state, $t '#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 add new content 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 add new content page. This name must be unique.'), + '#attached_js' => array( + drupal_get_path('module', 'system') . '/system.js', + array( + 'type' => 'setting', + 'data' => array( + 'machineReadableValue' => array( + 'name' => array( + 'text' => t('Machine name'), + 'target' => 'type', + 'searchPattern' => '[^a-z0-9]+', + 'replaceToken' => '_', + ), + ), + ), + ), + ), ); } else { @@ -96,12 +111,6 @@ function node_type_form(&$form_state, $t '#type' => 'value', '#value' => $type->type, ); - $form['identity']['type_display'] = array( - '#title' => t('Machine name'), - '#type' => 'item', - '#markup' => theme('placeholder', $type->type), - '#description' => t('The machine-readable name of this content type. This field cannot be modified for system-defined content types.'), - ); } $form['identity']['description'] = array( Index: modules/node/content_types.js =================================================================== RCS file: modules/node/content_types.js diff -N modules/node/content_types.js --- modules/node/content_types.js 4 Jul 2009 14:57:23 -0000 1.5 +++ /dev/null 1 Jan 1970 00:00:00 -0000 @@ -1,29 +0,0 @@ -// $Id: content_types.js,v 1.5 2009/07/04 14:57:23 dries Exp $ -(function ($) { - -Drupal.behaviors.contentTypes = { - attach: function () { - if ($('#edit-type').val() == $('#edit-name').val().toLowerCase().replace(/[^a-z0-9]+/g, '_').replace(/_+/g, '_') || $('#edit-type').val() == '') { - $('.form-item-type-wrapper').hide(); - $('#edit-name').keyup(function () { - var machine = $(this).val().toLowerCase().replace(/[^a-z0-9]+/g, '_').replace(/_+/g, '_'); - if (machine != '_' && machine != '') { - $('#edit-type').val(machine); - $('#node-type-name-suffix').empty().append(' Machine name: ' + machine + ' [').append($('' + Drupal.t('Edit') + '').click(function () { - $('.form-item-type-wrapper').show(); - $('#node-type-name-suffix').hide(); - $('#edit-name').unbind('keyup'); - return false; - })).append(']'); - } - else { - $('#edit-type').val(machine); - $('#node-type-name-suffix').text(''); - } - }); - $('#edit-name').keyup(); - } - } -}; - -})(jQuery); Index: modules/system/system.js =================================================================== RCS file: /cvs/drupal/drupal/modules/system/system.js,v retrieving revision 1.30 diff -u -p -r1.30 system.js --- modules/system/system.js 12 Aug 2009 11:43:10 -0000 1.30 +++ modules/system/system.js 15 Aug 2009 00:32:44 -0000 @@ -169,5 +169,65 @@ Drupal.behaviors.pageCache = { }, }; +/** + * Attach the auto machine readable behaviour. + * + * Settings are expected to have an array of + * source-form-element-name = { + * text : to show next to user readable value + * target : target-form-element-name, + * searchPattern : regex string without modifiers ie '[^a-z0-9]+' + * replaceToken : token to use for replacement ie '-' or '_' + * } + * + * @see menu_edit_menu() + */ +Drupal.behaviors.machineReadableValue = { + attach: function () { + for (var value in Drupal.settings.machineReadableValue) { + var searchPattern = new RegExp(Drupal.settings.machineReadableValue[value].searchPattern, 'g'); + var replaceToken = Drupal.settings.machineReadableValue[value].replaceToken; + // The name entered by a user. + var source = '#edit-' + value; + var suffix = source + '-suffix'; + // The machine readable name. + var target = '#edit-' + Drupal.settings.machineReadableValue[value].target; + // Wrapper element around the field. + var wrapper = '.' + Drupal.settings.machineReadableValue[value].target + '-wrapper'; + var text = Drupal.settings.machineReadableValue[value].text; + // Do not process the element if we got an error or the give name and the + // machine readable name are identical or the machine readable name is empty. + if (!$(target).hasClass('error') + && ($(target).val() == $(source).val().toLowerCase().replace(searchPattern, replaceToken) + || $(target).val() == '')) { + // Hide wrapper element. + $(wrapper).hide(); + // Bind keyup event to source element. + $(source).keyup(function () { + var machine = $(this).val().toLowerCase().replace(searchPattern, replaceToken); + 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(' ' + text + ': ' + machine + ' [').append($('' + Drupal.t('Edit') + '').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(); + } + } + } +}; + })(jQuery);