You are here

function fasttoggle_menu in Fasttoggle 7

Same name and namespace in other branches
  1. 5 fasttoggle.module \fasttoggle_menu()
  2. 6 fasttoggle.module \fasttoggle_menu()

Implements hook_menu().

This function creates the menu links for all fasttoggle items, so modules implementing fasttoggle support don't need to do anything in this area.

File

./fasttoggle.module, line 18
Enables fast toggling of binary or not so binary settings.

Code

function fasttoggle_menu() {
  $items = array();
  $items['admin/config/system/fasttoggle'] = array(
    'title' => 'Fasttoggle',
    'description' => 'Configure what fast toggling options are available.',
    'page callback' => 'drupal_get_form',
    'page arguments' => array(
      'fasttoggle_settings_form',
    ),
    'file' => 'fasttoggle.admin.inc',
    'access arguments' => array(
      'administer fasttoggle',
    ),
  );
  $configs = fasttoggle_get_available_links();

  // For each available link, create a menu item.
  // The config for an item can override the object type we're expecting, but
  // the general pattern is /fasttoggle/{obj_type}/{obj_id}/{group}/{instance}.
  if (!empty($configs)) {
    foreach ($configs as $key => $data) {
      $object_type = $key;
      $path_item = "%{$key}";
      if (isset($data['override_object_type'])) {
        if ($data['override_object_type'] > '') {
          $path_item = "%{$data['override_object_type']}";
        }
        else {
          $path_item = "%";
        }
      }
      else {
        if (isset($data['object_type'])) {
          $path_item = "%{$data['object_type']}";
        }
      }
      $path = "fasttoggle/{$object_type}/{$path_item}/%/%";
      $items[$path] = array(
        'title' => 'Toggle',
        'page callback' => 'fasttoggle_do_toggle_option',
        'page arguments' => [
          1,
          2,
          3,
          4,
        ],
        'access callback' => TRUE,
        // Access checking is handled in hook_fasttoggle_allowed_links().
        'type' => MENU_CALLBACK,
        'theme callback' => 'ajax_base_page_theme',
      );
    }
  }
  return $items;
}