Created
July 15, 2014 14:28
-
-
Save davereid/5344f3d1e6b9e3e3e1e7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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