You are here

function _groupmenu_get_group_menu_link in Group Menu 7

Get the primary group menu link for a group.

Parameters

Group $group: A Group to get the primary menu link for.

Return value

array A menu link array

1 call to _groupmenu_get_group_menu_link()
groupmenu_form_group_form_alter in ./groupmenu.module
Implements hook_form_FORM_ID_alter().

File

./groupmenu.module, line 917
Integrates menu with Group.

Code

function _groupmenu_get_group_menu_link(Group $group) {
  $menu_name = '';
  if (empty($group->menu)) {
    $item = array();
    if (isset($group->gid)) {
      $mlid = FALSE;
      $type_menus = array();
      $menus = groupmenu_get_group_menus(array(
        $group->gid,
      ));

      // Check all allowed menus if a link does not exist in the default menu.
      if (!empty($menus)) {
        foreach ($menus as $menu) {
          $type_menus[] = $menu['menu_name'];
        }
        $menu_name = $type_menus[0];
        $mlid = db_query_range("SELECT mlid FROM {menu_links} WHERE link_path = :path AND module = 'menu' AND menu_name IN (:type_menus) ORDER BY mlid ASC", 0, 1, array(
          ':path' => 'group/' . $group->gid,
          ':type_menus' => array_values($type_menus),
        ))
          ->fetchField();
      }
      if ($mlid) {
        $item = menu_link_load($mlid);
      }
    }

    // Set default values.
    $item = $item + array(
      'link_title' => '',
      'mlid' => 0,
      'plid' => 0,
      'menu_name' => $menu_name,
      'weight' => 0,
      'options' => array(),
      'module' => 'menu',
      'expanded' => 0,
      'hidden' => 0,
      'has_children' => 0,
      'customized' => 0,
    );
  }

  // Find the depth limit for the parent select.
  if (!isset($item['parent_depth_limit'])) {
    $item['parent_depth_limit'] = _menu_parent_depth_limit($item);
  }
  return $item;
}