menu_link_maintain

  1. drupal
    1. 6
    2. 8
    3. 7
Versions
6 – 8 menu_link_maintain($module, $op, $link_path, $link_title)

Insert, update or delete an uncustomized menu link related to a module.

Parameters

$module The name of the module.

$op Operation to perform: insert, update or delete.

$link_path The path this link points to.

$link_title Title of the link to insert or new title to update the link to. Unused for delete.

Return value

The insert op returns the mlid of the new item. Others op return NULL.

Related topics

▾ 3 functions call menu_link_maintain()

aggregator_save_category in modules/aggregator/aggregator.module
Add/edit/delete aggregator categories.
MenuRouterTestCase::testMenuItemHooks in modules/simpletest/tests/menu.test
Test menu maintenance hooks.
MenuRouterTestCase::testMenuLinkMaintain in modules/simpletest/tests/menu.test
Tests for menu_link_maintain().

Code

includes/menu.inc, line 3326

<?php
function menu_link_maintain($module, $op, $link_path, $link_title) {
  switch ($op) {
    case 'insert':
      $menu_link = array(
        'link_title' => $link_title, 
        'link_path' => $link_path, 
        'module' => $module,
      );
      return menu_link_save($menu_link);
      break;
    case 'update':
      $result = db_query("SELECT * FROM {menu_links} WHERE link_path = :link_path AND module = :module AND customized = 0", array(':link_path' => $link_path, ':module' => $module))->fetchAll(PDO::FETCH_ASSOC);
      foreach ($result as $link) {
        $link['link_title'] = $link_title;
        $link['options'] = unserialize($link['options']);
        menu_link_save($link);
      }
      break;
    case 'delete':
      menu_link_delete(NULL, $link_path);
      break;
  }
}
?>