| 1 |
<?php
|
| 2 |
/**
|
| 3 |
* @file
|
| 4 |
* Basic UI for port framework.
|
| 5 |
*/
|
| 6 |
|
| 7 |
/*
|
| 8 |
* Implementation of hook_help()
|
| 9 |
* @todo: collides with views_ui.
|
| 10 |
*/
|
| 11 |
function port_ui_help($section) {
|
| 12 |
switch ($section) {
|
| 13 |
case 'admin/build/export':
|
| 14 |
return t('Here you can export portions of this site. Exports are useful for creating install profiles or for deploying configurations from this site on other sites. The corresponding import form is available on !import. The following text is from views ui and should not show up here:', array('!import' => l(t('admin/build/import'), 'admin/build/import')));
|
| 15 |
case 'admin/build/import':
|
| 16 |
return t('Here you can import site elements exported from another Drupal site\'s !export.', array('!export' => l(t('admin/build/export'), 'admin/build/export')));
|
| 17 |
}
|
| 18 |
}
|
| 19 |
|
| 20 |
/**
|
| 21 |
* Implementation of hook_menu().
|
| 22 |
*/
|
| 23 |
function port_ui_menu($may_cache) {
|
| 24 |
if ($may_cache) {
|
| 25 |
$items[] = array(
|
| 26 |
'path' => 'admin/build/export',
|
| 27 |
'title' => t('Export'),
|
| 28 |
'description' => t("Export site elements."),
|
| 29 |
'callback' => 'drupal_get_form',
|
| 30 |
'callback arguments' => array('port_ui_export_form'),
|
| 31 |
'access' => user_access('administer site configuration'),
|
| 32 |
);
|
| 33 |
$items[] = array(
|
| 34 |
'path' => 'admin/build/import',
|
| 35 |
'title' => t('Import'),
|
| 36 |
'description' => t("Import site elements."),
|
| 37 |
'callback' => 'drupal_get_form',
|
| 38 |
'callback arguments' => array('port_ui_import_form'),
|
| 39 |
'access' => user_access('administer site configuration'),
|
| 40 |
);
|
| 41 |
}
|
| 42 |
return $items;
|
| 43 |
}
|
| 44 |
|
| 45 |
/**
|
| 46 |
* Main page callback.
|
| 47 |
*/
|
| 48 |
function port_ui_export_form($stage = 0) {
|
| 49 |
// Multi step handling
|
| 50 |
if ($stage > 2) {
|
| 51 |
$stage = 0;
|
| 52 |
}
|
| 53 |
switch ($stage) {
|
| 54 |
default:
|
| 55 |
// Select which ports to use (e. g. menu).
|
| 56 |
$form = _port_ui_select_ports_form();
|
| 57 |
break;
|
| 58 |
case 1:
|
| 59 |
// Select which items of these ports to export (e. g. menu 2, 3, 5).
|
| 60 |
// Skip if no options available.
|
| 61 |
if ($form = _port_ui_select_ports_options_form()) {
|
| 62 |
break;
|
| 63 |
}
|
| 64 |
$stage = 2;
|
| 65 |
case 2:
|
| 66 |
// Present results.
|
| 67 |
$form = _port_ui_ports_export_result_form();
|
| 68 |
break;
|
| 69 |
}
|
| 70 |
$form['#redirect'] = 'admin/build/export/'. ($stage + 1);
|
| 71 |
return $form;
|
| 72 |
}
|
| 73 |
|
| 74 |
/**
|
| 75 |
* Helper function, builds ports selection form.
|
| 76 |
*/
|
| 77 |
function _port_ui_select_ports_form() {
|
| 78 |
$ports = array();
|
| 79 |
$ports[0] = t('Select which elements of this site you would like to export');
|
| 80 |
$ports = port_get_port_names();
|
| 81 |
|
| 82 |
$form = array();
|
| 83 |
$form['port_ui_export'] = array(
|
| 84 |
'#type' => 'fieldset',
|
| 85 |
'#title' => t('Site elements'),
|
| 86 |
'#description' => t('Choose which site elements to export.'),
|
| 87 |
'#tree' => FALSE,
|
| 88 |
);
|
| 89 |
$form['port_ui_export']['port_ui_export'] = array(
|
| 90 |
'#type' => 'checkboxes',
|
| 91 |
'#options' => $ports,
|
| 92 |
'#default_value' => variable_get('port_ui_export', array()), // drupal_map_assoc($operations),
|
| 93 |
);
|
| 94 |
$form['port_ui_format'] = array(
|
| 95 |
'#type' => 'fieldset',
|
| 96 |
'#title' => t('Output format'),
|
| 97 |
'#description' => t('Choose the desired output format.'),
|
| 98 |
'#tree' => FALSE,
|
| 99 |
);
|
| 100 |
$form['port_ui_format']['port_ui_export_as_functions'] = array(
|
| 101 |
'#type' => 'radios',
|
| 102 |
'#options' => array('array' => t('Data array'), 'functions' => t('PHP functions')),
|
| 103 |
'#description' => t('Data array is ideal for e. g. copy/pasting the exported data to the !import. PHP functions are useful for creating install profiles.',
|
| 104 |
array('!import' => l(t('import text area'), 'admin/build/import'))),
|
| 105 |
'#default_value' => variable_get('port_ui_export_as_functions', 'array'),
|
| 106 |
);
|
| 107 |
$form = system_settings_form($form);
|
| 108 |
unset($form['buttons']['reset']);
|
| 109 |
$form['buttons']['submit']['#value'] = t('Next') .' >>';
|
| 110 |
return $form;
|
| 111 |
}
|
| 112 |
|
| 113 |
/**
|
| 114 |
* Helper function for building port options form section.
|
| 115 |
*/
|
| 116 |
function _port_ui_select_ports_options_form() {
|
| 117 |
$port_ids = variable_get('port_ui_export', array());
|
| 118 |
$defaults = variable_get('port_ui_export_options', array());
|
| 119 |
$export_options = port_get_export_options($port_ids);
|
| 120 |
$port_names = port_get_port_names();
|
| 121 |
|
| 122 |
$form = array();
|
| 123 |
foreach ($export_options as $port_id => $options) {
|
| 124 |
$form['port_ui_export_options'][$port_id] = array(
|
| 125 |
'#type' => 'checkboxes',
|
| 126 |
'#title' => $port_names[$port_id],
|
| 127 |
'#options' => $options,
|
| 128 |
'#default_value' => $defaults[$port_id],
|
| 129 |
);
|
| 130 |
$options_availabe = TRUE;
|
| 131 |
}
|
| 132 |
if ($options_availabe) {
|
| 133 |
$form['port_ui_export_options']['#type'] = 'fieldset';
|
| 134 |
$form['port_ui_export_options']['#title'] = t('Select which items to export');
|
| 135 |
$form['port_ui_export_options']['#tree'] = TRUE;
|
| 136 |
$form = system_settings_form($form);
|
| 137 |
unset($form['buttons']['reset']);
|
| 138 |
$form['buttons']['submit']['#value'] = t('Next') .' >>';
|
| 139 |
return $form;
|
| 140 |
}
|
| 141 |
return FALSE;
|
| 142 |
}
|
| 143 |
|
| 144 |
/**
|
| 145 |
* Helper function for presenting result form.
|
| 146 |
* @todo: error handling.
|
| 147 |
*/
|
| 148 |
function _port_ui_ports_export_result_form() {
|
| 149 |
$ports = variable_get('port_ui_export', array());
|
| 150 |
$options = variable_get('port_ui_export_options', array());
|
| 151 |
$functions = port_get_export_functions($ports);
|
| 152 |
|
| 153 |
// drupal_set_message('<pre>'. print_r($_GET['operations'], true) ."</pre>");
|
| 154 |
$result = port_export($functions, $options);
|
| 155 |
if (variable_get('port_ui_export_as_functions', 'functions') == 'functions') {
|
| 156 |
$result = port_convert_to_functions($result);
|
| 157 |
}
|
| 158 |
else {
|
| 159 |
$result = var_export($result, true);
|
| 160 |
}
|
| 161 |
$form = array();
|
| 162 |
if ($result) {
|
| 163 |
$form['result'] = array(
|
| 164 |
'#type' => 'textarea',
|
| 165 |
'#title' => t('Export data'),
|
| 166 |
'#default_value' => $result,
|
| 167 |
);
|
| 168 |
}
|
| 169 |
$form['done'] = array(
|
| 170 |
'#type' => 'submit',
|
| 171 |
'#value' => t('Start over'),
|
| 172 |
);
|
| 173 |
return $form;
|
| 174 |
}
|
| 175 |
|
| 176 |
/**
|
| 177 |
* Menu callback. Builds import page (form).
|
| 178 |
*/
|
| 179 |
function port_ui_import_form() {
|
| 180 |
$form['import'] = array(
|
| 181 |
'#type' => 'textarea',
|
| 182 |
'#title' => t('Import data'),
|
| 183 |
'#description' => t('Paste import array as exported by export form.'),
|
| 184 |
);
|
| 185 |
$form['submit'] = array(
|
| 186 |
'#type' => 'submit',
|
| 187 |
'#value' => t('Import'),
|
| 188 |
);
|
| 189 |
return $form;
|
| 190 |
}
|
| 191 |
|
| 192 |
/**
|
| 193 |
* Submit handler for port_import_form().
|
| 194 |
*/
|
| 195 |
function port_ui_import_form_submit($form_id, $form_values) {
|
| 196 |
if ($form_values['import']) {
|
| 197 |
eval('$import_data = '. $form_values['import'] .';');
|
| 198 |
port_import($import_data);
|
| 199 |
}
|
| 200 |
}
|
| 201 |
|