You are here

function organigrams_form_overview_organigrams in Organigrams 7

List all organigrams form.

Parameters

array $form: Contains form elements.

Return value

array Renderable form array.

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

File

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

Code

function organigrams_form_overview_organigrams($form) {

  // Retrieve all organigrams.
  $organigrams = organigrams_get_organigrams();

  // All form should be rendered as a tree.
  $form['#tree'] = TRUE;

  // Add items container.
  $form['items'] = array();

  // Retrieve organigrams count.
  $organigrams_count = count($organigrams);

  // Iterate through organigrams.
  foreach ($organigrams as $organigram) {

    // Retrieve the form element entry by reference.
    $organigram_element =& $form['items'][$organigram->oid];

    // Initialize the organigram element.
    $organigram_element = array();

    // Add the organigram as a property of the form element.
    $organigram_element['#organigram'] = $organigram;

    // Add organigram name as a markup element.
    $organigram_element['name'] = array(
      '#markup' => check_plain($organigram->name) . '<div class="description">[organigrams:' . $organigram->machine_name . ']</div>',
    );

    // Add organigram weight.
    $organigram_element['weight'] = array(
      '#type' => 'weight',
      '#title' => t('Weight for @name', array(
        '@name' => $organigram->name,
      )),
      '#title_display' => 'invisible',
      '#delta' => $organigrams_count,
      '#default_value' => $organigram->weight,
    );

    // Add list, view, add, edit and delete links.
    $organigram_element['list'] = array(
      '#type' => 'link',
      '#title' => t('list items'),
      '#href' => "admin/structure/organigrams/{$organigram->machine_name}",
    );
    $organigram_element['view'] = array(
      '#type' => 'link',
      '#title' => t('view'),
      '#href' => "organigram/{$organigram->machine_name}",
    );
    $organigram_element['edit'] = array(
      '#type' => 'link',
      '#title' => t('edit'),
      '#href' => "admin/structure/organigrams/{$organigram->machine_name}/edit",
    );
    $organigram_element['delete'] = array(
      '#type' => 'link',
      '#title' => t('delete'),
      '#href' => "admin/structure/organigrams/{$organigram->machine_name}/delete",
    );
    $organigram_element['export'] = array(
      '#type' => 'link',
      '#title' => t('export'),
      '#href' => "admin/structure/organigrams/{$organigram->machine_name}/export/full",
    );
  }
  $form['#empty_text'] = t('No organigrams available. <a href="@link">Add organigram</a>.', array(
    '@link' => url('admin/structure/organigrams/add'),
  ));

  // Only make this form include a submit button and weight if more than one
  // organigram exists.
  $form['actions'] = array(
    '#type' => 'actions',
  );
  $form['actions']['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Save'),
  );
  return $form;
}