You are here

function _power_menu_get_active_menu_block in Power Menu 7

Same name and namespace in other branches
  1. 6 power_menu.module \_power_menu_get_active_menu_block()

We are trying to figure out which of the blocks is currently active. We need this incase we display multiple menu blocks on the page, that are linked to the same term id, but have a different path. For example:

Menu Block 1

  • Item 1 -> neuigkeiten/1 (and is linked to tid 1)
  • Item 2 -> neuigkeiten/2 (and is linked to tid 2)

Menu Block 2

  • Ding 1 -> news/1 (and is linked to tid 1)
  • Ding 2 -> news/2 (and is linked to tid 2)

If we are now looking at node/4 (which has tid 2) we go into our power_menu table to see which path we have to set active, but there are two paths with a relation to tid 2. We don't know which to take, that's why we have to figure out, which menu-block is currently active on the page we are looking at. If both are active... well, screw you. Only one is going to be active.

File

./power_menu.module, line 189
This module provides some additional menu features. The features are not actually new, but are part of other modules. it's though very cumbersome to creating a new menu item, because one has to go to all the different places to configure these…

Code

function _power_menu_get_active_menu_block() {
  foreach ($result as $block) {

    // Match path if necessary
    if ($block->pages) {
      if ($block->visibility < 2) {
        $path = drupal_get_path_alias($_GET['q']);

        // Compare with the internal and path alias (if any).
        $page_match = drupal_match_path($path, $block->pages);
        if ($path != $_GET['q']) {
          $page_match = $page_match || drupal_match_path($_GET['q'], $block->pages);
        }

        // When $block->visibility has a value of 0, the block is displayed on
        // all pages except those listed in $block->pages. When set to 1, it
        // is displayed only on those pages listed in $block->pages.
        $page_match = !($block->visibility xor $page_match);
      }
      else {
        if (module_exists('php')) {
          $page_match = php_eval($block->pages);
        }
      }
    }
    else {
      $page_match = TRUE;
    }
  }
}