You are here

function menu_position_translated_menu_link_alter in Menu Position 7.2

Same name and namespace in other branches
  1. 7 menu_position.module \menu_position_translated_menu_link_alter()

Implements hook_translated_menu_link_alter().

All of the menu items of menu position rules have their "alter" option set which allows them to be altered with this hook. We "translate" the menu item to have the proper URL and title for the current page.

File

./menu_position.module, line 401
Provides menu links for dynamic positioning of nodes based on configurable rules.

Code

function menu_position_translated_menu_link_alter(&$item, &$map) {

  // Check if the rule's links are configured to be hidden.
  switch (variable_get('menu_position_active_link_display', 'child')) {
    case 'child':
      if ($item['module'] == 'menu_position') {
        $menu_item = menu_position_get_link($item['link_path']);

        // We only alter the link after its replacement has been set.
        if (!empty($menu_item['title'])) {
          $item['title'] = $menu_item['title'];
          $item['href'] = $menu_item['href'];
          $item['hidden'] = 0;
        }
      }
      elseif ($item['mlid'] == menu_position_expand_parent_link()) {
        $item['has_children'] = 1;
      }
      break;
    case 'parent':
      if ($item['mlid'] == menu_position_expand_parent_link()) {
        $item['localized_options']['attributes']['class'][] = 'active';
      }
      break;
  }
}