You are here

function farm_quick_menu in farmOS 7

Implements hook_menu().

File

modules/farm/farm_quick/farm_quick.module, line 81
Code for the Farm Quick module.

Code

function farm_quick_menu() {

  // Start with an empty menu items array.
  $items = array();

  // Ask for quick forms from modules.
  $forms = farm_quick_forms();

  // Get a list of enabled quick forms from saved variable.
  $enabled_quick_forms = variable_get('farm_quick_forms_enabled', array());

  // Filter out disabled forms.
  foreach ($forms as $name => $info) {
    if (empty($enabled_quick_forms[$name])) {
      unset($forms[$name]);
    }
  }

  // Add a menu item for each form.
  foreach ($forms as $name => $form) {

    // Get access permissions for the quick form.
    // Convert it to an array if it isn't already.
    $permissions = array();
    if (isset($form['permission'])) {
      if (!is_array($form['permission'])) {
        $form['permission'] = array(
          $form['permission'],
        );
      }
      $permissions = $form['permission'];
    }

    // Build a menu item definition.
    $menu_item = array(
      'title' => $form['label'],
      'page callback' => 'farm_quick_form_page',
      'page arguments' => array(
        $form['label'],
        $form['form'],
      ),
      'access callback' => 'farm_quick_access',
      'access arguments' => array(
        $permissions,
      ),
      'type' => MENU_LOCAL_TASK,
    );

    // If the quick form code is in a separate file, add that information
    // to the menu item so Drupal knows where to look.
    if (!empty($form['file']) && !empty($form['module'])) {
      $menu_item['file'] = $form['file'];
      $menu_item['file path'] = drupal_get_path('module', $form['module']);
    }

    // Add a menu item.
    $items['farm/quick/' . $name] = $menu_item;
  }

  // Add a tab for configuring quick forms.
  $items['farm/quick/configure'] = array(
    'title' => t('Configure'),
    'page callback' => 'drupal_get_form',
    'page arguments' => array(
      'farm_quick_configure_form',
    ),
    'access arguments' => array(
      'configure farm quick forms',
    ),
    'type' => MENU_LOCAL_TASK,
    'weight' => 100,
  );

  // Make the first item into the default tab.
  reset($items);
  $first = key($items);
  $items['farm/quick'] = $items[$first];
  $items['farm/quick']['title'] = 'Quick forms';
  $items['farm/quick']['type'] = MENU_LOCAL_TASK;
  $items[$first] = array(
    'title' => $items[$first]['title'],
    'type' => MENU_DEFAULT_LOCAL_TASK,
  );

  // Return menu items.
  return $items;
}