diff --git a/features.admin.inc b/features.admin.inc
index 4e12576..698e48d 100644
--- a/features.admin.inc
+++ b/features.admin.inc
@@ -104,23 +104,23 @@ function features_export_form($form, $form_state, $feature = NULL) {
'#description' => t('Example: Image gallery') . ' (' . t('Do not begin name with numbers.') . ')',
'#type' => 'textfield',
'#default_value' => !empty($feature->info['name']) ? $feature->info['name'] : '',
- '#attributes' => array('class' => array('feature-name')),
);
$form['info']['module_name'] = array(
- '#type' => 'textfield',
+ '#type' => 'machine_name',
'#title' => t('Machine-readable name'),
'#description' => t('Example: image_gallery') . '
' . t('May only contain lowercase letters, numbers and underscores. Try to avoid conflicts with the names of existing Drupal projects.'),
'#required' => TRUE,
'#default_value' => $feature_name,
- '#attributes' => array('class' => array('feature-module-name')),
- '#element_validate' => array('features_export_form_validate_field'),
+ '#machine_name' => array(
+ 'exists' => 'features_export_form_module_name_exists',
+ 'source' => array('info', 'name'),
+ ),
);
- // If recreating this feature, disable machine name field and blank out
- // js-attachment classes to ensure the machine name cannot be changed.
+ // If recreating this feature, disable machine name field to ensure the
+ // machine name cannot be changed.
if (isset($feature)) {
$form['info']['module_name']['#value'] = $feature_name;
$form['info']['module_name']['#disabled'] = TRUE;
- $form['info']['name']['#attributes'] = array();
}
$form['info']['description'] = array(
'#title' => t('Description'),
@@ -224,6 +224,13 @@ function features_export_form($form, $form_state, $feature = NULL) {
}
/**
+ * Machine name existence callback for the module name.
+ */
+function features_export_form_module_name_exists($value) {
+ return (bool) features_get_info('module', $value);
+}
+
+/**
* Return the render array elements for the Components selection on the Export form
* @param array $feature - feature associative array
* @param array $components - array of components in feature
@@ -779,16 +786,6 @@ function features_info_file_preview($form, &$form_state){
*/
function features_export_form_validate_field($element, &$form_state) {
switch ($element['#name']) {
- case 'module_name':
- if (!preg_match('!^[a-z0-9_]+$!', $element['#value'])) {
- form_error($element, t('The machine-readable name must contain only lowercase letters, numbers, and underscores.'));
- }
- // If user is filling out the feature name for the first time and uses
- // the name of an existing module throw an error.
- else if (empty($element['#default_value']) && features_get_info('module', $element['#value'])) {
- form_error($element, t('A module by the name @name already exists on your site. Please choose a different name.', array('@name' => $element['#value'])));
- }
- break;
case 'project_status_url':
if (!empty($element['#value']) && !valid_url($element['#value'])) {
form_error($element, t('The URL %url is invalid. Please enter a fully-qualified URL, such as http://www.example.com/feed.xml.', array('%url' => $element['#value'])));
diff --git a/features.js b/features.js
index 877285c..b0fba2f 100644
--- a/features.js
+++ b/features.js
@@ -100,33 +100,6 @@ jQuery.fn.sortElements = (function(){
}).trigger('change');
});
- // Export form machine-readable JS
- $('.feature-name:not(.processed)', context).each(function() {
- $('.feature-name')
- .addClass('processed')
- .after(' ');
- if ($('.feature-module-name').val() === $('.feature-name').val().toLowerCase().replace(/[^a-z0-9]+/g, '_').replace(/_+/g, '_') || $('.feature-module-name').val() === '') {
- $('.feature-module-name').parents('.form-item').hide();
- $('.feature-name').bind('keyup change', function() {
- var machine = $(this).val().toLowerCase().replace(/[^a-z0-9]+/g, '_').replace(/_+/g, '_');
- if (machine !== '_' && machine !== '') {
- $('.feature-module-name').val(machine);
- $('.feature-module-name-suffix').empty().append(' Machine name: ' + machine + ' [').append($(''+ Drupal.t('Edit') +'').click(function() {
- $('.feature-module-name').parents('.form-item').show();
- $('.feature-module-name-suffix').hide();
- $('.feature-name').unbind('keyup');
- return false;
- })).append(']');
- }
- else {
- $('.feature-module-name').val(machine);
- $('.feature-module-name-suffix').text('');
- }
- });
- $('.feature-name').keyup();
- }
- });
-
//View info dialog
var infoDialog = $('#features-info-file');
if (infoDialog.length != 0) {