function organigrams_form_export in Organigrams 7
Admin menu callback to export all items from an organigram.
Parameters
array $form: The form being used to export the items.
array $form_state: The form state array.
array $organigram: The organigram object to export.
Return value
mixed Renderable array containing a form.
1 string reference to 'organigrams_form_export'
- organigrams_menu in ./
organigrams.module - Implements hook_menu().
File
- ./
organigrams.admin.inc, line 549 - Defines the administration forms for managing organigrams.
Code
function organigrams_form_export($form, &$form_state, $organigram) {
// Show not found page if no argument is given.
if (empty($organigram)) {
drupal_not_found();
drupal_exit();
}
// Load the organigram if only a machine name is given.
if (is_string($organigram)) {
$organigram = organigrams_machine_name_load($organigram);
}
// If no organigram is found, show not found page.
if (!is_object($organigram)) {
drupal_not_found();
drupal_exit();
}
// Decide which export type should be shown by default.
$type = '';
$args = arg();
if (array_pop($args) == 'full') {
$type = 'full';
}
// Load all items fully loaded from the organigram.
$tree = organigrams_get_tree($organigram->oid, 0, NULL, TRUE);
// Encode it.
$tree_json = json_encode($tree);
// Encode the organigram data.
$organigram_json = json_encode(array(
'organigram' => $organigram,
'items' => $tree,
));
$form['export_type'] = array(
'#type' => 'select',
'#title' => t('What do you want to export?'),
'#description' => t('Select if you want to export the full organigram or only its items.'),
'#options' => array(
t('Full organigram'),
t('Only the organigram items'),
),
'#default_value' => $type == 'full' ? 0 : 1,
);
// Display the data in a textarea.
$form['organigram_export'] = array(
'#type' => 'textarea',
'#title' => t('Organigram export'),
'#description' => t('Copy the contents of this textarea and paste it in the import form of another organigram.'),
'#value' => $organigram_json,
'#states' => array(
'visible' => array(
':input[name=export_type]' => array(
'value' => 0,
),
),
),
);
// Display the data in a textarea.
$form['organigram_items_export'] = array(
'#type' => 'textarea',
'#title' => t('Organigram items export'),
'#description' => t('Copy the contents of this textarea and paste it in the import form of another organigram.'),
'#value' => $tree_json,
'#states' => array(
'visible' => array(
':input[name=export_type]' => array(
'value' => 1,
),
),
),
);
return $form;
}