From a8cc3e30c374e64d1bff2fda233190fd05c9a0ee Mon Sep 17 00:00:00 2001 From: Angie Byron Date: Sat, 22 Aug 2009 23:18:29 +0000 Subject: #471018 by clemens.tolboom, sun, stBorchert, and mverbaar: Added generic pattern/js for hiding machine readable names (applied to menu and content types). --- modules/node/content_types.inc | 23 +++++++++++++++-------- modules/node/content_types.js | 22 ---------------------- 2 files changed, 15 insertions(+), 30 deletions(-) (limited to 'modules/node') diff --git a/modules/node/content_types.inc b/modules/node/content_types.inc index 005603c06..7d5351e06 100644 --- a/modules/node/content_types.inc +++ b/modules/node/content_types.inc @@ -58,7 +58,6 @@ function theme_node_admin_overview($name, $type) { * 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,10 +77,23 @@ function node_type_form(&$form_state, $type = NULL) { '#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) { + $js_settings = array( + 'type' => 'setting', + 'data' => array( + 'machineReadableValue' => array( + 'name' => array( + 'text' => t('Machine name'), + 'target' => 'type', + 'searchPattern' => '[^a-z0-9]+', + 'replaceToken' => '_', + ), + ), + ), + ); $form['identity']['type'] = array( '#title' => t('Machine name'), '#type' => 'textfield', @@ -89,6 +101,7 @@ function node_type_form(&$form_state, $type = NULL) { '#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', $js_settings), ); } else { @@ -96,12 +109,6 @@ function node_type_form(&$form_state, $type = NULL) { '#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( diff --git a/modules/node/content_types.js b/modules/node/content_types.js index 98a0baed1..8ff713ba9 100644 --- a/modules/node/content_types.js +++ b/modules/node/content_types.js @@ -30,28 +30,6 @@ Drupal.behaviors.contentTypes = { } return vals.join(', '); }); - - // Process the machine name. - 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-textfield.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(); - } } }; -- cgit v1.2.3