You are here

API.txt in Power Menu 7

Same filename and directory in other branches
  1. 6 API.txt
=============================
 API
=============================

This Modul provides the following hooks for other modules to interact:

hook_power_menu_href
=============================
Let's assume you have the following situation. In your module you define
via hook_menu a path (say, /my_path/%). You implement the callback in 
the following way:

my_path -> display some kind of overview
my_path/23 -> only show the kinds of 23

In your menu you link to my_path/all. So going over the menu to path/all
all is well, your menu item get's activated, but then you go to element
23, my_path/all won't be activated anymore in your menu. Bummer.

my_path/23 is not of a nodetype kind and you can't assign a taxonomy
term to it. But not all hope is lost.

hook_power_menu_href will save you. It is being called on every page 
load and sending you the currently active menu item (which might not
be the one you would like to be activated). You can return a href of
a menu item that should be activated.

Example:

function rapsli_power_menu_href($menu_item) {
  $ar_active = array('my_path' => 'my_path/*');
  foreach ($ar_active as $key => $pattern) {
    if (drupal_match_path($menu_item['href'], $pattern)) {
      return $key;
    }
  }
}

With the array ar_active we defined a pattern and a menu href. So you 
could read this array as followed: If we are on a page with the pattern
my_path/* activate the menu item with the path "my_path".
We loop through the array and if we have a match of our pattern with the
current href, we return the desired href.

That's it.

hook_power_menu_properties
=============================
Define properties on your menu items and use a cool inheritance concept. So
for example lets say you want to display different adds, based on your menu.
But there might be pages with no special adds, resp. they have the same add
as the parent item. For example you have a menu item "sport" that has child
elements "hockey" and "tennis". You want the same adds on all three pages.
So you would set a property on sport, which is then also used by hockey and
tennis. In the adds.inc there is the exxample hook implementation:

function adds_power_menu_properties() {
  return array(
    'adds_skyscraper' => array(
      'file' => 'adds.inc',
      'path' => drupal_get_path('module', 'power_menu') . '/properties',
      'admin_submit' => 'adds_power_menu_admin_submit', //callback when submitting the menu item edit
      'property_name' => 'adds_skyscraper', // name of the property
      'property_load' => 'adds_skyscraper_power_menu_load_property', // callback for loading the property
      'description' => 'adds add, that is being outputted as variable to the page.tpl.php',
      'scope' => 'page', //options: page, block
    ),
    'adds_leaderboard' => array(
      'file' => 'adds.inc',
      'path' => drupal_get_path('module', 'power_menu') . '/properties',
      'admin_submit' => 'adds_power_menu_admin_submit', //callback when submitting the menu item edit
      'property_name' => 'adds_leaderboard', // name of the property
      'property_load' => 'adds_leaderboard_power_menu_load_property', // callback for loading the property
      'description' => 'adds add, that is being outputted as variable to the page.tpl.php',
      'scope' => 'page', //options: page, block
    ),
    'adds_rectangle' => array(
      'file' => 'adds.inc',
      'path' => drupal_get_path('module', 'power_menu') . '/properties',
      'admin_submit' => 'adds_power_menu_admin_submit', //callback when submitting the menu item edit
      'property_name' => 'adds_rectangle', // name of the property
      'property_load' => 'adds_rectangle_power_menu_load_property', // callback for loading the property
      'description' => 'adds add, that is being outputted as variable to the page.tpl.php',
      'scope' => 'block', //options: page, block
      'title' => t('Add'), // optional, only used for block scope
    ),
  );
}

File

API.txt
View source
  1. =============================
  2. API
  3. =============================
  4. This Modul provides the following hooks for other modules to interact:
  5. hook_power_menu_href
  6. =============================
  7. Let's assume you have the following situation. In your module you define
  8. via hook_menu a path (say, /my_path/%). You implement the callback in
  9. the following way:
  10. my_path -> display some kind of overview
  11. my_path/23 -> only show the kinds of 23
  12. In your menu you link to my_path/all. So going over the menu to path/all
  13. all is well, your menu item get's activated, but then you go to element
  14. 23, my_path/all won't be activated anymore in your menu. Bummer.
  15. my_path/23 is not of a nodetype kind and you can't assign a taxonomy
  16. term to it. But not all hope is lost.
  17. hook_power_menu_href will save you. It is being called on every page
  18. load and sending you the currently active menu item (which might not
  19. be the one you would like to be activated). You can return a href of
  20. a menu item that should be activated.
  21. Example:
  22. function rapsli_power_menu_href($menu_item) {
  23. $ar_active = array('my_path' => 'my_path/*');
  24. foreach ($ar_active as $key => $pattern) {
  25. if (drupal_match_path($menu_item['href'], $pattern)) {
  26. return $key;
  27. }
  28. }
  29. }
  30. With the array ar_active we defined a pattern and a menu href. So you
  31. could read this array as followed: If we are on a page with the pattern
  32. my_path/* activate the menu item with the path "my_path".
  33. We loop through the array and if we have a match of our pattern with the
  34. current href, we return the desired href.
  35. That's it.
  36. hook_power_menu_properties
  37. =============================
  38. Define properties on your menu items and use a cool inheritance concept. So
  39. for example lets say you want to display different adds, based on your menu.
  40. But there might be pages with no special adds, resp. they have the same add
  41. as the parent item. For example you have a menu item "sport" that has child
  42. elements "hockey" and "tennis". You want the same adds on all three pages.
  43. So you would set a property on sport, which is then also used by hockey and
  44. tennis. In the adds.inc there is the exxample hook implementation:
  45. function adds_power_menu_properties() {
  46. return array(
  47. 'adds_skyscraper' => array(
  48. 'file' => 'adds.inc',
  49. 'path' => drupal_get_path('module', 'power_menu') . '/properties',
  50. 'admin_submit' => 'adds_power_menu_admin_submit', //callback when submitting the menu item edit
  51. 'property_name' => 'adds_skyscraper', // name of the property
  52. 'property_load' => 'adds_skyscraper_power_menu_load_property', // callback for loading the property
  53. 'description' => 'adds add, that is being outputted as variable to the page.tpl.php',
  54. 'scope' => 'page', //options: page, block
  55. ),
  56. 'adds_leaderboard' => array(
  57. 'file' => 'adds.inc',
  58. 'path' => drupal_get_path('module', 'power_menu') . '/properties',
  59. 'admin_submit' => 'adds_power_menu_admin_submit', //callback when submitting the menu item edit
  60. 'property_name' => 'adds_leaderboard', // name of the property
  61. 'property_load' => 'adds_leaderboard_power_menu_load_property', // callback for loading the property
  62. 'description' => 'adds add, that is being outputted as variable to the page.tpl.php',
  63. 'scope' => 'page', //options: page, block
  64. ),
  65. 'adds_rectangle' => array(
  66. 'file' => 'adds.inc',
  67. 'path' => drupal_get_path('module', 'power_menu') . '/properties',
  68. 'admin_submit' => 'adds_power_menu_admin_submit', //callback when submitting the menu item edit
  69. 'property_name' => 'adds_rectangle', // name of the property
  70. 'property_load' => 'adds_rectangle_power_menu_load_property', // callback for loading the property
  71. 'description' => 'adds add, that is being outputted as variable to the page.tpl.php',
  72. 'scope' => 'block', //options: page, block
  73. 'title' => t('Add'), // optional, only used for block scope
  74. ),
  75. );
  76. }