Advertisement
Guest User

Untitled

a guest
Dec 17th, 2018
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.53 KB | None | 0 0
  1. /**
  2.  * Helper function to re-create a menu with links.
  3.  *
  4.  * @param array $links
  5.  *   List of links.
  6.  *
  7.  * @param array $menu
  8.  *   Menu data.
  9.  */
  10. function _my_feature_links_menu($links, $menu) {
  11.  
  12.   $exists = db_query("SELECT title FROM {menu_custom} WHERE menu_name=:menu_name", array(':menu_name' => $menu['menu_name']))->fetchField();
  13.   if (!$exists) {
  14.     menu_save($menu);
  15.   }
  16.  
  17.   $count = 0;
  18.   foreach ($links as $title => $link) {
  19.     $item = array(
  20.       'link_path' => $link,
  21.       'link_title' => $title,
  22.       'menu_name' => $menu['menu_name'],
  23.       'weight' => $count,
  24.     );
  25.     menu_link_save($item);
  26.     $count++;
  27.   }
  28. }
  29.  
  30.  
  31. /**
  32.  * Number Ticket/Issue - description.
  33.  */
  34. function my_feature_install() {
  35.   $news_by_audience = menu_load('menu-news-by-audience');
  36.   $news_utility = menu_load('menu-news-utility-menu');
  37.  
  38.   menu_delete($news_by_audience);
  39.   menu_delete($news_utility);
  40.  
  41.   $links_news_by_audience = array(
  42.     'Students' => 'taxonomy/term/4202',
  43.     'Business & Industry' => 'taxonomy/term/4206',
  44.     'Alumni' => 'taxonomy/term/4204',
  45.     'Visitors & Neighbors' => 'taxonomy/term/4203',
  46.     'Faculty & Staff' => 'taxonomy/term/4205',
  47.   );
  48.  
  49.   $links_news_utility = array(
  50.     'For the Media' => 'http://media.psu.edu/',
  51.     'Contact Us' => 'node/263941',
  52.     'Stay Connected' => 'node/142040',
  53.   );
  54.  
  55.   _my_feature_links_menu($links_news_by_audience, $news_by_audience);
  56.   _my_feature_links_menu($links_news_utility, $news_utility);
  57.  
  58.   features_revert(array('psu_news_header'));
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement