You are here

function menu_position_edit_menu_link in Menu Position 7.2

Same name and namespace in other branches
  1. 6 menu_position.admin.inc \menu_position_edit_menu_link()
  2. 7 menu_position.admin.inc \menu_position_edit_menu_link()

Adds a menu position rule.

Parameters

$rid: ID of the rule needing a menu link.

$mlid: The mlid of the menu link used in the rule.

$plid: The mlid of the parent menu link specified in the rule.

$admin_title: The administrative title of the rule.

Return value

The mlid of the rule's new menu link.

2 calls to menu_position_edit_menu_link()
menu_position_add_menu_link in ./menu_position.admin.inc
Adds a menu position rule.
menu_position_edit_rule in ./menu_position.admin.inc
Edits a menu position rule.

File

./menu_position.admin.inc, line 581
Provides infrequently used functions and hooks for menu_position.

Code

function menu_position_edit_menu_link($rid, $mlid, $plid, $admin_title) {

  // Add a menu link to handle matching pages.
  $item = array(
    'link_path' => 'menu-position/' . $rid,
    'link_title' => $admin_title . ' (menu position rule)',
    'mlid' => $mlid,
    'plid' => $plid,
    'hidden' => 1,
    'module' => 'menu_position',
    'options' => array(
      'alter' => TRUE,
      'attributes' => array(
        'class' => array(
          'menu-position-link',
        ),
      ),
    ),
  );

  // If this is an existing menu link, get the existing weight.
  if ($item['mlid']) {
    $existing_item = db_query("SELECT plid, weight FROM {menu_links} WHERE mlid = :mlid", array(
      ':mlid' => $item['mlid'],
    ))
      ->fetchAssoc();
    $item['weight'] = $existing_item['plid'] == $plid ? $existing_item['weight'] : 0;

    // If the rule has a new parent, update the old parent.
    if ($existing_item['plid'] != $item['plid']) {
      $old_parent = menu_link_load($existing_item['plid']);
      $old_parent['options']['alter'] = FALSE;
      menu_link_save($old_parent);
    }
  }

  // Update the new parent.
  $parent = menu_link_load($item['plid']);
  $parent['options']['alter'] = TRUE;
  menu_link_save($parent);
  return menu_link_save($item);
}