function hook_menu

Allows modules to specify valid URLs in FlightPath, and define what function to call when the user visits that URL.

After making changes to your hook menu, you <b>must</b> clear the menu cache for FlightPath! Otherwise, FlightPath will not be aware of your changes. This can be done on the /admin-tools/admin page.

This function should return an array containing everything FP needs to correctly set up the menu item.

First, the index of the array should be the URL itself. Ex: $items["my/url"] = array( ... );

The URL is allowed to contain wildcards (%). Ex: $items["content/%/edit"] = array(...);

The wildcard is in position "1", since the URL pieces begin with zero ("0").

Here are what the inner parts of the array mean:

  • title : The title of the page or menu item. Should not be wrapped in t() function.
  • page_callback: A string which defines the function to call when this URL is accessed.
  • page_arguments: An optional array of arguments to pass to the callback function. May contain numerican references to wildcards in the URL.
  • access_callback: A string which defines a function to call to determine if the user may access this URL. Can be set to TRUE if this URL is open to anyone. May be omitted if you simply want to test if the user has a particular permission, by only setting access_arguments.
  • access_arguments: An array containing the arguments to pass to the access_callback function. If the access_callback function is omitted, it is assumed to be "user_has_permission", in which case you may simply specify an array of permissions here. May contain numerican references to wildcards in the URL.
  • type: A constant value describing the type of menu item it is. Examples are:
    • MENU_TYPE_NORMAL_ITEM - A standard menu item. Will output as a link if the URL conforms to certain requirements.
    • MENU_TYPE_CALLBACK - A menu item which will not display itself on any blocks.
    • MENU_TYPE_TAB - A menu item which will output the page it draws with a tab at the top, or part of a tab family.
    • MENU_TYPE_SUB_TAB - This will output the page as a "sub tab" under the main tab. Ex: the student search tab's subtabs, or the View tab's Display by Year and Display By Type sub tabs.
  • tab_family: If this menu item is a tab, specifying a machine name for the tab family will group all other tabs in that family together, and draw the other tabs in that family at the top of the screen.
  • tab_parent: The *path* of the parent tab for this menu item. Will cause the parent tab's name to be displayed as a tab at the top of the page. Ex: "admin-tools/admin"
  • weight: Optional number, for when menu items are being displayed in a block. Smaller weights appear first.
  • file: Path to a file that this menu item's callback is located in.
  • page_settings: This is an optional array which allows for more detailed control over how the menu item and the page it draws will look. Ex: "page_settings" => array( //....//); See below:

    • page_has_search: TRUE or FALSE, whether or not the search box will be drawn at the top of the screen. This is the search box which searches for students.
    • page_show_title: TRUE if the page should display the title at the top of the content region.
    • page_banner_is_link: TRUE or FALSE. Does the banner at the top of the screen link back to the Main tab. Not implemented right now.
    • page_hide_report_error: TRUE or FALSE. Should the "Contact the FlightPath Production Team" link be shown at the bottom of the screen.
    • page_is_popup: TRUE or FALSE. Whether or not the page is going to be displayed in a popup. Will remove the banner and other elements which might not look good in a popup window.
    • display_greeting: TRUE or FALSE. Should the page have the greeting text at the top? Ex: see the Main tab.
    • display_currently_advising: TRUE or FALSE. Should the page display the "Currently Advising" box at the top of the page?
    • screen_mode: If set to "not_advising" while display_currently_advising is set to TRUE, it will not display the options to change degree options or advising terms.
    • bool_print: Set to TRUE if this page is meant to be printable (it is formatted to print easily).
    • target: The anchor target of this menu item (if it is drawn in a block). Ex: "_blank"
    • menu_icon: A string which points to an icon to display with this link, if it is being displayed in a block.
    • menu_links: An array of links. This is an array of parameters which would fit very will into the l() function. The links will appear as simple links at the top of the page. Will be filtered through hook_menu_handle_replacement_pattern(). Ex: "menu_links" => array(0 => array("text"=>"link", "path"=>"admin/tools", "query"=>"name=bob"))

      • 0..n

        • text: The text of the link
        • path: The internal path of the link. Ex: "admin-tools/admin"
        • query: Optional query to add to the end of the URL. Ex: "de_catalog_year=%DE_CATALOG_YEAR%" Will be filtered through hook_menu_handle_replacement_pattern()

See the examples below for demonstrations of typical menu items.

See also

hook_perm()

hook_menu_handle_replacement_pattern()

14 functions implement hook_menu()

Note: this list is generated by pattern matching, so it may include some functions that are not actually implementations of this hook.

admin_menu in modules/admin/admin.module
Implementation of hook_menu
advise_menu in modules/advise/advise.module
blank_degrees_menu in modules/blank_degrees/blank_degrees.module
Implementation of hook_menu
blocks_menu in modules/blocks/blocks.module
comments_menu in modules/comments/comments.module

... See full list

File

includes/hook.api.php, line 458
Lists all available hooks within FlightPath's core code.

Code

function hook_menu() {
  // Examples from various modules:
  $items = array();

  $items ["main"] = array(
    "title" => "Main",
    "page_callback" => "system_display_main_page",
    "access_callback" => TRUE,
    "type" => MENU_TYPE_TAB,
    "tab_family" => "system",
    "weight" => 10,
    "page_settings" => array(
      "display_greeting" => TRUE,
      "display_currently_advising" => TRUE,
      "screen_mode" => "not_advising",
      "page_has_search" => TRUE,
    ),
  );

  $items ["login"] = array(
    "title" => "Login",
    "page_callback" => "system_display_login_page",
    "access_callback" => TRUE,
    "type" => MENU_TYPE_NORMAL_ITEM,
  );

  $items ["admin-tools/clear-cache"] = array(
    "title" => "Clear all cache",
    "page_callback" => "system_perform_clear_cache",
    "access_arguments" => array("administer_modules"),
    "type" => MENU_TYPE_NORMAL_ITEM,
  );


  $items ["admin/db-updates"] = array(
    "title" => "Run DB updates?",
    "page_callback" => "fp_render_form",
    "page_arguments" => array("system_confirm_db_updates_form"),
    "access_arguments" => array("administer_modules"),
    "type" => MENU_TYPE_NORMAL_ITEM,
  );


  $items ["admin/config/system-settings"] = array(
    "title" => "System settings",
    "page_callback" => "fp_render_form",
    "page_arguments" => array("system_settings_form", "system_settings"),
    "access_arguments" => array("de_can_administer_system_settings"),
    "page_settings" => array(
      "page_has_search" => FALSE,
      "page_banner_is_link" => TRUE,
      "page_hide_report_error" => TRUE,
      "menu_icon" => fp_theme_location() . "/images/toolbox.gif",
      "menu_links" => array(
        0 => array(
          "text" => "Back to main menu",
          "path" => "admin-tools/admin",
          "query" => "de_catalog_year=%DE_CATALOG_YEAR%",
        ),
      ),
    ),
    "type" => MENU_TYPE_NORMAL_ITEM,
    "tab_parent" => "admin-tools/admin",
  );

  $items ["admin-tools/admin"] = array(
    "title" => "FlightPath Admin Console",
    "page_callback" => "admin_display_main",
    "access_arguments" => array("can_access_admin"),
    "tab_family" => "admin",
    "page_settings" => array(
      "page_has_search" => FALSE,
      "page_banner_is_link" => TRUE,
      "page_hide_report_error" => TRUE,
      "target" => "_blank",
    ),
    "type" => MENU_TYPE_TAB,
  );

  $items ["admin/config/modules"] = array(
    "title" => "Modules",
    "page_callback" => "fp_render_form",
    "page_arguments" => array("system_modules_form"),
    "access_arguments" => array("administer_modules"),
    "page_settings" => array(
      "page_has_search" => FALSE,
      "page_banner_is_link" => TRUE,
      "page_hide_report_error" => TRUE,
      "menu_links" => array(
        0 => array(
          "text" => "Back to main menu",
          "path" => "admin-tools/admin",
          "query" => "de_catalog_year=%DE_CATALOG_YEAR%",
        ),
      ),
    ),
    "type" => MENU_TYPE_NORMAL_ITEM,
    "tab_parent" => "admin-tools/admin",
  );


  $items ["view/print"] = array(
    "title" => "View",
    "page_callback" => "advise_display_view",
    "page_arguments" => array("view"),
    "access_callback" => TRUE,
    "page_settings" => array(
      "display_currently_advising" => TRUE,
      "bool_print" => TRUE,
      "screen_mode" => "not_advising",
    ),
    "type" => MENU_TYPE_CALLBACK,
  );



  $items ["admin/config/clear-menu-cache"] = array(
    "title" => "Clear menu cache",
    "page_callback" => "system_perform_clear_menu_cache",
    "access_arguments" => array("administer_modules"),
    "type" => MENU_TYPE_NORMAL_ITEM,
  );

  $items ["system-handle-form-submit"] = array(
    "page_callback" => "system_handle_form_submit",
    "access_callback" => TRUE,
    "type" => MENU_TYPE_CALLBACK,
  );

  $items ["logout"] = array(
    "title" => "Logout",
    "page_callback" => "system_handle_logout",
    "access_callback" => TRUE,
    "type" => MENU_TYPE_CALLBACK,
  );



  $items ["popup-report-contact"] = array(
    "title" => "Report/Contact",
    "page_callback" => "fp_render_form",
    "page_arguments" => array("system_popup_report_contact_form"),
    "access_callback" => TRUE,
    "page_settings" => array(
      "page_is_popup" => TRUE,
      "page_hide_report_error" => TRUE,
    ),
    "type" => MENU_TYPE_CALLBACK,
  );


  $items ["popup-contact-form/thank-you"] = array(
    "title" => "Report/Contact",
    "page_callback" => "system_popup_report_contact_thank_you",
    "access_callback" => TRUE,
    "page_settings" => array(
      "page_is_popup" => TRUE,
      "page_hide_report_error" => TRUE,
    ),
    "type" => MENU_TYPE_CALLBACK,
  );

  $items ["admin/degrees/add-degree"] = array(
    "title" => "Add Degree",
    "page_callback" => "fp_render_form",
    "page_arguments" => array("admin_add_degree_form"),
    "access_arguments" => array("can_edit_data_entry"),
    "page_settings" => array(
      "page_has_search" => FALSE,
      "page_banner_is_link" => TRUE,
      "page_hide_report_error" => TRUE,
      "menu_links" => array(
        0 => array(
          "text" => "Back to main menu",
          "path" => "admin-tools/admin",
          "query" => "de_catalog_year=%DE_CATALOG_YEAR%",
        ),
        1 => array(
          "text" => "Back to Degrees list",
          "path" => "admin/degrees",
          "query" => "de_catalog_year=%DE_CATALOG_YEAR%",
        ),
      ),
    ),
    "file" => menu_get_module_path("admin") . "/admin.degrees.inc",
    "type" => MENU_TYPE_NORMAL_ITEM,
    "tab_parent" => "admin/degrees",
  );

  $items ["admin/config/content"] = array(
    "title" => "Content",
    "page_callback" => "content_display_content_admin_list",
    "access_arguments" => array("admin_content"),
    "page_settings" => array(
      "page_has_search" => FALSE,
      "page_show_title" => TRUE,
      "page_banner_is_link" => TRUE,
      "page_hide_report_error" => TRUE,
      "menu_links" => array(
        0 => array(
          "text" => "Back to main menu",
          "path" => "admin-tools/admin",
          "query" => "de_catalog_year=%DE_CATALOG_YEAR%",
        ),
      ),
    ),
    "type" => MENU_TYPE_TAB,
    "tab_family" => "content_list",
  );

  $items ["content/%"] = array(
    "page_callback" => "content_view_content",
    "page_arguments" => array(1),
    "access_callback" => "content_user_access",
    "access_arguments" => array("view_cid", 1),
    "page_settings" => array(
      "page_has_search" => FALSE,
      "page_show_title" => TRUE,
      "page_banner_is_link" => TRUE,
      "page_hide_report_error" => TRUE,
      "menu_links" => array(
        0 => array(
          "text" => "Edit this content",
          "path" => "content/%CONTENT_CID%/edit",
          "query" => "",
        ),
      ),
    ),
    "type" => MENU_TYPE_TAB,
    "tab_parent" => "admin/config/content",
  );

  $items ["content/%/edit"] = array(
    "page_callback" => "fp_render_form",
    "page_arguments" => array("content_edit_content_form", "", "", 1),
    "access_callback" => "content_user_access",
    "access_arguments" => array("edit_cid", 1),
    "page_settings" => array(
      "page_has_search" => FALSE,
      "page_banner_is_link" => TRUE,
      "page_hide_report_error" => TRUE,
      "menu_links" => array(
        0 => array(
          "text" => "Back to main menu",
          "path" => "admin-tools/admin",
          "query" => "de_catalog_year=%DE_CATALOG_YEAR%",
        ),
        1 => array(
          "text" => "Back to content list",
          "path" => "admin/config/content",
          "query" => "de_catalog_year=%DE_CATALOG_YEAR%",
        ),
      ),
    ),
    "type" => MENU_TYPE_TAB,
    "tab_parent" => "admin/config/content",
  );

  return $items;
}