summaryrefslogtreecommitdiff
path: root/modules/system
diff options
context:
space:
mode:
authorDries Buytaert <dries@buytaert.net>2010-10-13 13:43:21 +0000
committerDries Buytaert <dries@buytaert.net>2010-10-13 13:43:21 +0000
commit284f2b11a48b893cbd13d5429ad68d207488e4e6 (patch)
tree84b9bd1672ec7d9f585c2e4019d2f1f3b508afe1 /modules/system
parent3e6b9b5ea35dfb32e3c30a4d012f67c1d268a570 (diff)
downloadbrdo-284f2b11a48b893cbd13d5429ad68d207488e4e6.tar.gz
brdo-284f2b11a48b893cbd13d5429ad68d207488e4e6.tar.bz2
- Patch #902644 by sun, tobiasb: machine names are too hard to implement. Date types and menu names are not validated.
This patch fixes a bug, but is also a last minute clean-up that will help with better distribution support. We discussed this in http://drupal.org/node/933846.
Diffstat (limited to 'modules/system')
-rw-r--r--modules/system/system.admin.css10
-rw-r--r--modules/system/system.admin.inc24
-rw-r--r--modules/system/system.js74
-rw-r--r--modules/system/system.module12
-rw-r--r--modules/system/system.test2
5 files changed, 27 insertions, 95 deletions
diff --git a/modules/system/system.admin.css b/modules/system/system.admin.css
index 1d3882669..adcc369fd 100644
--- a/modules/system/system.admin.css
+++ b/modules/system/system.admin.css
@@ -46,6 +46,16 @@ div.admin .expert-link {
}
/**
+ * Quick inline admin links.
+ */
+small .admin-link:before {
+ content: '[';
+}
+small .admin-link:after {
+ content: ']';
+}
+
+/**
* Modules page.
*/
#system-modules div.incompatible {
diff --git a/modules/system/system.admin.inc b/modules/system/system.admin.inc
index b2f5ee240..431a41242 100644
--- a/modules/system/system.admin.inc
+++ b/modules/system/system.admin.inc
@@ -2068,28 +2068,12 @@ function system_add_date_format_type_form($form, &$form_state) {
'#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' => array(
+ 'exists' => 'system_get_date_types',
+ 'source' => array('date_type'),
),
);
diff --git a/modules/system/system.js b/modules/system/system.js
index 07c2eb64f..3cee79f30 100644
--- a/modules/system/system.js
+++ b/modules/system/system.js
@@ -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);
diff --git a/modules/system/system.module b/modules/system/system.module
index 7466480c4..88c9c94c7 100644
--- a/modules/system/system.module
+++ b/modules/system/system.module
@@ -347,6 +347,18 @@ function system_element_info() {
'#theme' => 'textfield',
'#theme_wrappers' => array('form_element'),
);
+ $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,
diff --git a/modules/system/system.test b/modules/system/system.test
index bc5f5593f..e6db7a13c 100644
--- a/modules/system/system.test
+++ b/modules/system/system.test
@@ -948,7 +948,7 @@ class DateTimeFunctionalTest extends DrupalWebTestCase {
// 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(