You are here

function biblio_menu_links in Bibliography Module 7.2

Modify and add links in various menus

1 call to biblio_menu_links()
biblio_menu in ./biblio.module
Implements hook_menu().

File

./biblio.module, line 928

Code

function biblio_menu_links() {

  // Get all biblio-generated links
  $result = db_select('menu_links', 'm')
    ->fields('m', array(
    'menu_name',
    'mlid',
    'plid',
    'link_path',
  ))
    ->condition('link_path', '%biblio%', 'like')
    ->execute();
  $add_link_exists = FALSE;

  // Menu link ID as specified in menu_links
  $biblio_root_mlid = 0;
  while ($row = $result
    ->fetchObject()) {
    switch ($row->link_path) {

      // if the menu path is for example.com/biblio, and it's in the navigation
      // menu, set the root (parent) link id
      case 'biblio':
        if ($row->menu_name == 'navigation') {
          $biblio_root_mlid = $row->mlid;
        }
        break;
      case 'admin/content/biblio/add':

        // Check if the "Add a new Biblio" link exists, to avoid duplicates
        if ($row->plid == $biblio_root_mlid && $row->menu_name == 'navigation') {
          $add_link_exists = TRUE;
        }
        break;
    }
  }
  if (!$add_link_exists) {

    // Create a link on the navigation menu to add a biblio
    $add_link = array(
      'link_path' => drupal_get_normal_path('admin/content/biblio/add'),
      'menu_name' => 'navigation',
      'plid' => $biblio_root_mlid,
      'link_title' => t('Add a new Biblio'),
    );
    menu_link_save($add_link);
  }
}