You are here

public function PowerMenuPathHandler::getMenuPathToActivate in Power Menu 7.2

Overrides PowerMenuHandlerInterface::getMenuPathToActivate

See also

PowerMenuHandlerInterface::getMenuPathToActivate()

File

plugins/menu_handlers/PowerMenuPathHandler.class.php, line 82

Class

PowerMenuPathHandler
Implementation of the interface PowerMenuHandlerInterface.

Code

public function getMenuPathToActivate($entity, $type, array $router_item, $alias) {
  global $language;
  $path = NULL;
  $bundles = variable_get('power_menu_path_bundles', array());
  $steps = variable_get('power_menu_path_number', 1);
  $menus = variable_get('power_menu_handlers_menus');

  // Get the bundle name
  list(, , $bundle) = entity_extract_ids($type, $entity);

  // Is path recognition enabled for this entity type and bundle
  if (in_array($type . '|' . $bundle, $bundles)) {
    for ($i = 1; $i <= $steps; $i++) {
      $alias = explode('/', $alias);
      array_pop($alias);

      // Does a parent path exists
      if (count($alias) > 0) {
        $alias = implode('/', $alias);

        // Menu link lookup for given alias
        $query = db_select('url_alias', 'ua');
        $query
          ->leftJoin('menu_links', 'ml', 'ua.source = ml.link_path');
        $path = $query
          ->fields('ml', array(
          'link_path',
        ))
          ->condition('ua.alias', $alias)
          ->condition('ua.language', array(
          $language->language,
          LANGUAGE_NONE,
        ), 'IN')
          ->condition('ml.menu_name', $menus, 'IN')
          ->execute()
          ->fetchField();
        if ($path) {
          break;
        }
      }
      else {
        break;
      }
    }
  }
  return $path;
}