function menu_link_maintain

Inserts, updates, enables, disables, or deletes an uncustomized menu link.

Parameters

string $module: The name of the module that owns the link.

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

string $link_path: The path this link points to.

string $link_title: (optional) Title of the link to insert or new title to update the link to. Unused for delete.

Return value

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

Related topics

4 calls to menu_link_maintain()
aggregator_save_category in drupal/core/modules/aggregator/aggregator.module
Adds/edits/deletes aggregator categories.
RouterTest::testMenuItemHooks in drupal/core/modules/system/lib/Drupal/system/Tests/Menu/RouterTest.php
Test menu maintenance hooks.
RouterTest::testMenuLinkMaintain in drupal/core/modules/system/lib/Drupal/system/Tests/Menu/RouterTest.php
Tests for menu_link_maintain().
standard_install in drupal/core/profiles/standard/standard.install
Implements hook_install().

File

drupal/core/includes/menu.inc, line 3340
API for the Drupal menu system.

Code

function menu_link_maintain($module, $op, $link_path, $link_title = NULL) {
  switch ($op) {
    case 'insert':
      $menu_link = array(
        'link_title' => $link_title,
        'link_path' => $link_path,
        'module' => $module,
      );
      return menu_link_save($menu_link);
    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) {
        $existing = $link;
        if (isset($link_title)) {
          $link['link_title'] = $link_title;
        }
        $link['options'] = unserialize($link['options']);
        menu_link_save($link, $existing);
      }
      break;
    case 'enable':
    case 'disable':
      $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) {
        $existing = $link;
        $link['hidden'] = $op == 'disable' ? 1 : 0;
        $link['customized'] = 1;
        if (isset($link_title)) {
          $link['link_title'] = $link_title;
        }
        $link['options'] = unserialize($link['options']);
        menu_link_save($link, $existing);
      }
      break;
    case 'delete':
      menu_link_delete(NULL, $link_path);
      break;
  }
}