hook.api.php

  1. 7.x includes/hook.api.php
  2. 6.x includes/hook.api.php
  3. 5.x includes/hook.api.php

Lists all available hooks within FlightPath's core code.

This script is not meant to be included and used in FlightPath, it is simply for documentation of how the various hooks work.

In each example, you may use a hook by replacing the word "hook" with the name of your custom module.

For example, hook_menu() might be my_module_menu(). FlightPath will automatically begin using the hooks in your module, once the module is enabled.

File

includes/hook.api.php
View source
  1. <?php
  2. /**
  3. * @file
  4. * Lists all available hooks within FlightPath's core code.
  5. *
  6. * This script is not meant to be included and used in FlightPath,
  7. * it is simply for documentation of how the various hooks work.
  8. *
  9. * In each example, you may use a hook by replacing the word "hook"
  10. * with the name of your custom module.
  11. *
  12. * For example, hook_menu() might be my_module_menu(). FlightPath
  13. * will automatically begin using the hooks in your module, once the
  14. * module is enabled.
  15. */
  16. /**
  17. * This hook allows other modules to act when we are using the admin operation
  18. * of duplicating an entire catalog year's worth of data.
  19. *
  20. * This is called AFTER the core code has run.
  21. * We expect $source_year and $destination_year to be 4-digit years.
  22. * Ex: 2021 and 2022.
  23. *
  24. *
  25. * $_SESSION['admin_duplicate_year'] will have the courses, groups, and degrees we have worked on as well,
  26. * which other modules may find useful, or wish to make changes to.
  27. *
  28. */
  29. function hook_admin_duplicate_year($source_year, $destination_year) {
  30. // $_SESSION['admin_duplicate_year'] will have the courses, groups, and degrees we have worked on as well,
  31. // which other modules may find useful, or wish to make changes to.
  32. // Ex: $_SESSION['admin_duplicate_year']['courses'] ... ['groups'] ... ['degrees']
  33. // Delete relevant data with catalog_year = destination_year
  34. // ...
  35. // Copy relevant data FROM catalog year source_year to destination_year
  36. // ...
  37. }
  38. /**
  39. * This hook allows a module to modify the links which appear on the left sidebar.
  40. */
  41. function hook_sidebar_left_links_alter($bool_for_hamburger_menu, &$links) {
  42. if (module_enabled('XYZ')) {
  43. $links[] = array(
  44. 'path' => 'tools/xyz',
  45. 'icon' => 'fa-suitcase',
  46. 'desc' => t('XYZ'),
  47. 'class' => 'xyz',
  48. 'weight' => 550,
  49. );
  50. }
  51. // No need to return anything, $links is passed by reference.
  52. }
  53. /**
  54. * This accepts a CWID (student_id or faculty_id), and returns back a
  55. * URL to the user's image, or FALSE if it cannot find one.
  56. *
  57. * type can be either "student" or "faculty"
  58. *
  59. */
  60. function hook_get_user_image_url($cwid, $type = 'student') {
  61. $url = '';
  62. if ($type == 'student') {
  63. $url = "https://myschool.edu/student-data/" . $cwid . ".jpg";
  64. }
  65. if ($type == 'faculty') {
  66. $url = "https://myschool.edu/facstaff-data/" . $cwid . ".jpg";
  67. }
  68. return $url;
  69. }
  70. /**
  71. * This hook allows you to alter the links which appear under the user menu pulldown, in the top-right
  72. * of the screen.
  73. */
  74. function hook_user_menu_links_alter(&$links) {
  75. }
  76. /**
  77. * Alter forms which are created using the Form API
  78. *
  79. * @param &$form
  80. * This is the actual form array, retrieved from the form's callback
  81. * function. It should ALWAYS be passed by reference, so that the
  82. * changes you make to it will carry through.
  83. * @param $form_id
  84. * This is the "form_id" of the form-- usually the name of the callback
  85. * function which created the form. It can be used to identify forms
  86. * before you attempt to take action.
  87. *
  88. */
  89. function hook_form_alter(&$form, $form_id) {
  90. if ($form_id == "example_form_callback") {
  91. $form["new_element"] = array(
  92. // ...
  93. );
  94. }
  95. }
  96. /**
  97. * Used by the stats module, this will ask other modules to return an array
  98. * of paths suitable for the fp_render_menu_block() function. In other words,
  99. * the paths should be the **beginning** of the paths of your custom reports or other links
  100. * which you wish to show up on the stats screen.
  101. *
  102. * To see this in action, examine the stats.module file, function stats_display_main()
  103. * @see stats_display_main
  104. */
  105. function hook_stats_additional_menublocks() {
  106. return array(
  107. 'Custom Reports' => 'stats/custom-reports',
  108. 'Fancy Reports' => 'stats/fancy-reports',
  109. );
  110. }
  111. /**
  112. * This hook is called before displaying the student profile box (which appears at the top of the screen
  113. * on the profile page, as well as other tabs. If bool_mini is set to TRUE, then it means we are showing an
  114. * abbreviated display, like on the Degree tab. If FALSE, it means we are showing everything, like on the student
  115. * profile tab.
  116. *
  117. * Notice that the $extra_profile_items are passed by reference. There is no need to return a value as a result.
  118. */
  119. function hook_alter_student_profile_items($bool_mini, &$extra_profile_items) {
  120. // Option 1
  121. // Add this item for test scores:
  122. $extra_profile_items['right_side'][] = array(
  123. 'label' => 'ACT Score:',
  124. 'content' => '33 (28 E / 35 M)',
  125. 'extra_class' => 'optional-css-class',
  126. 'mobile_content' => 'This is like "content", but is initially hidden via CSS.
  127. If we are on a mobile display, then "content" is hidden via CSS
  128. and this field is displayed instead.',
  129. );
  130. // Option 2: You can also make use of fp_push_and_balance_profile_items() as demonstrated below:
  131. global $current_student_id;
  132. $user_id = db_get_user_id_from_cwid($current_student_id, 'student');
  133. $start_term = trim(user_get_attribute($user_id, 'start_term', ''));
  134. if ($start_term) {
  135. // Filter through term_description...
  136. $disp_term = get_term_description($start_term);
  137. $item = array(
  138. 'label' => 'Candidacy Session:',
  139. 'content' => $start_term,
  140. );
  141. fp_push_and_balance_profile_items($extra_profile_items, array("start_term__value" => $item));
  142. }
  143. }
  144. /**
  145. * Similar to hook_form_alter, this function lets other modules alter
  146. * content which is being rendered through the "render" system.
  147. *
  148. * You may make changes to the render array.
  149. */
  150. function hook_content_alter(&$render, $render_id) {
  151. if ($render_id == 'some_id') {
  152. $render_array['extra'] = array(
  153. 'value' => 'Add this extra content.',
  154. );
  155. }
  156. }
  157. /**
  158. * This hook his called just before returning a Course object from CourseList::find_best_grade_match or find_most_recent_match.
  159. *
  160. * Returns TRUE or FALSE if the $candidate_course is allowed to match for the $needle_course.
  161. *
  162. * @param $degree_id This is the degree the course is trying to be matched within, if applicable.
  163. * @param $group_id This is the group the course is trying to be matched within, if applicable.
  164. *
  165. *
  166. * Note: it should ALWAYS return TRUE as the default case.
  167. *
  168. */
  169. function hook_courselist_find_match_allow_course(Course $candidate_course, Course $needle_course, CourseList $haystack_list_matches, $degree_id = 0, $group_id = 0) {
  170. if ($degree_id == 12345 && $candidate_course->name_equals('ART 101') && ($group_id != 0 && $group_id != '')) {
  171. return FALSE;
  172. }
  173. return TRUE;
  174. }
  175. /**
  176. * This hook is called right before retrieving the plain English description
  177. * for a term_id. It allows modules to change the term_id.
  178. *
  179. * Notice that term_id and $bool_abbreviate are passed by reference!
  180. */
  181. function hook_alter_term_id_prior_to_description(&$term_id, &$bool_abbreviate, $school_id = 0) {
  182. if ($term_id == "201740") {
  183. // change term_id to something else.
  184. $term_id = "555570";
  185. }
  186. }
  187. /**
  188. * Is the course allowed to be assigned to the specified degree? Returns TRUE or FALSE
  189. *
  190. * @return boolean
  191. */
  192. function hook_flightpath_can_assign_course_to_degree_id($degree_id, $course) {
  193. // See previously assigned degrees: $course->assigned_to_degree_ids_array
  194. return TRUE;
  195. } // ...can_assign_course_to_degree_id
  196. /**
  197. * Is the course allowed to be assigned to the specified group? Returns TRUE or FALSE.
  198. * $group should be a fully formed Group object.
  199. *
  200. * This is useful if you have a rule like "No course worth 3 hours is allowed in XYZ group" or something similar.
  201. *
  202. * @return boolean
  203. */
  204. function hook_flightpath_can_assign_course_to_group($group, $course) {
  205. //... Special logic here to see if this course is allowed in this group.
  206. return TRUE;
  207. }
  208. /**
  209. * This hook allows other modules to interact with the AdvisingScreen object
  210. * adter the build_screen_elements method is called.
  211. *
  212. * Of particular interest could be $advising_screen->box_array[]. This is an array of HTML
  213. * for the semester blocks which appear on the screen.
  214. */
  215. function hook_advise_build_screen_elements(&$advising_screen) {
  216. }
  217. /**
  218. * This hook allows another module to alter the way a "degree header" row is drawn onto the advising screen.
  219. *
  220. * These are the rows which appear above a new degree, and say "Required by degree_title", etc. This hook
  221. * allows modules to alter its content.
  222. *
  223. * To see how it is used,
  224. * @see _AdvisingScreen::display_semester()
  225. * @see _AdvisingScreenTypeView::display_semester_list()
  226. *
  227. *
  228. */
  229. function hook_theme_advise_degree_header_row(&$theme) {
  230. }
  231. /**
  232. * This hook allows another module to alter the way a course row is drawn onto the advising screen.
  233. */
  234. function hook_theme_advise_course_row(&$theme) {
  235. }
  236. /**
  237. * Similar to hook_theme_advise_course_row.
  238. * This lets the user theme the "select X hours..." row for a group.
  239. */
  240. function hook_theme_advise_group_select_row(&$theme) {
  241. }
  242. /**
  243. * Similar to other theme functions, this function will take an array which describes *all* the pie charts,
  244. * and allow another module to act on them.
  245. *
  246. * To see how it is used,
  247. * @see _AdvisingScreen::draw_progress_boxes()
  248. */
  249. function hook_theme_pie_charts(&$theme) {
  250. }
  251. /**
  252. * Reports status information which each module is aware of, visible on admin/config/status.
  253. *
  254. * This allows modules to let the user know about requirements which are not being met, or
  255. * simply to let them know that someting is working successfully.
  256. *
  257. * For example, you may want to let the user know that a nightly job failed to run the night before.
  258. *
  259. * @return array
  260. * - severity: "normal", "warning", and "alert" are the choices.
  261. * - status: A short message.
  262. *
  263. */
  264. function hook_status() {
  265. // Example from system.module, reporting on if Cron has run recently:
  266. $rtn = array();
  267. $rtn["severity"] = "normal";
  268. // Check on the last time cron was run; make sure it's working properly.
  269. $last_run = variable_get("cron_last_run", 0);
  270. if ($last_run < strtotime("-2 DAY")) {
  271. $rtn["severity"] = "alert";
  272. $rtn["status"] = t("Cron hasn't run in over 2 days. For your installation of FlightPath
  273. to function properly, cron.php must be accessed routinely. At least once per day is recommended.");
  274. }
  275. else {
  276. $rtn["status"] = t("Cron was last run on %date", array("%date" => format_date($last_run)));
  277. }
  278. $rtn["status"] .= "<p style='font-size: 0.8em;'>" . t("Your site's cron URL is:");
  279. $rtn["status"] .= "<br>&nbsp; &nbsp; <i>" . $GLOBALS["fp_system_settings"]["base_url"] . "/cron.php?t=" . $GLOBALS["fp_system_settings"]["cron_security_token"] . "</i>
  280. <br>" . t("Example linux cron command:") . "&nbsp; <i>wget -O - -q -t 1 http://ABOVE_URL</i>";
  281. $rtn["status"] .= "</p>";
  282. return $rtn;
  283. }
  284. /**
  285. * Allows a module to act on the degree_plan object AFTER being initialized by the FlightPath module.
  286. *
  287. * This happens BEFORE any of the student's courses are assigned to the degree plan.
  288. *
  289. */
  290. function hook_init_flightpath_degree($student_id, &$degree_plan) {
  291. // Perform actions
  292. // Nothing is returned, since we are using pass-by-reference
  293. }
  294. /**
  295. * Returns a full listing of the student's majors.
  296. *
  297. * @see fp_get_student_majors()
  298. */
  299. function hook_fp_get_student_majors($student_cwid, $bool_return_as_full_record = FALSE, $perform_join_with_degrees = TRUE, $bool_skip_directives = TRUE, $bool_check_for_allow_dynamic = TRUE) {
  300. // Example code from system.module:
  301. $db = get_global_database_handler();
  302. $rtn = $db->get_student_majors_from_db($student_cwid, $bool_return_as_full_record, $perform_join_with_degrees, $bool_skip_directives, $bool_check_for_allow_dynamic);
  303. return $rtn;
  304. }
  305. /**
  306. * Validates form submissions from the Form API
  307. *
  308. * This function can be named anything you want (or can be considered optional).
  309. * If named the same thing as the form callback, it will be utilized automatically.
  310. * For example, if you form is named my_form, then if you have a validate function
  311. * named my_form_validate, it will be called automatically.
  312. *
  313. * Since $form_state is passed by reference, you may make changes to this array, and
  314. * those changes will carry through to other validate functions (defined with #validate_handlers)
  315. * and then to the submit handler(s).
  316. *
  317. * @see hook_submit($form, &$form_state)
  318. */
  319. function hook_validate($form, &$form_state) {
  320. $age = $form_state["values"]["age"];
  321. if ($age < 18) {
  322. form_error("age", "Sorry, you must be 18 or older to submit this form.");
  323. return;
  324. }
  325. }
  326. /**
  327. * This hook is called every time the system cron is run.
  328. *
  329. * Modules should place code here which is meant to be run on a schedule.
  330. */
  331. function hook_cron() {
  332. // Example: check for students who have dropped, and email their advisors.
  333. }
  334. /**
  335. * Handle submissions from the Form API
  336. *
  337. * Like hook_validate, this function (if it exists) is called after you submit a form,
  338. * and after the validation completes without errors. This is where you should act on
  339. * the submission, confident that it has passed validation, and the values in $form_state
  340. * are in the final state.
  341. *
  342. * @see hook_validate($form, &$form_state)
  343. */
  344. function hook_submit($form, &$form_state) {
  345. $values = $form_state["values"];
  346. db_query("INSERT INTO example (f_name) ('?') ", $values["name"]);
  347. }
  348. /**
  349. * This hook will be executed the first time a module is enabled in the system.
  350. *
  351. * It is expected to go in a PHP file named [module].install. Ex: system.install
  352. *
  353. * @see hook_enable()
  354. * @see hook_disable()
  355. * @see hook_update($old_schema, $new_schema)
  356. * @see hook_uninstall()
  357. */
  358. function hook_install() {
  359. // Perform installation functions.
  360. db_query("CREATE TABLE ...... ");
  361. }
  362. /**
  363. * This hook will be executed when a module is enabled in the system. It will be
  364. * executed AFTER hook_install.
  365. *
  366. * It is expected to go in a PHP file named [module].install. Ex: system.install
  367. *
  368. * @see hook_install()
  369. * @see hook_disable()
  370. * @see hook_update($old_schema, $new_schema)
  371. * @see hook_uninstall()
  372. */
  373. function hook_enable() {
  374. fp_add_message("Don't forget to go to settings...");
  375. }
  376. /**
  377. * This hook will be executed when a module is disabled in the system.
  378. *
  379. * It is expected to go in a PHP file named [module].install. Ex: system.install
  380. *
  381. * @see hook_install()
  382. * @see hook_enable()
  383. * @see hook_update($old_schema, $new_schema)
  384. * @see hook_uninstall()
  385. */
  386. function hook_disable() {
  387. fp_add_message("Sorry to see you go!");
  388. }
  389. /**
  390. * This hook will be executed when a module is "uninstalled" in the system. Once
  391. * a module is disabled, an "uninstall" link will appear.
  392. *
  393. * It is expected to go in a PHP file named [module].install. Ex: system.install
  394. *
  395. * @see hook_install()
  396. * @see hook_enable()
  397. * @see hook_update($old_schema, $new_schema)
  398. * @see hook_disable()
  399. */
  400. function hook_uninstall() {
  401. db_query("DROP TABLE mycustomtable ... ");
  402. }
  403. /**
  404. * This hook will be executed when a module is "updated" in the system. If the system
  405. * sees that the schema version defined in the .info file is different than the one
  406. * in the database for that module, an update link will appear.
  407. *
  408. * It is expected to go in a PHP file named [module].install. Ex: system.install
  409. *
  410. * @see hook_install()
  411. * @see hook_enable()
  412. * @see hook_uninstall()
  413. * @see hook_disable()
  414. */
  415. function hook_update($old_schema, $new_schema) {
  416. if ($old_schema < 5) {
  417. db_query("ALTER TABLE ...... ");
  418. }
  419. }
  420. /**
  421. * Handle needed database updates when user updates a module.
  422. *
  423. * Modules can specify which schema their tables are using in their .info file.
  424. * if the module, in a later version, changes the table it writes to, it should increment
  425. * the schema number, whic causes the user to be notified (on the modules page) that they need
  426. * to run the DB updates.
  427. *
  428. * When the DB updates are run, every module implementing this function will be called
  429. * (it is expected to be in a .install file, instead of the .module file, though both get
  430. * included by the system first).
  431. *
  432. * In this function, the developer can see what schema they are coming FROM, and make table
  433. * or other alterations based on that information.
  434. *
  435. * @param $old_schema
  436. * This will be the schema value we are upgrading FROM. Ex: 0, 1, 17, etc.
  437. * @param $new_schema
  438. * This is the new schema value in the module's .info file, that
  439. * we are upgrading to. Ex: 2, 18, etc.
  440. *
  441. */
  442. function hook_update($old_schema, $new_schema) {
  443. if ($new_schema < 4) {
  444. db_query("ALTER TABLE my_example_table ...... ");
  445. }
  446. }
  447. /**
  448. * Allows each module to perform actions when the cache is cleared.
  449. *
  450. * If your custom module needs to clear its own cache, for example,
  451. * then you should implement this hook and place your module-specific
  452. * code inside.
  453. *
  454. */
  455. function hook_clear_cache() {
  456. db_query("DELETE FROM mymodule_cache_tables WHERE 1");
  457. }
  458. /**
  459. * Allows each module to execute code when the module is first loaded.
  460. *
  461. * Typically, this means that we will execute code when the page is first loaded.
  462. * Also useful for including javascript or CSS on the page, but only under certain
  463. * conditions (like who the user is, or what permissions they have)
  464. *
  465. * @see hook_exit
  466. */
  467. function hook_init() {
  468. // Perform actions when page is loaded...
  469. if (user_has_permission("some_permission")) {
  470. $GLOBALS["some_variable"] = TRUE;
  471. }
  472. }
  473. /**
  474. * Allows each module to execute code when the FlightPath page is completely finished.
  475. *
  476. * Be aware that theming and themable functions will not work, since this hook is called
  477. * after the page has been completely rendered. If you need to output debug statements for yourself,
  478. * use echo or print, and it will be at the BOTTOM of the page.
  479. *
  480. * @see hook_init
  481. */
  482. function hook_exit() {
  483. // ex: Close outside db connections
  484. // ex: print "Time for page to load:" . $ctime;
  485. }
  486. /**
  487. * Perform actions when the user logs in successfully.
  488. *
  489. * Notice that $account is passed by reference. You may make whatever changes
  490. * you wish to this object.
  491. */
  492. function hook_user_login(&$account) {
  493. if ($account->uid = 9) {
  494. $account->this_is_jeff = TRUE;
  495. }
  496. }
  497. /**
  498. * Runs AFTER FlightPath has logged out. Allows modules to add additional
  499. * functionality. For example, to go to a special page.
  500. */
  501. function hook_user_logout() {
  502. fp_goto("special-post-logout-page");
  503. }
  504. /**
  505. * This hook defines available permissions for a module.
  506. * These perms are used with hook_menu() and the function user_has_permission()
  507. *
  508. * They are defined in the form of an associative array.
  509. *
  510. * Return array should look like this:
  511. * $rtn["machine_name_of_perm"] = array(
  512. * "title" => "Human readable title for perm",
  513. * "description" => "Optional longer description of what perm allows.",
  514. * "admin_restricted" => FALSE, // Optional. If TRUE, only admin (user_id 1) can grant this permission to other roles.
  515. * );
  516. *
  517. * @return array
  518. *
  519. * @see hook_menu()
  520. * @see user_has_permission()
  521. *
  522. */
  523. function hook_perm() {
  524. // An example from system.module:
  525. $perms = array (
  526. "access_logged_in_content" => array(
  527. "title" => t("Access logged-in content"),
  528. "description" => t("This should be given to all authenticated users. It simply means
  529. the user is allowed to view the logged-in area of FlightPath."),
  530. ),
  531. "administer_modules" => array(
  532. "title" => t("Administer modules"),
  533. "description" => t("This will allow a user to install, enable, disable, and uninstall modules."),
  534. "admin_restricted" => TRUE, // means only appears for admin (user_id == 1)
  535. ),
  536. "run_cron" => array(
  537. "title" => t("Run Cron"),
  538. "description" => t("The user may run hook_cron functions at will. Causes a new menu link to appear
  539. on the admin page."),
  540. ),
  541. "de_can_administer_system_settings" => array(
  542. "title" => t("Can administer system settings"),
  543. "description" => t("This allows the user to edit any of the FlightPath
  544. system settings."),
  545. ),
  546. "view_fpm_debug" => array(
  547. "title" => t("View debug output from the fpm() function"),
  548. "description" => t("The user may view debug output from the fpm() function.
  549. Useful for developers."),
  550. "admin_restricted" => TRUE, // means only appears for admin (user_id == 1)
  551. ),
  552. );
  553. return $perms;
  554. }
  555. /**
  556. * Allows modules to hook in after a new student object is created.
  557. *
  558. * This is so that modules can modify student objects (including what courses they
  559. * have taken) when that student object is first created. For example, if you need
  560. * to query extra databases to get all of a student's credits.
  561. */
  562. function hook_student_load(&$student) {
  563. if ($student->gpa > 3) {
  564. $student->deans_list = TRUE;
  565. }
  566. }
  567. /**
  568. * Allows modules to hook in after a degree plan object is created & loaded.
  569. *
  570. * Specifically, this is called at the end of the DegreePlan::load_degree_plan() method is called.
  571. *
  572. * Similar concept to hook_student_load
  573. *
  574. * @see hook_student_load()
  575. */
  576. function hook_degree_plan_load(&$degree) {
  577. if ($degree->major_code == 'XYZ') {
  578. $degree->is_xyz = TRUE;
  579. }
  580. }
  581. /**
  582. * Allows modules to act after a group object has been loaded.
  583. *
  584. * Specifically, this is called at the end of Group::load_group()
  585. *
  586. * @see hook_degree_plan_load()
  587. */
  588. function hook_group_load(&$group) {
  589. if ($group->group_name == "YXZ") {
  590. $group->is_xyz = TRUE;
  591. }
  592. }
  593. /**
  594. * Allows modules to act after a course object has been loaded.
  595. *
  596. * Specifically, this is called at the end of Course::load_course()
  597. *
  598. * @see hook_degree_plan_load()
  599. */
  600. function hook_course_load(&$course) {
  601. if ($course->subject_id == "YXZ") {
  602. $course->is_xyz = TRUE;
  603. }
  604. }
  605. /**
  606. * Allows modules to execute code when the admin user has chose to "apply draft changes".
  607. */
  608. function hook_apply_draft_changes() {
  609. $table_name = "my_module_table";
  610. $draft_table_name = "draft_$table_name";
  611. // First, truncate existing...
  612. $query = "truncate table $table_name";
  613. $res = db_query($query);
  614. // Now, copy in draft changes...
  615. $query = "INSERT INTO $table_name
  616. SELECT * FROM $draft_table_name ";
  617. $res = db_query($query);
  618. }
  619. /**
  620. * Allows modules to specify valid URLs in FlightPath, and define what function to call
  621. * when the user visits that URL.
  622. *
  623. * After making changes to your hook menu, you <b>must</b> clear the menu cache for FlightPath!
  624. * Otherwise, FlightPath will not be aware of your changes. This can be done on the /admin-tools/admin page.
  625. *
  626. * This function should return an array containing everything FP needs to correctly set up
  627. * the menu item.
  628. *
  629. * First, the index of the array should be the URL itself.
  630. * Ex: $items["my/url"] = array(
  631. * ...
  632. * );
  633. *
  634. * The URL is allowed to contain wildcards (%).
  635. * Ex:
  636. * $items["content/%/edit"] = array(...);
  637. *
  638. * The wildcard is in position "1", since the URL pieces begin with zero ("0").
  639. *
  640. * Here are what the inner parts of the array mean:
  641. * - title : The title of the page or menu item. Should not be wrapped in t() function.
  642. * - page_callback: A string which defines the function to call when this URL is accessed.
  643. * - page_arguments: An optional array of arguments to pass to the callback function. May contain numerican references to wildcards in the URL.
  644. * - access_callback: A string which defines a function to call to determine if the user may access this URL.
  645. * 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
  646. * permission, by only setting access_arguments.
  647. * - access_arguments: An array containing the arguments to pass to the access_callback function. If the access_callback
  648. * function is omitted, it is assumed to be "user_has_permission", in which case you may simply specify
  649. * an array of permissions here. May contain numerical references to wildcards in the URL.
  650. * - type: A constant value describing the type of menu item it is. Examples are:
  651. * - MENU_TYPE_NORMAL_ITEM - A standard menu item. Will output as a link if the URL conforms to certain requirements.
  652. * - MENU_TYPE_CALLBACK - A menu item which will not display itself on any blocks.
  653. * - 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.
  654. * - MENU_TYPE_DEFAULT_TAB - This is a menu item which will be rendered in a block like a CALLBACK, but is in fact the first in a tab family.
  655. * - 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
  656. * the View tab's Display by Year and Display By Type sub tabs.
  657. * - tab_family: If this menu item is a tab, specifying a machine name for the tab family will group all other tabs
  658. * in that family together, and draw the other tabs in that family at the top of the screen.
  659. * - tab_parent: The *path* of the parent tab for this menu item. Will cause the parent tab's name to be displayed
  660. * as a tab at the top of the page. Ex: "admin-tools/admin"
  661. * - weight: Optional number, for when menu items are being displayed in a block. Smaller weights appear first.
  662. * - file: Path to a file that this menu item's callback is located in.
  663. * - page_settings: This is an optional array which allows for more detailed control over how the menu item and the page
  664. * it draws will look. Ex: "page_settings" => array( //....//); See below:
  665. * - page_has_search: TRUE or FALSE, whether or not the search box will be drawn at the top of the screen. This is the
  666. * search box which searches for students.
  667. * - page_show_title: TRUE if the page should display the title at the top of the content region.
  668. * - 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.
  669. * - page_hide_report_error: TRUE or FALSE. Should the "Contact the FlightPath Production Team" link be shown at the bottom of the screen.
  670. * - 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
  671. * elements which might not look good in a popup window.
  672. * - display_currently_advising: TRUE or FALSE. Should the page display the "Currently Advising" box at the top of the page?
  673. * - screen_mode: If set to "not_advising" while display_currently_advising is set to TRUE, it will not display the options
  674. * to change degree options or advising terms.
  675. * - tab_title: This is a string which, if this is a tab, this will be the tab's text. If not present, we will use the regular title.
  676. * - target: The anchor target of this menu item (if it is drawn in a block). Ex: "_blank"
  677. * - menu_icon: A string which points to an icon to display with this link, if it is being displayed in a block.
  678. * - menu_links: An array of links. This is an array of parameters which would fit very will into the l() function.
  679. * The links will appear as simple links at the top of the page. Will be filtered through hook_menu_handle_replacement_pattern().
  680. * Ex: "menu_links" => array(0 => array("text"=>"link", "path"=>"admin/tools", "query"=>"name=bob"))
  681. * - 0..n
  682. * - text: The text of the link
  683. * - path: The internal path of the link. Ex: "admin-tools/admin"
  684. * - query: Optional query to add to the end of the URL. Ex: "de_catalog_year=%DE_CATALOG_YEAR%"
  685. * Will be filtered through hook_menu_handle_replacement_pattern()
  686. *
  687. *
  688. * See the examples below for demonstrations of typical menu items.
  689. *
  690. * @return array
  691. *
  692. * @see hook_perm()
  693. * @see hook_menu_handle_replacement_pattern()
  694. *
  695. */
  696. function hook_menu() {
  697. // Examples from various modules:
  698. $items = array();
  699. $items["main"] = array(
  700. "title" => "Main",
  701. "page_callback" => "system_display_main_page",
  702. "access_callback" => TRUE,
  703. "type" => MENU_TYPE_TAB,
  704. "tab_family" => "system",
  705. "weight" => 10,
  706. "page_settings" => array(
  707. "display_greeting" => TRUE,
  708. "display_currently_advising" => TRUE,
  709. "screen_mode" => "not_advising",
  710. "page_has_search" => TRUE,
  711. ),
  712. );
  713. $items["login"] = array(
  714. "title" => "Login",
  715. "page_callback" => "system_display_login_page",
  716. "access_callback" => TRUE,
  717. "type" => MENU_TYPE_NORMAL_ITEM,
  718. );
  719. $items["admin-tools/clear-cache"] = array(
  720. "title" => "Clear all cache",
  721. "page_callback" => "system_perform_clear_cache",
  722. "access_arguments" => array("administer_modules"),
  723. "type" => MENU_TYPE_NORMAL_ITEM,
  724. );
  725. $items["admin/db-updates"] = array(
  726. "title" => "Run DB updates?",
  727. "page_callback" => "fp_render_form",
  728. "page_arguments" => array("system_confirm_db_updates_form"),
  729. "access_arguments" => array("administer_modules"),
  730. "type" => MENU_TYPE_NORMAL_ITEM,
  731. );
  732. $items["admin/config/system-settings"] = array(
  733. "title" => "System settings",
  734. "page_callback" => "fp_render_form",
  735. "page_arguments" => array("system_settings_form", "system_settings"),
  736. "access_arguments" => array("de_can_administer_system_settings"),
  737. "page_settings" => array(
  738. "page_hide_report_error" => TRUE,
  739. "menu_icon" => fp_theme_location() . "/images/toolbox.gif",
  740. "menu_links" => array(
  741. 0 => array(
  742. "text" => "Back to main menu",
  743. "path" => "admin-tools/admin",
  744. "query" => "de_catalog_year=%DE_CATALOG_YEAR%",
  745. ),
  746. ),
  747. ),
  748. "type" => MENU_TYPE_NORMAL_ITEM,
  749. "tab_parent" => "admin-tools/admin",
  750. );
  751. $items["admin-tools/admin"] = array(
  752. "title" => "FlightPath Admin Console",
  753. "page_callback" => "admin_display_main",
  754. "access_arguments" => array("can_access_admin"),
  755. "tab_family" => "admin",
  756. "page_settings" => array(
  757. "page_hide_report_error" => TRUE,
  758. "target" => "_blank",
  759. ),
  760. "type" => MENU_TYPE_TAB,
  761. );
  762. $items["admin/config/modules"] = array(
  763. "title" => "Modules",
  764. "page_callback" => "fp_render_form",
  765. "page_arguments" => array("system_modules_form"),
  766. "access_arguments" => array("administer_modules"),
  767. "page_settings" => array(
  768. "page_hide_report_error" => TRUE,
  769. "menu_links" => array(
  770. 0 => array(
  771. "text" => "Back to main menu",
  772. "path" => "admin-tools/admin",
  773. "query" => "de_catalog_year=%DE_CATALOG_YEAR%",
  774. ),
  775. ),
  776. ),
  777. "type" => MENU_TYPE_NORMAL_ITEM,
  778. "tab_parent" => "admin-tools/admin",
  779. );
  780. $items["view/print"] = array(
  781. "title" => "View",
  782. "page_callback" => "advise_display_view",
  783. "page_arguments" => array("view"),
  784. "access_callback" => TRUE,
  785. "page_settings" => array (
  786. "display_currently_advising" => TRUE,
  787. "bool_print" => TRUE,
  788. "screen_mode" => "not_advising",
  789. ),
  790. "type" => MENU_TYPE_CALLBACK,
  791. );
  792. $items["admin/config/clear-menu-cache"] = array(
  793. "title" => "Clear menu cache",
  794. "page_callback" => "system_perform_clear_menu_cache",
  795. "access_arguments" => array("administer_modules"),
  796. "type" => MENU_TYPE_NORMAL_ITEM,
  797. );
  798. $items["system-handle-form-submit"] = array(
  799. "page_callback" => "system_handle_form_submit",
  800. "access_callback" => TRUE,
  801. "type" => MENU_TYPE_CALLBACK,
  802. );
  803. $items["logout"] = array(
  804. "title" => "Logout",
  805. "page_callback" => "system_handle_logout",
  806. "access_callback" => TRUE,
  807. "type" => MENU_TYPE_CALLBACK,
  808. );
  809. $items["popup-report-contact"] = array(
  810. "title" => "Report/Contact",
  811. "page_callback" => "fp_render_form",
  812. "page_arguments" => array("system_popup_report_contact_form"),
  813. "access_callback" => TRUE,
  814. "page_settings" => array(
  815. "page_is_popup" => TRUE,
  816. "page_hide_report_error" => TRUE,
  817. ),
  818. "type" => MENU_TYPE_CALLBACK,
  819. );
  820. $items["popup-contact-form/thank-you"] = array(
  821. "title" => "Report/Contact",
  822. "page_callback" => "system_popup_report_contact_thank_you",
  823. "access_callback" => TRUE,
  824. "page_settings" => array(
  825. "page_is_popup" => TRUE,
  826. "page_hide_report_error" => TRUE,
  827. ),
  828. "type" => MENU_TYPE_CALLBACK,
  829. );
  830. $items["admin/degrees/add-degree"] = array(
  831. "title" => "Add Degree",
  832. "page_callback" => "fp_render_form",
  833. "page_arguments" => array("admin_add_degree_form"),
  834. "access_arguments" => array("can_edit_data_entry"),
  835. "page_settings" => array(
  836. "page_hide_report_error" => TRUE,
  837. "menu_links" => array(
  838. 0 => array(
  839. "text" => "Back to main menu",
  840. "path" => "admin-tools/admin",
  841. "query" => "de_catalog_year=%DE_CATALOG_YEAR%",
  842. ),
  843. 1 => array(
  844. "text" => "Back to Degrees list",
  845. "path" => "admin/degrees",
  846. "query" => "de_catalog_year=%DE_CATALOG_YEAR%",
  847. ),
  848. ),
  849. ),
  850. "file" => menu_get_module_path("admin") . "/admin.degrees.inc",
  851. "type" => MENU_TYPE_NORMAL_ITEM,
  852. "tab_parent" => "admin/degrees",
  853. );
  854. $items["admin/config/content"] = array(
  855. "title" => "Content",
  856. "page_callback" => "content_display_content_admin_list",
  857. "access_arguments" => array("admin_content"),
  858. "page_settings" => array(
  859. "page_show_title" => TRUE,
  860. "page_hide_report_error" => TRUE,
  861. "menu_links" => array(
  862. 0 => array(
  863. "text" => "Back to main menu",
  864. "path" => "admin-tools/admin",
  865. "query" => "de_catalog_year=%DE_CATALOG_YEAR%",
  866. ),
  867. ),
  868. ),
  869. "type" => MENU_TYPE_TAB,
  870. "tab_family" => "content_list",
  871. );
  872. $items["content/%"] = array(
  873. "page_callback" => "content_view_content",
  874. "page_arguments" => array(1),
  875. "access_callback" => "content_user_access",
  876. "access_arguments" => array("view_cid", 1),
  877. "page_settings" => array(
  878. "page_show_title" => TRUE,
  879. "page_hide_report_error" => TRUE,
  880. "menu_links" => array(
  881. 0 => array(
  882. "text" => "Edit this content",
  883. "path" => "content/%CONTENT_CID%/edit",
  884. "query" => "",
  885. ),
  886. ),
  887. ),
  888. "type" => MENU_TYPE_TAB,
  889. "tab_parent" => "admin/config/content",
  890. );
  891. $items["content/%/edit"] = array(
  892. "page_callback" => "fp_render_form",
  893. "page_arguments" => array("content_edit_content_form", "", "", 1),
  894. "access_callback" => "content_user_access",
  895. "access_arguments" => array("edit_cid", 1),
  896. "page_settings" => array(
  897. "page_hide_report_error" => TRUE,
  898. "menu_links" => array(
  899. 0 => array(
  900. "text" => "Back to main menu",
  901. "path" => "admin-tools/admin",
  902. "query" => "de_catalog_year=%DE_CATALOG_YEAR%",
  903. ),
  904. 1 => array(
  905. "text" => "Back to content list",
  906. "path" => "admin/config/content",
  907. "query" => "de_catalog_year=%DE_CATALOG_YEAR%",
  908. ),
  909. ),
  910. ),
  911. "type" => MENU_TYPE_TAB,
  912. "tab_parent" => "admin/config/content",
  913. );
  914. return $items;
  915. }
  916. /**
  917. * This function allows the user to theme footnotes before they are drawn onto the screen.
  918. *
  919. */
  920. function hook_theme_advise_footnote(&$theme) {
  921. }
  922. /**
  923. * This function is called by the t() function, and gives modules a chance to intercept
  924. * a string and change it. Meant primarily for translating to another language, but also
  925. * good for simple replacements. Used by the Locale module.
  926. *
  927. * NOTE: Since str is passed by reference, we don't need to return anything
  928. */
  929. function hook_translate(&$str, $langcode = NULL) {
  930. // Ex:
  931. $str = str_replace("something", "something_else", $str);
  932. // Since str is passed by reference, we don't need to return anything
  933. }
  934. /**
  935. * This hook lets us make alterations to menu items before saving them to the database.
  936. *
  937. * It is only called when the menu cache is cleared and being rebuilt.
  938. *
  939. * Notice that $items is passed by reference, so you must make changes to the
  940. * $items array if you want those changes saved, as seen in the xample below.
  941. *
  942. */
  943. function hook_menu_alter(&$items) {
  944. foreach ($items as $path => $item) {
  945. if ($path == 'admin/config/some-path') {
  946. $items[$path]['access_callback'] = 'new_function_name';
  947. }
  948. }
  949. }
  950. /**
  951. * This hook is called by the menu system. It allows each module
  952. * the chance to replace string patterns in its menu items (defined in hook_menu).
  953. *
  954. * It can also be used in the Title of the page or tab.
  955. *
  956. * Replacement patterns must begin and end with %. Ex: %STUDENT_NAME%
  957. *
  958. * @see hook_menu()
  959. */
  960. function hook_menu_handle_replacement_pattern($str) {
  961. /*
  962. * This example, from admin.module, will replace the pattern %DE_CATALOG_YEAR%
  963. * with the actual current catalog year in the system.
  964. *
  965. * An example menu item which uses this replacement pattern would be this:
  966. * $items["admin/config/urgent-message"] = array(
  967. * "title" => "Edit urgent message",
  968. * "page_callback" => "fp_render_form",
  969. * "page_arguments" => array("admin_urgent_message_form", "system_settings"),
  970. * "access_arguments" => array("can_edit_urgent_message"),
  971. * "page_settings" => array(
  972. *
  973. *
  974. * "page_hide_report_error" => TRUE,
  975. * "menu_links" => array(
  976. * 0 => array(
  977. * "text" => "Back to main menu",
  978. * "path" => "admin-tools/admin",
  979. * "query" => "de_catalog_year=%DE_CATALOG_YEAR%", // RIGHT HERE!
  980. * ),
  981. * ),
  982. * ),
  983. * "type" => MENU_TYPE_NORMAL_ITEM,
  984. * "tab_parent" => "admin-tools/admin",
  985. * );
  986. *
  987. */
  988. if (strpos($str, "%DE_CATALOG_YEAR%") !== 0) {
  989. // It contains this replacement pattern!
  990. $str = str_replace("%DE_CATALOG_YEAR%", admin_get_de_catalog_year(), $str);
  991. }
  992. return $str;
  993. }
  994. /**
  995. * This hook allows modules to perform extra functions just after an advising
  996. * session is saved by the system.
  997. *
  998. * The main advising form (on the View and What If tabs) are currently _not_ defined
  999. * through the system's form API. Therefore, a simple hook_submit wouldn't be possible.
  1000. *
  1001. * This hook was created to bridge that gap, until the advising form can be brought into
  1002. * the form API (possibly by 5.x)
  1003. *
  1004. * Advising session values should still be in _REQUEST or _POST.
  1005. *
  1006. *
  1007. * @param $adv_id_array
  1008. * Since this hook is called immediately after submitting the advising session,
  1009. * this array will contain the database ID's to the rows added to the advising_sessions table.
  1010. *
  1011. */
  1012. function hook_save_advising_session_from_post ($student_id, $is_draft, $adv_id_array) {
  1013. foreach ($adv_id_array as $id) {
  1014. // Perform extra actions on those advising sessions.
  1015. }
  1016. // Example functions:
  1017. // Email student a copy of what was just advised for them to take.
  1018. // Maybe lift an advising flag in the mainframe system?
  1019. }

Functions

Namesort descending Description
hook_admin_duplicate_year This hook allows other modules to act when we are using the admin operation of duplicating an entire catalog year's worth of data.
hook_advise_build_screen_elements This hook allows other modules to interact with the AdvisingScreen object adter the build_screen_elements method is called.
hook_alter_student_profile_items This hook is called before displaying the student profile box (which appears at the top of the screen on the profile page, as well as other tabs. If bool_mini is set to TRUE, then it means we are showing an abbreviated display, like on the Degree…
hook_alter_term_id_prior_to_description This hook is called right before retrieving the plain English description for a term_id. It allows modules to change the term_id.
hook_apply_draft_changes Allows modules to execute code when the admin user has chose to "apply draft changes".
hook_clear_cache Allows each module to perform actions when the cache is cleared.
hook_content_alter Similar to hook_form_alter, this function lets other modules alter content which is being rendered through the "render" system.
hook_courselist_find_match_allow_course This hook his called just before returning a Course object from CourseList::find_best_grade_match or find_most_recent_match.
hook_course_load Allows modules to act after a course object has been loaded.
hook_cron This hook is called every time the system cron is run.
hook_degree_plan_load Allows modules to hook in after a degree plan object is created & loaded.
hook_disable This hook will be executed when a module is disabled in the system.
hook_enable This hook will be executed when a module is enabled in the system. It will be executed AFTER hook_install.
hook_exit Allows each module to execute code when the FlightPath page is completely finished.
hook_flightpath_can_assign_course_to_degree_id Is the course allowed to be assigned to the specified degree? Returns TRUE or FALSE
hook_flightpath_can_assign_course_to_group Is the course allowed to be assigned to the specified group? Returns TRUE or FALSE. $group should be a fully formed Group object.
hook_form_alter Alter forms which are created using the Form API
hook_fp_get_student_majors Returns a full listing of the student's majors.
hook_get_user_image_url This accepts a CWID (student_id or faculty_id), and returns back a URL to the user's image, or FALSE if it cannot find one.
hook_group_load Allows modules to act after a group object has been loaded.
hook_init Allows each module to execute code when the module is first loaded.
hook_init_flightpath_degree Allows a module to act on the degree_plan object AFTER being initialized by the FlightPath module.
hook_install This hook will be executed the first time a module is enabled in the system.
hook_menu Allows modules to specify valid URLs in FlightPath, and define what function to call when the user visits that URL.
hook_menu_alter This hook lets us make alterations to menu items before saving them to the database.
hook_menu_handle_replacement_pattern This hook is called by the menu system. It allows each module the chance to replace string patterns in its menu items (defined in hook_menu).
hook_perm This hook defines available permissions for a module. These perms are used with hook_menu() and the function user_has_permission()
hook_save_advising_session_from_post This hook allows modules to perform extra functions just after an advising session is saved by the system.
hook_sidebar_left_links_alter This hook allows a module to modify the links which appear on the left sidebar.
hook_stats_additional_menublocks Used by the stats module, this will ask other modules to return an array of paths suitable for the fp_render_menu_block() function. In other words, the paths should be the **beginning** of the paths of your custom reports or other links which you…
hook_status Reports status information which each module is aware of, visible on admin/config/status.
hook_student_load Allows modules to hook in after a new student object is created.
hook_submit Handle submissions from the Form API
hook_theme_advise_course_row This hook allows another module to alter the way a course row is drawn onto the advising screen.
hook_theme_advise_degree_header_row This hook allows another module to alter the way a "degree header" row is drawn onto the advising screen.
hook_theme_advise_footnote This function allows the user to theme footnotes before they are drawn onto the screen.
hook_theme_advise_group_select_row Similar to hook_theme_advise_course_row. This lets the user theme the "select X hours..." row for a group.
hook_theme_pie_charts Similar to other theme functions, this function will take an array which describes *all* the pie charts, and allow another module to act on them.
hook_translate This function is called by the t() function, and gives modules a chance to intercept a string and change it. Meant primarily for translating to another language, but also good for simple replacements. Used by the Locale module.
hook_uninstall This hook will be executed when a module is "uninstalled" in the system. Once a module is disabled, an "uninstall" link will appear.
hook_update Handle needed database updates when user updates a module.
hook_user_login Perform actions when the user logs in successfully.
hook_user_logout Runs AFTER FlightPath has logged out. Allows modules to add additional functionality. For example, to go to a special page.
hook_user_menu_links_alter This hook allows you to alter the links which appear under the user menu pulldown, in the top-right of the screen.
hook_validate Validates form submissions from the Form API