/[drupal]/contributions/modules/menu_breadcrumb/menu_breadcrumb.module
ViewVC logotype

Contents of /contributions/modules/menu_breadcrumb/menu_breadcrumb.module

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.7 - (show annotations) (download) (as text)
Mon Oct 5 22:01:27 2009 UTC (7 weeks, 3 days ago) by xuriz
Branch: MAIN
CVS Tags: HEAD
Changes since 1.6: +1 -21 lines
File MIME type: text/x-php
#595244 by jweowu: fix misuse of hook_enable() / hook_disable()
1 <?php
2 // $Id: menu_breadcrumb.module,v 1.6 2009/08/30 22:13:21 xuriz Exp $
3 /**
4 * @file
5 * The main file for the menu_breadcrumb module.
6 *
7 * By default, Drupal 6 will use the Navigation menu for the breadcrumb.
8 * This module allows you to use the menu the current page belongs to for
9 * the breadcrumb.
10 *
11 * As an added bonus, it also allows you to append the page title to the
12 * breadcrumb (either as a clickable url or not) and hide the breadcrumb
13 * if it only contains the link to the front page.
14 *
15 * Maintained by: Geoffrey de Vlugt <gdevlugt@gmail.com>
16 */
17
18 /**
19 * Implementation of hook_help().
20 */
21 function menu_breadcrumb_help($path, $arg) {
22 $output = '';
23 switch ($path) {
24 case 'admin/settings/modules#description':
25 $output = t('Allows you to use the menu the current page belongs to for the breadcrumb.');
26 break;
27 case 'admin/settings/menu_breadcrumb':
28 $output = t('<p>By default, Drupal 6 will use the Navigation menu for the breadcrumb. This module allows you to use the menu the current page belongs to for the breadcrumb.</p><p>As an added bonus, it also allows you to append the page title to the breadcrumb (either as a clickable url or not) and hide the breadcrumb if it only contains the link to the front page.</p>');
29 break;
30 }
31
32 return $output;
33 }
34
35 /**
36 * Implementation of hook_menu().
37 */
38 function menu_breadcrumb_menu() {
39 $items = array();
40
41 $items['admin/settings/menu_breadcrumb'] = array(
42 'title' => 'Menu breadcrumb',
43 'description' => 'Configure menu breadcrumb.',
44 'page callback' => 'drupal_get_form',
45 'page arguments' => array('menu_breadcrumb_admin_settings_form'),
46 'access arguments' => array('administer site configuration'),
47 'type' => MENU_NORMAL_ITEM,
48 );
49
50 return $items;
51 }
52
53 /**
54 * Implementation of hook_init().
55 */
56 function menu_breadcrumb_init() {
57 if (variable_get('menu_breadcrumb_determine_menu', 1)) {
58 $menu_list = variable_get('menu_breadcrumb_menus', array('admin_menu', 'devel'));
59 $filter = variable_get('menu_breadcrumb_menus_filter', 'blacklist');
60 $menu_item = menu_get_item();
61 $result = db_query("SELECT mlid, menu_name FROM {menu_links} WHERE link_path = '%s'", $menu_item['href']);
62 while ($menu_link = db_fetch_array($result)) {
63 // @see http://www.php.net/manual/en/function.in-array.php#86695
64 $menu_in_list = in_array($menu_link['menu_name'], $menu_list, TRUE);
65 if ( ( $filter == 'whitelist' && $menu_in_list ) ||
66 ( $filter == 'blacklist' && !$menu_in_list ) ) {
67 menu_set_active_menu_name($menu_link['menu_name']);
68 break;
69 }
70 }
71 }
72
73 $breadcrumb = drupal_get_breadcrumb();
74
75 if (variable_get('menu_breadcrumb_append_node_title', 0) == 1) {
76 if (variable_get('menu_breadcrumb_append_node_url', 0) == 1) {
77 $breadcrumb[] = l(drupal_get_title(), $_GET['q'], array('html' => TRUE,));
78 }
79 else {
80 $breadcrumb[] = drupal_get_title();
81 }
82 }
83
84 if (count($breadcrumb) == 1 && variable_get('menu_breadcrumb_hide_on_single_item', 0)) {
85 $breadcrumb = array();
86 }
87
88 drupal_set_breadcrumb($breadcrumb);
89 }
90
91 /**
92 * Menu breadcrumb admin settings form.
93 *
94 * @return
95 * The settings form used by Menu breadcrumb.
96 */
97 function menu_breadcrumb_admin_settings_form() {
98 $form['menu_breadcrumb_determine_menu'] = array(
99 '#type' => 'checkbox',
100 '#title' => t('Use menu the page belongs to for the breadcrumb.'),
101 '#description' => t('By default, Drupal 6 will use the Navigation menu for the breadcrumb. If you want to use the menu the active page belongs to for the breadcrumb, enable this option.'),
102 '#default_value' => variable_get('menu_breadcrumb_determine_menu', 1),
103 );
104
105 $form['menu_breadcrumb_append_node_title'] = array(
106 '#type' => 'checkbox',
107 '#title' => t('Append page title to breadcrumb'),
108 '#description' => t('Choose whether or not the page title should be included in the breadcrumb.'),
109 '#default_value' => variable_get('menu_breadcrumb_append_node_title', 0),
110 );
111
112 $form['menu_breadcrumb_append_node_url'] = array(
113 '#type' => 'checkbox',
114 '#title' => t('Appended page title as an URL.'),
115 '#description' => t('Choose whether or not the appended page title should be an URL.'),
116 '#default_value' => variable_get('menu_breadcrumb_append_node_url', 0),
117 );
118
119 $form['menu_breadcrumb_hide_on_single_item'] = array(
120 '#type' => 'checkbox',
121 '#title' => t('Hide the breadcrumb if the breadcrumb only contains the link to the front page.'),
122 '#description' => t('Choose whether or not the breadcrumb should be hidden if the breadcrumb only contains a link to the front page (<em>Home</em>.).'),
123 '#default_value' => variable_get('menu_breadcrumb_hide_on_single_item', 0),
124 );
125
126 $include_exclude_description = 'Use this to specify which menus are used to generate breadcrumbs. ' ;
127 $form['include_exclude'] = array(
128 '#type' => 'fieldset',
129 '#title' => t('Include / Exclude Menus'),
130 '#description' => t($include_exclude_description),
131 ) ;
132
133 $form['include_exclude']['menu_breadcrumb_menus_filter'] = array(
134 '#type' => 'radios',
135 '#title' => t('Menu filter'),
136 '#options' => array(
137 'blacklist' => t('Blacklist - Menu items will never be chosen from the menus selected below.'),
138 'whitelist' => t('Whitelist - Menu items will only be chosen from the menus selected below.'),
139 ),
140 '#default_value' => variable_get('menu_breadcrumb_menus_filter', 'blacklist'),
141 );
142
143 $form['include_exclude']['menu_breadcrumb_menus'] = array(
144 '#type' => 'checkboxes',
145 '#title' => t('Menu list'),
146 '#description' => t('Select which menus to apply the blacklist / whitelist to.'),
147 '#options' => drupal_map_assoc(menu_get_names()),
148 '#default_value' => variable_get('menu_breadcrumb_menus', array('admin_menu', 'devel')),
149 );
150
151 return system_settings_form($form);
152 }

  ViewVC Help
Powered by ViewVC 1.1.2