function features_export_form in Features 7
Same name and namespace in other branches
- 6 features.admin.inc \features_export_form()
- 7.2 features.admin.inc \features_export_form()
Form constructor for features export form.
Acts as a router based on the form_state.
Parameters
object|null $feature: The feature object, if available. NULL by default.
See also
features_export_build_form_submit()
features_export_build_form_populate()
1 string reference to 'features_export_form'
- features_menu in ./
features.module - Implements hook_menu().
File
- ./
features.admin.inc, line 20 - @todo.
Code
function features_export_form($form, $form_state, $feature = NULL) {
module_load_include('inc', 'features', 'features.export');
features_include();
$form = array(
'#attributes' => array(
'class' => array(
'features-export-form',
),
),
'#feature' => isset($feature) ? $feature : NULL,
);
$form['info'] = array(
'#type' => 'fieldset',
'#tree' => FALSE,
);
$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'] : '',
'#attributes' => array(
'class' => array(
'feature-name',
),
),
);
$form['info']['module_name'] = array(
'#type' => 'textfield',
'#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' => !empty($feature->name) ? $feature->name : '',
'#attributes' => array(
'class' => array(
'feature-module-name',
),
),
'#element_validate' => array(
'features_export_form_validate_field',
),
);
// If recreating this feature, disable machine name field and blank out
// js-attachment classes 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'),
'#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,
'#element_validate' => array(
'features_export_form_validate_field',
),
);
$form['info']['project_status_url'] = array(
'#title' => t('URL of update XML'),
'#description' => t('Example: http://mywebsite.com/fserver'),
'#type' => 'textfield',
'#required' => FALSE,
'#default_value' => !empty($feature->info['project status url']) ? $feature->info['project status url'] : '',
'#size' => 30,
'#element_validate' => array(
'features_export_form_validate_field',
),
);
// User-selected feature source components.
$components = features_get_components();
uasort($components, 'features_compare_component_name');
$form['export'] = array(
'#type' => 'fieldset',
'#tree' => FALSE,
'#theme' => 'features_form_export',
);
$form['export']['components'] = array(
'#title' => t('Edit components'),
'#type' => 'select',
'#options' => array(
'------',
),
'#attributes' => array(
'class' => array(
'features-select-components',
),
),
);
$form['export']['sources'] = array(
'#tree' => TRUE,
'#theme' => 'features_form_components',
);
foreach ($components as $component => $component_info) {
$options = features_invoke($component, 'features_export_options');
if ($component === 'dependencies') {
$default_value = !empty($feature->info['dependencies']) ? $feature->info['dependencies'] : array();
}
else {
$default_value = !empty($feature->info['features'][$component]) ? $feature->info['features'][$component] : array();
}
if ($options) {
// Find all default components that are not provided by this feature and
// strip them out of the possible options.
if ($map = features_get_default_map($component)) {
foreach ($map as $k => $v) {
if (isset($options[$k]) && (!isset($feature->name) || $v !== $feature->name)) {
unset($options[$k]);
}
}
}
// Ensure all options are stripped of potentially bad values.
foreach ($options as $k => $v) {
$options[$k] = check_plain($v);
}
$label = isset($component_info['name']) ? $component_info['name'] . ": " . $component : $component;
$form['export']['components']['#options'][$component] = $label;
if (!empty($options)) {
$form['export']['sources'][$component] = array(
'#type' => 'checkboxes',
'#options' => features_dom_encode_options($options),
'#title' => check_plain($component),
'#default_value' => features_dom_encode_options($default_value, FALSE),
'#ajax' => array(
'callback' => 'features_export_build_form_populate',
'wrapper' => 'features-export-contents',
),
);
}
else {
$form['export']['sources'][$component] = array(
'#type' => 'item',
'#title' => check_plain($component),
'#value' => t('All components of this type are exported by other features or modules.'),
);
}
}
}
$form['export']['features'] = array(
'#tree' => TRUE,
'#prefix' => "<div id='features-export-populated'><div id='features-export-contents'>",
'#suffix' => "</div></div>",
'#markup' => !empty($feature->info) ? theme('features_components', array(
'info' => $feature->info,
'sources' => $feature->info['features'],
)) : "<div class='placeholder'></div>",
);
$form['buttons'] = array(
'#theme' => 'features_form_buttons',
'#tree' => FALSE,
);
$form['buttons']['submit'] = array(
'#type' => 'submit',
'#value' => t('Download feature'),
'#weight' => 10,
'#submit' => array(
'features_export_build_form_submit',
),
);
return $form;
}