Inserts, updates, enables, disables, or deletes an uncustomized menu link.
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.
integer|null The insert op returns the mlid of the new item. Others op return NULL.
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;
}
}