Skip to content

Instantly share code, notes, and snippets.

@lincoln-chawora
Last active September 4, 2019 16:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lincoln-chawora/b19ca4427ad26905d15d8676b420d2b6 to your computer and use it in GitHub Desktop.
Save lincoln-chawora/b19ca4427ad26905d15d8676b420d2b6 to your computer and use it in GitHub Desktop.
How to update a menu link in drupal 7 using hook n update
/**
* Update we chat link inside menu social.
*/
function YOUR_THEME_main_menu_update_7004() {
$id = db_select('menu_links', 'm')
->fields('m', ['mlid'])
->condition('menu_name', 'menu-social')
->condition('link_title', 'WeChat')
->execute()
->fetchCol();
if (count($id) == 1) {
$item = menu_link_load($id[0]);
$item['options']['attributes']['class'][] = 'qr-link';
menu_link_save($item);
}
else {
throw new DrupalUpdateException('Could not find menu link to update.');
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment