regions_top_nav.module

  1. cis7 sites/all/modules/elmsln_contrib/regions/modules/regions_top_nav/regions_top_nav.module
  2. cle7 sites/all/modules/elmsln_contrib/regions/modules/regions_top_nav/regions_top_nav.module
  3. ecd7 sites/all/modules/elmsln_contrib/regions/modules/regions_top_nav/regions_top_nav.module
  4. elmsmedia7 sites/all/modules/elmsln_contrib/regions/modules/regions_top_nav/regions_top_nav.module
  5. harmony7 sites/all/modules/elmsln_contrib/regions/modules/regions_top_nav/regions_top_nav.module
  6. icor7 sites/all/modules/elmsln_contrib/regions/modules/regions_top_nav/regions_top_nav.module
  7. meedjum_blog7 sites/all/modules/elmsln_contrib/regions/modules/regions_top_nav/regions_top_nav.module
  8. mooc7 sites/all/modules/elmsln_contrib/regions/modules/regions_top_nav/regions_top_nav.module

Add a top nav bar for dropping blocks into.

Functions

Namesort descending Description
regions_top_nav_define_regions Implements hook_define_region().
regions_top_nav_init Implementation of hook_init().
regions_top_nav_map_notification Implementation of hook_map_notification().
regions_top_nav_regions_region_alter Implements hook_regions_region_alter().
regions_top_nav_theme_registry_alter Implements hook_theme_registry_alter().
_regions_top_nav_get_map
_regions_top_nav_output Helper function to position outut for top nav, a static area
_regions_top_nav_render_region Helper function for rendering the blocks in this region
_regions_top_nav_status_messages Helper function to retrieves system messages.
_regions_top_nav_system_path

File

