Skip to content

Instantly share code, notes, and snippets.

@davereid
Created July 15, 2014 14:28
Show Gist options
  • Save davereid/5344f3d1e6b9e3e3e1e7 to your computer and use it in GitHub Desktop.
Save davereid/5344f3d1e6b9e3e3e1e7 to your computer and use it in GitHub Desktop.
<?php
function menu_children_alphabetical_reorder($plid) {
if ($children = db_query("SELECT mlid, link_title FROM {menu_links} WHERE plid = :plid", array(':plid' => $mlid))->fetchAllAssoc()) {
natcasesort($children);
$weight = 0;
foreach (array_keys($children) as $mlid) {
db_update('menu_links')
->fields(array('weight' => $weight++))
->condition('mlid' => $mlid)
->execute();
}
}
}
function menu_children_alphabetical_menu_link_insert($link) {
if ($link['plid'] == 500) {
menu_children_alphabetical_reorder($link['plid']);
}
}
function menu_children_alphabetical_menu_link_update($link) {
if ($link['plid'] == 500) {
menu_children_alphabetical_reorder($link['plid']);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment