function features_export_build_form_submit in Features 7
Same name and namespace in other branches
- 6 features.admin.inc \features_export_build_form_submit()
- 7.2 features.admin.inc \features_export_build_form_submit()
Form submission handler for features_export_form().
1 string reference to 'features_export_build_form_submit'
- features_export_form in ./
features.admin.inc - Form constructor for features export form.
File
- ./
features.admin.inc, line 203 - @todo.
Code
function features_export_build_form_submit($form, &$form_state) {
module_load_include('inc', 'features', 'features.export');
features_include();
// Assemble the combined component list
$stub = array();
$components = array_keys(features_get_components());
foreach ($components as $component) {
// User-selected components take precedence.
if (!empty($form_state['values']['sources'][$component])) {
$stub[$component] = features_dom_decode_options(array_filter($form_state['values']['sources'][$component]));
}
else {
if (!empty($form['#feature']->info['features'][$component])) {
$stub[$component] = $form['#feature']->info['features'][$component];
}
}
}
// Generate populated feature
$module_name = $form_state['values']['module_name'];
$export = features_populate($stub, $form_state['values']['sources']['dependencies'], $module_name);
// Directly copy the following attributes
$attr = array(
'name',
'description',
'package',
);
foreach ($attr as $key) {
$export[$key] = isset($form_state['values'][$key]) ? $form_state['values'][$key] : NULL;
}
// If either update status-related keys are provided, add a project key
// corresponding to the module name.
if (!empty($form_state['values']['version']) || !empty($form_state['values']['project_status_url'])) {
$export['project'] = $form_state['values']['module_name'];
}
if (!empty($form_state['values']['version'])) {
$export['version'] = $form_state['values']['version'];
}
if (!empty($form_state['values']['project_status_url'])) {
$export['project status url'] = $form_state['values']['project_status_url'];
}
// Generate download
if ($files = features_export_render($export, $module_name, TRUE)) {
$filename = (!empty($export['version']) ? "{$module_name}-{$export['version']}" : $module_name) . '.tar';
// Clear out output buffer to remove any garbage from tar output.
if (ob_get_level()) {
ob_end_clean();
}
drupal_add_http_header('Content-type', 'application/x-tar');
drupal_add_http_header('Content-Disposition', 'attachment; filename="' . $filename . '"');
drupal_send_headers();
$tar = array();
$filenames = array();
foreach ($files as $extension => $file_contents) {
if (!in_array($extension, array(
'module',
'info',
))) {
$extension .= '.inc';
}
$filenames[] = "{$module_name}.{$extension}";
print features_tar_create("{$module_name}/{$module_name}.{$extension}", $file_contents);
}
if (features_get_modules($module_name, TRUE)) {
$module_path = drupal_get_path('module', $module_name);
// file_scan_directory() can throw warnings when using PHP 5.3, messing
// up the output of our file stream. Suppress errors in this one case in
// order to produce valid output.
foreach (@file_scan_directory($module_path, '/.*/') as $file) {
$filename = substr($file->uri, strlen($module_path) + 1);
if (!in_array($filename, $filenames)) {
// Add this file.
$contents = file_get_contents($file->uri);
print features_tar_create("{$module_name}/{$filename}", $contents);
unset($contents);
}
}
}
print pack("a1024", "");
exit;
}
}