sites/all/modules/elmsln_contrib/regions/modules/regions_top_nav/regions_top_nav.module
View source
  1. <?php
  2. /**
  3. * @file
  4. * Add a top nav bar for dropping blocks into.
  5. */
  6. /**
  7. * Implements hook_define_region().
  8. */
  9. function regions_top_nav_define_regions() {
  10. $region['regions_top_nav'] = array(
  11. 'title' => 'Top nav region',
  12. 'js' => drupal_get_path('module', 'regions_top_nav') . '/regions_top_nav.js',
  13. 'css' => drupal_get_path('module', 'regions_top_nav') . '/regions_top_nav.css',
  14. 'render_callback' => '_regions_top_nav_render_region',
  15. );
  16. return $region;
  17. }
  18. /**
  19. * Helper function for rendering the blocks in this region
  20. */
  21. function _regions_top_nav_render_region($block_html, $block) {
  22. // build a unique key for this block for theming
  23. if (request_path() != 'system/ajax' && strpos(request_path(), 'autocomplete') === FALSE) {
  24. $renderable_block = _block_get_renderable_array(array($block));
  25. return drupal_render($renderable_block);
  26. }
  27. }
  28. /**
  29. * Implementation of hook_init().
  30. */
  31. function regions_top_nav_init() {
  32. $settings = array(
  33. 'regions_top_nav' => array(
  34. 'msg_count' => array(),
  35. 'icon_map' => _regions_top_nav_get_map(),
  36. ),
  37. );
  38. drupal_add_js($settings, 'setting');
  39. }
  40. // helper function to display current system path
  41. function _regions_top_nav_system_path() {
  42. $output = '';
  43. // dig out current menu path based on whats active
  44. $active_menu = menu_get_active_trail();
  45. // pop off the top of the content structure
  46. $active_menu[1] = $active_menu[0];
  47. array_shift($active_menu);
  48. // iterate each menu item and convert to valid breadcrumb
  49. foreach ($active_menu as $menu) {
  50. if (isset($menu['href'])) {
  51. $item = array();
  52. $item['element'] = array(
  53. '#title' => $menu['title'],
  54. '#href' => $menu['href'],
  55. '#localized_options' => $menu['localized_options'],
  56. '#attributes' => array(),
  57. '#below' => FALSE,
  58. );
  59. $output .= theme('menu_link', $item);
  60. }
  61. }
  62. return $output;
  63. }
  64. /**
  65. * Implements hook_theme_registry_alter().
  66. */
  67. function regions_top_nav_theme_registry_alter(&$theme_registry) {
  68. $theme_registry['status_messages']['function'] = '_regions_top_nav_status_messages';
  69. }
  70. /**
  71. * Helper function to retrieves system messages.
  72. */
  73. function _regions_top_nav_status_messages($variables) {
  74. global $user;
  75. $output = '';
  76. // get all messages and unset them for the session
  77. $messages = drupal_get_messages();
  78. // need a separater container for title mapping
  79. $title_messages = $messages;
  80. if (!empty($messages)) {
  81. $content = '';
  82. // get a map of all known values
  83. $map = _regions_top_nav_get_map();
  84. // account for parent items which reduces redundancy in the UI
  85. foreach ($title_messages as $key => $message_group) {
  86. // if this item actually has a parent, move it's status messages in there
  87. if (isset($map[$key]['parent'])) {
  88. // test to see if this item came across itself to merge under, otherwise
  89. if (isset($title_messages[$map[$key]['parent']])) {
  90. $title_messages[$map[$key]['parent']] = array_merge($title_messages[$map[$key]['parent']], $message_group);
  91. }
  92. else {
  93. // this is basically just a push of the value into its parent
  94. $title_messages[$map[$key]['parent']] = $message_group;
  95. }
  96. unset($title_messages[$key]);
  97. }
  98. }
  99. // build out the title bar
  100. $title = '';
  101. foreach ($title_messages as $key => $message_group) {
  102. // see if we have a map, if not use default
  103. if (isset($map[$key])) {
  104. $type = $key;
  105. }
  106. else {
  107. $type = 'default';
  108. }
  109. // if there are multiple messages then place a count indicator
  110. $msg_count = '';
  111. if (count($message_group) > 1) {
  112. $msg_count = '<div class="regions_top_nav_msg_bar_icon_count">'. count($message_group) .'</div>';
  113. }
  114. // block title as icons
  115. $title .= '<div class="regions_top_nav_msg_bar_icon"><a href="#" title="'. $map[$type]['title'] .', click for more details"><img src="'. $map[$type]['bar_icon'] .'" title="'. $map[$type]['title'] .', click for more details" alt="'. $map[$type]['title'] .', click for more details" /></a>'. $msg_count .'</div>';
  116. }
  117. // build out the message array
  118. foreach ($messages as $key => $message_group) {
  119. // see if we have a map, if not use default
  120. if (isset($map[$key])) {
  121. $type = $key;
  122. }
  123. else {
  124. $type = 'default';
  125. }
  126. // loop through as messages are grouped by type
  127. foreach ($message_group as $message) {
  128. // block content area
  129. $content .= '<div class="regions_top_nav_row"><img src="'. $map[$type]['icon'] .'" title="'. $map[$type]['title'] .', click for more details" alt="'. $map[$type]['title'] .', click for more details" class="regions_top_nav_icon"/><div class="regions_top_nav_msg"><div class="regions_top_nav_msg_title">'. $map[$type]['title'] .'</div><div class="regions_top_nav_msg_text">'. $message .'</div></div></div>';
  130. }
  131. }
  132. // add arrow to right side to indicate this can be opened
  133. $title .= '<a href="#" title="Click to see notifications"><img src="'. base_path() . drupal_get_path('module', 'regions_top_nav') .'/images/notifications/arrow_down.png" alt="Click to see notifications" class="regions_top_nav_arrow"/></a>';
  134. // construct the block for display
  135. $output = '<div class="regions_block_title">'. $title .'</div><div class="regions_block_content">'. $content .'</div>';
  136. }
  137. return $output;
  138. }
  139. /**
  140. * Implementation of hook_map_notification().
  141. */
  142. function regions_top_nav_map_notification() {
  143. // provide defaults for drupal
  144. $map = array(
  145. 'default' => array(
  146. 'title' => 'Message',
  147. 'icon' => base_path() . drupal_get_path('module', 'regions_top_nav') .'/images/notifications/default.png',
  148. 'bar_icon' => base_path() . drupal_get_path('module', 'regions_top_nav') .'/images/notifications/default_bar.png',
  149. ),
  150. 'status' => array(
  151. 'title' => 'Status',
  152. 'icon' => base_path() . drupal_get_path('module', 'regions_top_nav') .'/images/notifications/status.png',
  153. 'bar_icon' => base_path() . drupal_get_path('module', 'regions_top_nav') .'/images/notifications/status_bar.png',
  154. ),
  155. 'warning' => array(
  156. 'title' => 'Warning',
  157. 'icon' => base_path() . drupal_get_path('module', 'regions_top_nav') .'/images/notifications/warning.png',
  158. 'bar_icon' => base_path() . drupal_get_path('module', 'regions_top_nav') .'/images/notifications/warning_bar.png',
  159. ),
  160. 'error' => array(
  161. 'title' => 'Error',
  162. 'icon' => base_path() . drupal_get_path('module', 'regions_top_nav') .'/images/notifications/error.png',
  163. 'bar_icon' => base_path() . drupal_get_path('module', 'regions_top_nav') .'/images/notifications/error_bar.png',
  164. ),
  165. );
  166. return $map;
  167. }
  168. // helper function that builds the notifications map
  169. function _regions_top_nav_get_map() {
  170. $map = module_invoke_all('map_notification');
  171. return $map;
  172. }
  173. /**
  174. * Implements hook_regions_region_alter().
  175. */
  176. function regions_top_nav_regions_region_alter(&$region, $region_name) {
  177. // override this region regardless of blocks, its not for blocks
  178. if ($region_name == 'regions_top_nav') {
  179. $new_markup = array(
  180. 'start' => '<div id="' . $region_name . '" class="regions region">',
  181. 'inner' => '<div class="regions_pre_block_container"></div><div class="regions_block_container">',
  182. 'blocks' => _regions_top_nav_output(),
  183. 'inner_end' => '</div><div class="regions_post_block_container"></div>',
  184. 'end' => '</div>',
  185. );
  186. $region = $new_markup;
  187. }
  188. }
  189. /**
  190. * Helper function to position outut for top nav, a static area
  191. */
  192. function _regions_top_nav_output() {
  193. $output = '';
  194. // build system path
  195. $output .= '<div id="regions_top_nav_system_path" class="region_content">'. _regions_top_nav_system_path() .'</div>';
  196. // if annonymous, display a login link
  197. if (user_is_anonymous()) {
  198. $output .= '<div id="regions_top_nav_user_menu" class="region_content">'. l(t('Login'), 'user/login') .'</div>';
  199. }
  200. else {
  201. // wrap name to offset it from the piture
  202. global $user;
  203. $rendername = $user->name;
  204. $output .= '<div id="regions_top_nav_user_menu" class="region_content"><span>'. $user->name .'</span><span>'. l(t('Logout'), 'user/logout') .'</span></div>';
  205. }
  206. $output .= '<div id="regions_top_nav_notifications" class="region_content">'. theme('status_messages') .'</div>';
  207. return $output;
  208. }