function features_tools_export_build_form_submit in Features Tools 6
Same name and namespace in other branches
- 6.2 features_tools.module \features_tools_export_build_form_submit()
submit function for the features_export_form, write the file to disk.
1 call to features_tools_export_build_form_submit()
1 string reference to 'features_tools_export_build_form_submit'
- features_tools_form_features_export_form_alter in ./
features_tools.module - Implementation of hook_form_FORM_ID_alter().
File
- ./
features_tools.module, line 153 - features_tools module
Code
function features_tools_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]));
}
elseif (!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',
);
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.
$directory = '';
$destination = $form_state['values']['features_tools_dest'];
if ($destination) {
$directory .= $destination . '/';
}
//TODO: find a better term then arg(3) to find if we are on create page or recreat.
if (arg(3) == 'create') {
$directory .= $module_name;
}
if ($files = features_export_render($export, $module_name, TRUE)) {
//If the directory dont exists create it.
if (!file_exists($directory)) {
mkdir($directory, 0777, TRUE);
}
$error = false;
foreach ($files as $extension => $file_contents) {
if (!in_array($extension, array(
'module',
'info',
))) {
$extension .= '.inc';
}
if (file_put_contents("{$directory}/{$module_name}.{$extension}", $file_contents) === FALSE) {
$error = true;
}
}
if ($error) {
drupal_set_message(t('One or more files cannot be writing to the file system this is probably a permission issue. @see http://drupal.org/project/features_tools for more info'));
}
else {
drupal_set_message(t('The feature was successfully created.'));
}
}
drupal_flush_all_caches();
}