function features_export_form in Features 7.2
Same name and namespace in other branches
- 6 features.admin.inc \features_export_form()
- 7 features.admin.inc \features_export_form()
Form builder for features export form.
Used on:
- 'admin/structure/features/create'
- 'admin/structure/features/%feature/recreate'
Acts as a router based on the form_state.
Parameters
array $form: Form array, as passed in from form API.
array $form_state: Form state.
object|null $feature: The feature object, if available. NULL by default.
Return value
array Form array.
See also
\features_export_build_form_submit()
1 string reference to 'features_export_form'
- features_menu in ./
features.module - Implements hook_menu().
File
- ./
features.admin.inc, line 133 - Forms for Features admin screens.
Code
function features_export_form($form, $form_state, $feature = NULL) {
module_load_include('inc', 'features', 'features.export');
features_include();
$feature_name = !empty($feature->name) ? $feature->name : '';
$form = array(
'#attributes' => array(
'class' => array(
'features-export-form',
'clearfix',
),
),
'#feature' => isset($feature) ? $feature : NULL,
);
$form['info'] = array(
'#type' => 'fieldset',
'#title' => t('General Information'),
'#tree' => FALSE,
'#weight' => 2,
'#collapsible' => FALSE,
'#collapsed' => FALSE,
'#prefix' => "<div id='features-export-info'>",
'#suffix' => '</div>',
);
$form['info']['name'] = array(
'#title' => t('Name'),
'#description' => t('Example: Image gallery') . ' (' . t('Do not begin name with numbers.') . ')',
'#type' => 'textfield',
'#default_value' => !empty($feature->info['name']) ? $feature->info['name'] : '',
);
$form['info']['module_name'] = array(
'#type' => 'machine_name',
'#title' => t('Machine-readable name'),
'#description' => t('Example: image_gallery') . '<br/>' . t('May only contain lowercase letters, numbers and underscores. <strong>Try to avoid conflicts with the names of existing Drupal projects.</strong>'),
'#required' => TRUE,
'#default_value' => $feature_name,
'#machine_name' => array(
/* @see \features_export_form_module_name_exists() */
'exists' => 'features_export_form_module_name_exists',
'source' => array(
'info',
'name',
),
),
);
// If recreating this feature, disable machine name field to ensure the
// machine name cannot be changed, unless user role has granted permission to
// edit machine name of disabled features.
if (isset($feature) && ($feature->status || !user_access('rename features'))) {
$form['info']['module_name']['#value'] = $feature_name;
$form['info']['module_name']['#disabled'] = TRUE;
}
$form['info']['description'] = array(
'#title' => t('Description'),
'#description' => t('Provide a short description of what users should expect when they enable your feature.'),
'#type' => 'textfield',
'#default_value' => !empty($feature->info['description']) ? $feature->info['description'] : '',
);
$form['info']['package'] = array(
'#title' => t('Package'),
'#description' => t('Organize your features in groups.'),
'#type' => 'textfield',
'#autocomplete_path' => 'features/autocomplete/packages',
'#default_value' => !empty($feature->info['package']) ? $feature->info['package'] : 'Features',
);
$form['info']['version'] = array(
'#title' => t('Version'),
'#description' => t('Examples: 7.x-1.0, 7.x-1.0-beta1'),
'#type' => 'textfield',
'#required' => FALSE,
'#default_value' => !empty($feature->info['version']) ? $feature->info['version'] : '',
'#size' => 30,
/* @see \features_export_form_validate_field() */
'#element_validate' => array(
'features_export_form_validate_field',
),
);
$form['advanced'] = array(
'#type' => 'fieldset',
'#title' => t('Advanced Options'),
'#tree' => FALSE,
'#collapsible' => TRUE,
'#collapsed' => TRUE,
'#weight' => 10,
'#prefix' => "<div id='features-export-advanced'>",
'#suffix' => '</div>',
);
$form['advanced']['project_status_url'] = array(
'#title' => t('URL of update XML'),
'#description' => t('URL of Feature Server. For Example: http://mywebsite.com/fserver'),
'#type' => 'textfield',
'#required' => FALSE,
'#default_value' => !empty($feature->info['project status url']) ? $feature->info['project status url'] : '',
/* @see \features_export_form_validate_field() */
'#element_validate' => array(
'features_export_form_validate_field',
),
);
$directory = !empty($feature->filename) ? dirname($feature->filename) : variable_get('features_default_export_path', FEATURES_DEFAULT_EXPORT_PATH);
if (!empty($feature_name) && substr_compare($directory, $feature_name, strlen($directory) - strlen($feature_name), strlen($feature_name)) === 0) {
// If path ends with module_name, strip it.
$directory = dirname($directory);
}
if (user_access('generate features')) {
$form['advanced']['generate_path'] = array(
'#title' => t('Path to Generate feature module'),
'#description' => t('File path for feature module. For Example: sites/all/modules/features or /tmp. ' . t('Leave blank for <strong>@path</strong>', array(
'@path' => $directory,
))),
'#type' => 'textfield',
'#required' => FALSE,
'#default_value' => !empty($feature->info['project path']) ? $feature->info['project path'] : '',
);
$form['advanced']['generate'] = array(
'#type' => 'submit',
'#value' => t('Generate feature'),
/* @see \features_export_build_form_submit() */
/* @see \features_form_rebuild() */
'#submit' => array(
'features_export_build_form_submit',
'features_form_rebuild',
),
);
}
// Build the component listing panel on the right.
_features_export_form_components($form, $form_state);
$form['advanced']['info-preview'] = array(
'#type' => 'button',
'#value' => t('Preview .info file'),
'#ajax' => array(
/* @see \features_info_file_preview() */
'callback' => 'features_info_file_preview',
'wrapper' => 'features-export-wrapper',
),
);
// Info dialog.
$form['advanced']['info-file'] = array(
'#prefix' => '<div id="features-info-file" title="Export .info file preview">',
'text' => array(
'#type' => 'textarea',
'#default_value' => '',
'#resizable' => FALSE,
),
'#suffix' => '</div>',
);
$form['buttons'] = array(
/* @see \theme_features_form_buttons() */
'#theme' => 'features_form_buttons',
'#tree' => FALSE,
'#weight' => 99,
'#prefix' => "<div id='features-export-buttons'>",
'#suffix' => '</div>',
);
$form['buttons']['submit'] = array(
'#type' => 'submit',
'#value' => t('Download feature'),
'#weight' => 10,
/* @see \features_export_build_form_submit() */
/* @see \features_form_rebuild() */
'#submit' => array(
'features_export_build_form_submit',
'features_form_rebuild',
),
);
$form['#attached']['library'][] = array(
'system',
'ui.dialog',
);
return $form;
}