You are here

function organigrams_form_import_items in Organigrams 7

Admin menu callback to import all items into an organigram.

Parameters

array $form: The form being used to import the items.

array $form_state: The form state array.

array $organigram: The organigram object to import the items in.

Return value

mixed Renderable array containing a form.

1 string reference to 'organigrams_form_import_items'
organigrams_menu in ./organigrams.module
Implements hook_menu().

File

./organigrams.admin.inc, line 638
Defines the administration forms for managing organigrams.

Code

function organigrams_form_import_items($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();
  }

  // Add the organigram to the form.
  $form['#organigram'] = $organigram;

  // Load the import field if confirm_import is not yet set.
  if (empty($form_state['confirm_import'])) {

    // A textarea for the import code.
    $form['import'] = array(
      '#type' => 'textarea',
      '#title' => t('Items import'),
      '#description' => t('Paste the contents of an organigram export in this textarea.'),
    );

    // Add actions.
    $form['actions'] = array(
      '#type' => 'actions',
    );
    $form['actions']['submit'] = array(
      '#type' => 'submit',
      '#value' => t('Start import'),
    );
  }
  else {
    $form['import'] = array(
      '#type' => 'value',
      '#value' => $form_state['values']['import'],
    );
    $form = confirm_form($form, t('Are you sure you want to import items to organigram %name?', array(
      '%name' => $organigram->name,
    )), "admin/structure/organigrams/{$organigram->machine_name}", t('Importing new items in an organigram will delete all existing items. This action cannot be undone.'), t('Import items'), t('Cancel'));
  }
  return $form;
}