example_helper.module

example_helper.module - Example module file

This file should be used as an example for how to create a new custom module.

Notice that we start the PHP tag, but do not close it. This makes sure we do not have white space at the end of the file.

Functions & methods

NameDescription
example_helper_display_hello_world_pageDisplay our Hello World page to the user.
example_helper_initImplementation of "hook_init".
example_helper_menuImplementation of hook_menu

File

custom/modules/example_helper/example_helper.module
View source
  1. <?php
  2. /**
  3. * @file
  4. * example_helper.module - Example module file
  5. *
  6. * This file should be used as an example for how to create a new custom module.
  7. *
  8. * Notice that we start the PHP tag, but do not close it. This makes sure we do not
  9. * have white space at the end of the file.
  10. */
  11. /**
  12. * Implementation of "hook_init".
  13. *
  14. * Notice we replace the word "hook" with our module name. This is how
  15. * FlightPath knows to find this function.
  16. *
  17. * It will be run on every page load.
  18. *
  19. * Documentation: http://getflightpath.com/api/flightpath/includes!hook.api.php/function/hook_init/4.x
  20. */
  21. function example_helper_init() {
  22. // Add a message to the screen which all users can see
  23. fp_add_message(t("Example Helper is running."));
  24. // Let's also provide a link to our menu item, created in hook_menu.
  25. // Notice to the use of the "l" function, for "link".
  26. fp_add_message(l("Example Helper's Hello World link", "example-helper/hello-world"));
  27. }
  28. /**
  29. * Implementation of hook_menu
  30. *
  31. * This is a powerful function in FlightPath. We use it to define which "menu" items
  32. * ie, URLs, are valid in FlightPath, and what permissions are required to visit those
  33. * URLs.
  34. *
  35. * After creating new menu items in thos function, you MUST clear the menu cache
  36. * (link in the Admin Console of FlightPath). Otherwise, FP will not be aware of your
  37. * new URLs.
  38. *
  39. * Documentation: http://getflightpath.com/api/flightpath/includes!hook.api.php/function/hook_menu/4.x
  40. */
  41. function example_helper_menu() {
  42. $items = array();
  43. $items["example-helper/hello-world"] = array(
  44. "title" => "Hello World!", // Title of the URL
  45. "page_callback" => "example_helper_display_hello_world_page", // What function to call when the user visits this URL
  46. "access_callback" => TRUE, // set to TRUE if anonymous users may view this page (no permissions required)
  47. "page_settings" => array(
  48. "page_show_title" => TRUE, // must be set to display title at the top of the page.
  49. ),
  50. "type" => MENU_TYPE_CALLBACK, // one of several types of menu items.
  51. );
  52. return $items;
  53. }
  54. /**
  55. * Display our Hello World page to the user.
  56. *
  57. * This is the callback function for our example-helper/hello-world menu item.
  58. * Notice that we will build up our HTML for the page in a varialbe,
  59. * and then RETURN it. We do not attempt to print it out. When we RETURN it,
  60. * FlightPath handles the themeing of the content, which is what we want.
  61. */
  62. function example_helper_display_hello_world_page() {
  63. $rtn = '';
  64. $rtn .= '<b>Hello everyone! This is a test to make sure my menu item is working.</b>
  65. <ul>
  66. <li>Notice we just type straight HTML in this page.</li>
  67. <li>Then, we return our result.</li>
  68. </ul>';
  69. return $rtn;
  70. }