Projet

Général

Profil

Révision 6d8023f2

Ajouté par Assos Assos il y a plus de 5 ans

Weekly update of contrib modules

Voir les différences:

drupal7/sites/all/modules/taxonomy_menu/README.txt
187 187
 when clicking on the menu items. It produces nice breadcrumbs and page titles (remember to set 
188 188
 the titles for the arguments in views as described) - and it always displays descendants.
189 189
 The only module that supports the saving of a whole term lineage when selecting a deep level 
190
 item seems to be HIERACHICAL SELECT. See chapter INTEGRATION WITH OTHER MODULES
190
 item seems to be HIERARCHICAL SELECT. See chapter INTEGRATION WITH OTHER MODULES
191 191
 
192 192
INTEGRATION WITH OTHER MODULES
193 193
==============================
......
205 205
It is a nice and very helpful module to link taxonomy terms to nodes. 
206 206
Taxonomy Menu does not interface with the content taxonomy tables, so be sure to enable the option 
207 207
"Save values additionally to the core taxonomy system (into the 'term_node' table)" 
208
otherwise the related taxonomy terms will not be accessable for Taxonomy Menu.
208
otherwise the related taxonomy terms will not be accessible for Taxonomy Menu.
209 209
(http://drupal.org/project/content_taxonomy)
210 210
 
211 211
HIERARCHICAL SELECT with submodule HS_TAXONOMY
......
241 241
================
242 242
 * Taxonomy Menu does not handle the menu call backs. It only creates the links to the menus.
243 243
   This means that everythign that is displayed on the page (including title, content, breadcrumbs, etc)
244
   are not controled by Taxonony Menu.
244
   are not controlled by Taxonony Menu.
245 245
 * The router item must be created before Taxonomy Menu creates the links.  Failure to so so 
246 246
   will cause the menu items to not be created.
247 247
 * Router items can be created by either a view or another modules hook_menu.
drupal7/sites/all/modules/taxonomy_menu/UPGRADE.txt
1
TAXONOMY MENU
2
=============
3

  
4
Upgrading from 6.1 => 6.2
5
=========================
6
1. Copy new version to sites/all/modules/taxonomy_menu
7
2. Run update.php
8

  
9
If that doesn't work then follow:
10
1. Disable the module at admin/build/modules
11
2. Uninstall the module at admin/build/modules/uninstall
12
3. Copy new version to sites/all/modules/taxonomy_menu
13
4. Enable the new version at admin/build/modules
14

  
15
See README.TXT for configuration options.
16

  
17
The best method is to treat this upgrade as a new module.
18
The setting of the previous version will not be upgraded.
drupal7/sites/all/modules/taxonomy_menu/taxonomy_menu.batch.inc
6 6
 */
7 7

  
8 8
/**
9
 * The $batch can include the following values. Only 'operations'
10
 * and 'finished' are required, all others will be set to default values.
11
 *
12
 * @param operations
13
 *   An array of callbacks and arguments for the callbacks.
14
 *   There can be one callback called one time, one callback
15
 *   called repeatedly with different arguments, different
16
 *   callbacks with the same arguments, one callback with no
17
 *   arguments, etc.
18
 *
19
 * @param finished
20
 *   A callback to be used when the batch finishes.
21
 *
22
 * @param title
23
 *   A title to be displayed to the end user when the batch starts.
24
 *
25
 * @param init_message
26
 *   An initial message to be displayed to the end user when the batch starts.
27
 *
28
 * @param progress_message
29
 *   A progress message for the end user. Placeholders are available.
30
 *   Placeholders note the progression by operation, i.e. if there are
31
 *   2 operations, the message will look like:
32
 *    'Processed 1 out of 2.'
33
 *    'Processed 2 out of 2.'
34
 *   Placeholders include:
35
 *     @current, @remaining, @total and @percentage
36
 *
37
 * @param error_message
38
 *   The error message that will be displayed to the end user if the batch
39
 *   fails.
9
 *Starts a batch operation.
40 10
 *
11
 * @param int $vid
12
 *   Vocabulary ID.
41 13
 */
42 14
function _taxonomy_menu_insert_link_items_batch($vid) {
43
  $terms = taxonomy_get_tree($vid, 0, NULL, TRUE);
15
  $depth = variable_get(_taxonomy_menu_build_variable('max_depth', $vid), 0);
16
  if ($depth == 0) {
17
    $depth = NULL;
18
  }
19
  $terms = taxonomy_get_tree($vid, 0, $depth, TRUE);
44 20
  $menu_name = variable_get(_taxonomy_menu_build_variable('vocab_menu', $vid), FALSE);
45 21

  
46 22
  $batch = array(
23
    // An array of callbacks and arguments for the callbacks.
47 24
    'operations' => array(
48 25
      array('_taxonomy_menu_insert_link_items_process', array($terms, $menu_name)),
49 26
    ),
27
    // A callback to be used when the batch finishes.
50 28
    'finished' => '_taxonomy_menu_insert_link_items_success',
29
    // A title to be displayed to the end user when the batch starts.
51 30
    'title' => t('Rebuilding Taxonomy Menu'),
31
    // An initial message to be displayed to the end user when the batch starts.
52 32
    'init_message' => t('The menu items have been deleted, and are about to be regenerated.'),
33
    // A progress message for the end user. Placeholders are available.
34
    // Placeholders include: @current, @remaining, @total and @percentage
53 35
    'progress_message' => t('Import progress: Completed @current of @total stages.'),
54
    'redirect' => 'admin/structure/taxonomy',
36
    // The message that will be displayed to the end user if the batch fails.
55 37
    'error_message' => t('The Taxonomy Menu rebuild process encountered an error.'),
38
    'redirect' => 'admin/structure/taxonomy',
56 39
  );
57 40
  batch_set($batch);
58 41
  batch_process();
59 42
}
60 43

  
61

  
62
/*
63
 * Insert 10 menu link items
44
/**
45
 * Batch operation callback function: inserts 10 menu link items.
46
 *
47
 * @param array $terms
48
 *   Taxonomy terms as from taxonomy_get_tree().
49
 * @param string $menu_name
50
 *   Setting for the menu item name assigned to the vocabulary.
51
 * @param array $context
52
 *   Batch context array.
53
 *
54
 * @see _taxonomy_menu_insert_link_items_batch().
64 55
 */
65 56
function _taxonomy_menu_insert_link_items_process($terms, $menu_name, &$context) {
66 57
  _taxonomy_menu_batch_init_context($context, $start, $end, 10);
......
79 70

  
80 71

  
81 72

  
82
/*
83
 * Set a message stating the menu has been updated
73
/**
74
 * Batch finished callback: sets a message stating the menu has been updated.
75
 *
76
 * @see _taxonomy_menu_insert_link_items_batch().
84 77
 */
85 78
function _taxonomy_menu_insert_link_items_success() {
86 79
  // TODO state menu name here.
87 80
  drupal_set_message(t('The Taxonomy Menu has been updated.'));
88 81
}
89 82

  
90
/*
91
 * Initialise the batch context
92
 * @param array $context Batch context array.
93
 * @param int $start The item to start on in this pass
94
 * @param int $end The end item of this pass
95
 * @param int $items The number of items to process in this pass
83
/**
84
 * Initialise the batch context.
85
 *
86
 * @param array $context
87
 *   Batch context array.
88
 * @param int $start
89
 *   The item to start on in this pass.
90
 * @param int $end
91
 *   The end item of this pass.
92
 * @param int $items
93
 *   The number of items to process in this pass.
96 94
 */
97 95
function _taxonomy_menu_batch_init_context(&$context, &$start, &$end, $items) {
98 96
  // Initialize sandbox the first time through.
......
104 102
  $end = $start + $items;
105 103
}
106 104

  
107

  
108
/*
105
/**
109 106
 * Update the batch context
110 107
 *
111
 * @param array $context Batch context array.
112
 * @param int $end The end point of the most recent pass
113
 * @param int $total The total number of items to process in this batch
114
 * @param str $msg Message for the progress bar
108
 * @param array $context
109
 *   Batch context array.
110
 * @param int $end
111
 *   The end point of the most recent pass.
112
 * @param int $total
113
 *   The total number of items to process in this batch.
114
 * @param str $msg
115
 *   Message for the progress bar.
116
 * @see _taxonomy_menu_insert_link_items_process().
115 117
 */
116 118
function _taxonomy_menu_batch_update_context(&$context, $end, $total, $msg) {
117
  //Update context array
118 119
  if ($end > $total) {
119 120
    $context['finished'] = 1;
120 121
    return;
drupal7/sites/all/modules/taxonomy_menu/taxonomy_menu.database.inc
6 6
 * Database functions
7 7
 */
8 8

  
9
 /**
10
 *  helper function to insert a menu item
9
/**
10
 * Inserts a menu item.
11 11
 *
12
 * @param $mlid
13
 * @param $tid
14
 * @param $vid
12
 * @param int $mlid
13
 *   Menu link ID.
14
 * @param int $tid
15
 *   Taxonomy term ID.
16
 * @param int $vid
17
 *   Vocabulary ID.
15 18
 */
16 19
function _taxonomy_menu_insert_menu_item($mlid, $tid, $vid) {
17 20
  $fields = array(
......
23 26
}
24 27

  
25 28
/**
26
 * Return the corresponding menu link id.
29
 * Returns the corresponding menu link id.
27 30
 *
28
 * @param $tid
29
 *   the term's id
31
 * @param int $tid
32
 *   Taxonomy term ID.
33
 * @param int $vid
34
 *   Vocabulary ID.
35
 * @return int
36
 *   Menu link ID for that taxonomy term.
30 37
 */
31 38
function _taxonomy_menu_get_mlid($tid, $vid) {
32 39
  $where = array(
......
37 44
}
38 45

  
39 46
/**
40
 * Retrieve the term / menu relations for a vocab.
47
 * Retrieves the term / menu relations for a vocab.
41 48
 *
42 49
 * @param $vid
43
 *   vocabulary's id
44
 * @return
45
 *   array(tid => mlid)
50
 *   Vocabulary ID.
51
 *
52
 * @return array
53
 *   Relations to menu link ID as an array keyed by taxonomy term ID.
54
 *     array(tid => mlid)
46 55
 */
47 56
function _taxonomy_menu_get_menu_items($vid) {
48

  
49
  $result = db_query('SELECT tid, mlid FROM {taxonomy_menu} WHERE vid = :vid', array(':vid' => $vid));
50
  $menu_items = array();
51
  $menu_items = $result->fetchAllKeyed();
52
  return $menu_items;
57
  return db_query('SELECT tid, mlid FROM {taxonomy_menu} WHERE vid = :vid', array(':vid' => $vid))->fetchAllKeyed();
53 58
}
54 59

  
55
 /**
56
  * Delete all links associated with this vocab from both the taxonomy_menu
57
  * table and the menu_link table.
58
  *
59
  * @param $vid
60
  *   vocabulary's id
61
  */
60
/**
61
 * Deletes all links associated with this vocab from both the taxonomy_menu
62
 * table and the menu_link table.
63
 *
64
 * @param int $vid
65
 *   Vocabulary ID.
66
 */
62 67
function _taxonomy_menu_delete_all($vid) {
63 68
  $menu_terms = _taxonomy_menu_get_menu_items($vid);
64 69
  if (!empty($menu_terms)) {
......
74 79
}
75 80

  
76 81
/**
77
 * Get an array of the tid's related to the node
82
 * Gets an array of the tid's related to the node
83
 *
84
 * @param object $node
85
 *   Node object.
78 86
 *
79
 * @param $node
80
 * @return array of tids
87
 * @return array
88
 *   Array of taxonomy term IDs.
81 89
 */
82 90
function _taxonomy_menu_get_node_terms($node) {
83 91
  // Get the taxonomy fields.
......
89 97
    if (isset($node->$field_name)) {
90 98
      $tid_field = $node->$field_name;
91 99
      // Loop through all the languages.
92

  
93 100
      foreach ($tid_field as $tid_field_languages) {
94 101
        // Loop through all the tids
95

  
96 102
        foreach ($tid_field_languages as $tid) {
97 103
          $tids[] = $tid['tid'];
98 104
        }
......
103 109
}
104 110

  
105 111
/**
106
 * Get an array of the tid's from the parent
112
 * Gets the parent tids for a taxonomy term.
107 113
 *
108
 * @param $tid
109
 * @return array of tid
114
 * @param int $tid
115
 *   Taxonomy term ID.
116
 *
117
 * @return array
118
 *   Array of taxonomy term IDs.
110 119
 */
111 120
function _taxonomy_menu_get_parents($tid) {
112 121
  $output = array();
......
118 127
}
119 128

  
120 129
/**
121
  * Delete all rows from {taxomony_menu} associated with this tid
122
  *
123
  * @param $vid
124
  * @param $tid
125
  */
130
 * Deletes all rows from {taxomony_menu} associated with this tid
131
 *
132
 * @param $vid
133
 * @param $tid
134
 * @param int $vid
135
 *   Vocabulary ID.
136
 * @param int $tid
137
 *   Taxonomy term ID.
138
 */
126 139
function _taxonomy_menu_delete_item($vid, $tid) {
127 140
  $and = db_and()->condition('vid', $vid)->condition('tid', $tid);
128 141
  db_delete('taxonomy_menu')->condition($and)->execute();
129 142
}
130 143

  
131 144
/**
132
 * Get all of the tid for a given vid
145
 * Gets all taxonomy terms for a given vocabulary.
133 146
 *
134
 * @param $vid
135
 * @return array of $tid
147
 * @param int $vid
148
 *   Vocabulary ID.
149
 *
150
 * @return array
151
 *   Array of taxonomy term IDs.
136 152
 */
137 153
function _taxonomy_menu_get_terms($vid) {
138 154
  $result = db_select('taxonomy_term_data', 'td')
......
143 159
}
144 160

  
145 161
/**
146
 * @TODO Needs Updating since terms are related via node fields
162
 * Gets the count of nodes for each term (without children).
147 163
 *
148
 * used to get the count without children
164
 * @param int $tid
165
 *   Taxonomy term ID.
149 166
 *
150
 * @param $tid
167
 * @return int
168
 *   Count of nodes that reference the term.
169
 *
170
 * @todo Needs updating since terms are related via fields now.
151 171
 */
152 172
function _taxonomy_menu_term_count($tid) {
153 173
  $result = db_select('taxonomy_index', 'tn');
......
160 180
}
161 181

  
162 182
/**
163
 * Get tid for a given mlid
183
 * Gets tid for a given mlid.
164 184
 *
165
 * @param $mlid
166
 * @return $tid
185
 * @param int $mlid
186
 *   Menu link ID.
187
 *
188
 * @return int $tid
189
 *   Taxonomy term ID.
167 190
 */
168 191
function _taxonomy_menu_get_tid($mlid) {
169
  $where = array(
170
    ':mlid' => $mlid,
171
  );
172
  return db_query('SELECT tid FROM {taxonomy_menu} WHERE mlid = :mlid', $where)->fetchField();
192
  return db_query('SELECT tid FROM {taxonomy_menu} WHERE mlid = :mlid', array(':mlid' => $mlid))->fetchField();
173 193
}
174 194

  
175 195
/**
176
 * Get vid, tid for a given mlid
196
 * Gets the vocabulary ID and taxonomy term ID for a given menu link ID.
197
 *
198
 * @param int $mlid
199
 *   Menu link ID.
177 200
 *
178
 * @param $mlid
179
 * @return array of vid, tid
201
 * @return array
202
 *   array(vid, tid)
180 203
 */
181 204
function _taxonomy_menu_get_item($mlid) {
182 205
  $result = db_select('taxonomy_menu', 'tm')
183 206
    ->condition('mlid', $mlid, '=')
184 207
    ->fields('tm', array('tid', 'vid'))
185 208
    ->execute();
209

  
186 210
  return $result->fetch();
187 211
}
188 212

  
189 213
/**
190
 * Get the vocabulary for a tid
191
 * @param $tid array of tids
214
 * Gets the vocabulary for a taxonomy term ID.
215
 *
216
 * @param array $tids
217
 *   Taxonomy term IDs.
218
 *
192 219
 * @return $vid
220
 *   Vocabulary ID.
193 221
 */
194 222
function _taxonomy_menu_get_vid_by_tid($tids) {
195 223
  if ($tids) {
......
198 226
      ->fields('term_data', array('vid'))
199 227
      ->distinct()
200 228
      ->execute();
201
    $vids = array();
202 229
    return $result->fetchAllAssoc('vid');
203 230
  }
204 231
}
205

  
206
/**
207
 * Options functions
208
 */
drupal7/sites/all/modules/taxonomy_menu/taxonomy_menu.info
1
core          = "7.x"
1
name = Taxonomy menu
2
description = Adds links to taxonomy terms into a menu.
3
core = 7.x
4

  
2 5
dependencies[] = taxonomy
3 6
dependencies[] = menu
4
description   = "Adds links to taxonomy terms to a menu."
5
name          = "Taxonomy menu"
6
package       = Taxonomy menu
7
files[] = taxonomy_menu.batch.inc
8
files[] = taxonomy_menu.database.inc
9
files[] = taxonomy_menu.module
7

  
10 8
files[] = taxonomy_menu.test
11
files[] = taxonomy_menu.install
12 9

  
13
; Information added by Drupal.org packaging script on 2014-04-01
14
version = "7.x-1.5"
10
; Information added by Drupal.org packaging script on 2018-12-22
11
version = "7.x-1.6"
15 12
core = "7.x"
16 13
project = "taxonomy_menu"
17
datestamp = "1396359247"
18

  
14
datestamp = "1545492784"
drupal7/sites/all/modules/taxonomy_menu/taxonomy_menu.install
9 9
 * Implements hook_uninstall().
10 10
 */
11 11
function taxonomy_menu_uninstall() {
12

  
13
  //remove menu items
12
  // Remove menu items.
14 13
  db_delete('menu_links')->condition('module', 'taxonomy_menu', '=')->execute();
15 14

  
16
  //rebuild the menus
15
  // Rebuild the menus.
17 16
  variable_set('menu_rebuild_needed', TRUE);
18 17

  
19
  // Delete variables
20
  $query = db_select('variable', 'v')->fields('v')->execute();
18
  // Gets array of more specific variables set by Taxonomy Menu module.
19
  // This prevents known issue https://www.drupal.org/node/1966684
20
  // where uninstalling Taxonomy Menu will delete variables related
21
  // to the Taxonomy Menu Block module.
22
  $variable_suffixes = array(
23
    'vocab_menu',
24
    'vocab_parent',
25
    'voc_item',
26
    'display_num',
27
    'hide_empty_terms',
28
    'expanded',
29
    'rebuild',
30
    'path',
31
    'menu_end_all',
32
    'display_descendants',
33
    'voc_name',
34
    'sync',
35
    'end_all',
36
    'flat',
37
    'max_depth',
38
    'term_item_description',
39
  );
40

  
41
  // Delete variables.
42
  $query = db_select('variable', 'v')
43
           ->fields('v', array('name', 'value'))
44
           ->condition('name', '%' . db_like('taxonomy_menu') . '%', 'LIKE')
45
           ->execute();
21 46
  $variables = $query->fetchAll();
22 47
  foreach ($variables as $variable) {
23
    if (strpos($variable->name, 'taxonomy_menu') !== FALSE) {
24
      variable_del($variable->name);
48
    // Add check to make sure we only delete variables for Taxonomy Menu,
49
    // not variables for Taxonomy Menu Block.
50
    foreach ($variable_suffixes as $suffix) {
51
      $taxonomy_menu_variable_name = 'taxonomy_menu_' . $suffix;
52
      if (strpos($variable->name, $taxonomy_menu_variable_name) !== FALSE) {
53
        variable_del($variable->name);
54
      }
25 55
    }
26 56
  }
27 57
}
28 58

  
29
/**
30
 * Implements hook_install().
31
 */
32
function taxonomy_menu_install() {
33
}
34

  
35 59
/**
36 60
 * Implements hook_schema().
37 61
 */
38 62
function taxonomy_menu_schema() {
39

  
40 63
  $schema['taxonomy_menu'] = array(
41 64
    'description' => 'Links a taxonomy term to a menu item.',
42 65
    'fields' => array(
drupal7/sites/all/modules/taxonomy_menu/taxonomy_menu.module
2 2

  
3 3
/**
4 4
 * @file
5
 * It generates menu links for all selected taxonomy terms
5
 * Adds links to taxonomy terms into a menu.
6 6
 */
7 7

  
8
//include the database layer
9
require_once(DRUPAL_ROOT . '/' . drupal_get_path('module', 'taxonomy_menu') . '/taxonomy_menu.database.inc');
8
// Include the database layer.
9
module_load_include('inc', 'taxonomy_menu', 'taxonomy_menu.database');
10 10

  
11
//include the batch functions
12
require_once(DRUPAL_ROOT . '/' . drupal_get_path('module', 'taxonomy_menu') . '/taxonomy_menu.batch.inc');
11
// Include the batch functions.
12
module_load_include('inc', 'taxonomy_menu', 'taxonomy_menu.batch');
13

  
14
/**
15
 * Implements hook_help().
16
 */
17
function taxonomy_menu_help($path, $arg) {
18
  switch ($path) {
19
    case 'admin/help#taxonomy_menu':
20
      $output = '';
21
      $output .= '<p>' . t('The Taxonomy Menu module transforms your taxonomy vocabularies into menus.') . '</p>';
22
      $output .= '<p>' . t('For more information, please visit the official <a href="@url">project page</a> on Drupal.org.', array('@url' => 'https://www.drupal.org/project/taxonomy_menu')) . '</p>';
23
      return $output;
24
  }
25
}
13 26

  
14 27
/**
15 28
 * Implements hook_form_alter().
......
19 32
 */
20 33
function taxonomy_menu_form_alter(&$form, &$form_state, $form_id) {
21 34
  if ($form_id == 'taxonomy_form_vocabulary') {
22
    // do not alter on deletion
35
    // Do not alter on deletion.
23 36
    if (isset($form_state['confirm_delete']) && isset($form_state['values']['vid'])) {
24 37
      return;
25 38
    }
......
61 74
      '#title' => t('Menu location'),
62 75
      '#default_value' => $default,
63 76
      '#options' => $menu_items,
64
      '#description' => t('The menu and parent under which to insert taxonomy menu items.'),
77
      '#description' => t('Taxonomy menu items will be inserted below the item selected here.'),
65 78
      '#attributes' => array('class' => array('menu-title-select')),
66 79
    );
67 80

  
......
73 86
      '#description' => t('The path will be taxonomy/term/tid if <em>Default</em> has been selected.<br />The menu path will be passed through drupal_get_path_alias() function so all aliases will be applied.'),
74 87
    );
75 88

  
76
    //get taxonomy menu form options
89
    // Get taxonomy menu form options.
77 90
    if (isset($form['vid']) && $form['vid']['#value']) {
78 91
      $vid = $form['vid']['#value'];
79 92
    }
......
82 95
    }
83 96
    $form['taxonomy_menu']['options'] = _taxonomy_menu_create_options($vid);
84 97

  
85
    //rebuild the menu
98
    // Rebuild the menu.
86 99
    $form['taxonomy_menu']['options']['rebuild'] = array(
87 100
      '#type' => 'checkbox',
88
      '#title' => t('Select to rebuild the menu on submit.'),
101
      '#title' => t('Rebuild the menu on submit'),
89 102
      '#default_value' => 0,
90 103
      '#weight' => 20,
91
      '#description' => t('Rebuild the menu on submit. <strong>Warning</strong>: This will delete then re-create all of the menu items. Only use this option if you are experiencing issues like missing menu items or other inconsistencies.'),
104
      '#description' => t('<strong>Warning</strong>: This will delete then re-create all of the menu items. Only use this option if you are experiencing issues like missing menu items or other inconsistencies.'),
92 105
    );
93
    // move the buttons to the bottom of the form
106
    // Move the buttons to the bottom of the form.
94 107
    $form['submit']['#weight'] = 49;
95 108
    $form['delete']['#weight'] = 50;
96 109

  
97
    // add an extra submit handler to save these settings
110
    // Add an extra submit handler to save these settings.
98 111
    $form['#submit'][] = 'taxonomy_menu_vocab_submit';
99 112

  
100 113
  }
101 114
  elseif ($form_id == "taxonomy_overview_terms") {
102
    // add an extra submit handler to sync the rearranged terms with menu
115
    // Add an extra submit handler to sync the rearranged terms with menu.
103 116
    // @ TODO: using hook_taxonomy_vocabulary_update is nicer then callback,
104
    // but gives less info and does not always fire.
117
    // But gives less info and does not always fire.
105 118
    $form['#submit'][] = 'taxonomy_menu_overview_submit';
106 119
  }
107 120
}
......
117 130
  $changed = FALSE;
118 131

  
119 132
  if (is_numeric($form_state['values']['taxonomy_menu']['vocab_parent'])) {
120
    // Menu location has been set to disabled, don't want to throw notices
133
    // Menu location has been set to disabled, don't want to throw notices.
121 134
    $form_state['values']['taxonomy_menu']['vocab_parent'] = '0:0';
122 135
  }
123 136

  
124 137
  // Split the menu location into menu name and menu item id.
125 138
  list($vocab_parent['vocab_menu'], $vocab_parent['vocab_parent']) = explode(':', $form_state['values']['taxonomy_menu']['vocab_parent']);
126 139

  
127
  // Init flag variables to avoid notices if changes haven't happened
140
  // Init flag variables to avoid notices if changes haven't happened.
128 141
  $changed_menu = FALSE;
129 142
  $change_vocab_item = FALSE;
130 143
  $changed_path = FALSE;
131 144

  
132
  // Set the menu name and check for changes
145
  // Set the menu name and check for changes.
133 146
  $variable_name = _taxonomy_menu_build_variable('vocab_menu', $vid);
134 147
  if (_taxonomy_menu_check_variable($variable_name, $vocab_parent['vocab_menu'])) {
135 148
    $changed_menu = TRUE;
136 149
  }
137 150
  variable_set($variable_name, $vocab_parent['vocab_menu']);
138 151

  
139
  // Set the menu parent item and check for changes
152
  // Set the menu parent item and check for changes.
140 153
  $variable_name = _taxonomy_menu_build_variable('vocab_parent', $vid);
141 154
  if (_taxonomy_menu_check_variable($variable_name, $vocab_parent['vocab_parent'])) {
142 155
    $changed_menu = TRUE;
143 156
  }
144 157
  variable_set($variable_name, $vocab_parent['vocab_parent']);
145 158

  
146
  // Set the path and check for changes
159
  // Set the path and check for changes.
147 160
  $variable_name = _taxonomy_menu_build_variable('path', $vid);
148 161
  if (_taxonomy_menu_check_variable($variable_name, $form_state['values']['taxonomy_menu']['path'])) {
149 162
    $changed_path = TRUE;
......
154 167
    // Create the variable name
155 168
    $variable_name = _taxonomy_menu_build_variable($key, $vid);
156 169

  
157
    // Check to see if the vocab enable options has changed
170
    // Check to see if the vocab enable options has changed.
158 171
    if ($key == 'voc_item') {
159 172
      if (_taxonomy_menu_check_variable($variable_name, $value)) {
160 173
        $change_vocab_item = TRUE;
161 174
      }
162 175
    }
163 176

  
164
    // If $changed is alreayd set to true, then don't bother checking any others.
177
    // If $changed is already set to true, then don't bother checking any others.
165 178
    if (!$changed) {
166 179
      // Check to see if the variable has changed.
167 180
      if (_taxonomy_menu_check_variable($variable_name, $value)) {
......
190 203
    // Only send a message if one has been created.
191 204
    if (isset($message) && $message) {
192 205
      // $message is sanitized coming out of its source function,
193
      // no need to reclean it here
206
      // No need to reclean it here.
194 207
      drupal_set_message($message, 'status');
195 208
    }
196 209
  }
197 210
}
198 211

  
199 212
/**
200
 * Submit handler, reacting on form ID: taxonomy_overview_terms
213
 * Submit handler, reacting on form ID: taxonomy_overview_terms.
201 214
 */
202 215
function taxonomy_menu_overview_submit(&$form, &$form_state) {
203 216
  // Only sync if taxonomy_menu is enabled for this vocab and the 'sync'
......
215 228
    $vid = $form['#vocabulary']->vid;
216 229
  }
217 230
  elseif ($form_state['rebuild'] == TRUE && isset($form['#vocabulary']->vid) ) {
218
    // Try to catch the 'Reset to alphabetical' button
231
    // Try to catch the 'Reset to alphabetical' button.
219 232
    $vid = NULL;
220 233
  }
221 234
  elseif ($form_state['rebuild'] == FALSE && isset($form['vid']['#value']) ) {
......
236 249

  
237 250
      // Report status.
238 251
      if (isset($message)) {
239
        // message is sanitized coming out of _taxonomy_menu_update_link_items
240
        // no need to reclean it here
252
        // Message is sanitized coming out of _taxonomy_menu_update_link_items
253
        // no need to reclean it here.
241 254
        drupal_set_message($message, 'status');
242 255
      }
243 256

  
......
248 261
}
249 262

  
250 263
/**
251
 * rebuilds a menu
264
 * Rebuilds a menu.
252 265
 *
253
 * @param $vid
254
 * @return $message
255
 *  message that is displayed
266
 * @param int $vid
267
 *   Vocabulary ID.
268
 *
269
 * @return string
270
 *   Message that is displayed.
256 271
 */
257 272
function _taxonomy_menu_rebuild($vid) {
258
  // Remove all of the menu items for this vocabulary
273
  // Remove all of the menu items for this vocabulary.
259 274
  _taxonomy_menu_delete_all($vid);
260 275

  
261
  // Only insert the links if a menu is set
276
  // Only insert the links if a menu is set.
262 277
  if (variable_get(_taxonomy_menu_build_variable('vocab_menu', $vid), FALSE)) {
263 278
    _taxonomy_menu_insert_link_items($vid);
264 279
    menu_rebuild();
......
272 287
/**
273 288
 * Checks to see if the variable has changed.
274 289
 *
275
 * @param $variable
276
 *  name of variable
277
 * @return Boolean
278
 *  TRUE if it has changed
290
 * @param string $variable
291
 *   Name of variable.
292
 *
293
 * @return bool
294
 *   TRUE if it has changed
279 295
 */
280 296
function _taxonomy_menu_check_variable($variable, $new_value) {
281 297
  if ($new_value != variable_get($variable, FALSE)) {
......
285 301
}
286 302

  
287 303
/**
288
 * Update the menu items
304
 * Updates the menu items.
289 305
 *
290 306
 * @param $vid
291
 *  vocab id
307
 *   Vocabulary ID.
292 308
 */
293 309
function _taxonomy_menu_update_link_items($vid) {
294 310
  $menu_name = variable_get(_taxonomy_menu_build_variable('vocab_menu', $vid), FALSE);
311
  $depth = variable_get(_taxonomy_menu_build_variable('max_depth', $vid), 0);
295 312

  
296
  // Get a list of the current tid - menu_link combinations
313
  // Get a list of the current tid - menu_link combinations.
297 314
  $menu_links = _taxonomy_menu_get_menu_items($vid);
298 315

  
299
  // Cycle through the menu links
316
  // Cycle through the menu links.
300 317
  foreach ($menu_links as $tid => $mlid) {
318
    if (!_taxonomy_menu_term_too_deep($tid, $depth))
301 319
    // $args must be reset each time through.
302 320
    $args = array(
303 321
      'menu_name' => $menu_name,
......
311 329
      $args['term'] = taxonomy_term_load($tid);
312 330
    }
313 331

  
314
    //update the menu link
332
    // Update the menu link.
315 333
    taxonomy_menu_handler('update', $args);
316 334
  }
317 335

  
......
319 337
}
320 338

  
321 339
/**
322
 * Creates new link items for the vocabulary
340
 * Creates new link items for the vocabulary.
323 341
 *
324 342
 * @param $vid
343
 *   Vocabulary ID.
325 344
 */
326 345
function _taxonomy_menu_insert_link_items($vid) {
327 346
  $menu_name = variable_get(_taxonomy_menu_build_variable('vocab_menu', $vid), FALSE);
328
  // Check to see if we should had a vocab item
347
  // Check to see if we should had a vocab item.
329 348
  if (variable_get(_taxonomy_menu_build_variable('voc_item', $vid), FALSE)) {
330 349
      $args = array(
331 350
        'vid' => $vid,
......
333 352
      );
334 353
      taxonomy_menu_handler('insert', $args);
335 354
    }
336
  // Let batch api take care of inserting the menu items
355
  // Let batch api take care of inserting the menu items.
337 356
  _taxonomy_menu_insert_link_items_batch($vid);
338 357
}
339 358

  
......
341 360
 * Implements hook_taxonomy_vocabulary_delete().
342 361
 */
343 362
function taxonomy_menu_taxonomy_vocabulary_delete($vocabulary) {
344
  //delete the menu items
363
  // Delete the menu items for this vocab.
345 364
  _taxonomy_menu_delete_all($vocabulary->vid);
346 365
  $menu_name = variable_get(_taxonomy_menu_build_variable('vocab_menu', $vocabulary->vid), 0);
347 366
  menu_cache_clear($menu_name);
367

  
368
  // Delete all the variables for this vocab.
369
  $variable_prefixes = array(
370
    'taxonomy_menu_vocab_menu_',
371
    'taxonomy_menu_vocab_parent_',
372
    'taxonomy_menu_voc_item_',
373
    'taxonomy_menu_display_num_',
374
    'taxonomy_menu_hide_empty_terms_',
375
    'taxonomy_menu_expanded_',
376
    'taxonomy_menu_rebuild_',
377
    'taxonomy_menu_path_',
378
    'taxonomy_menu_menu_end_all_',
379
    'taxonomy_menu_display_descendants_',
380
    'taxonomy_menu_voc_name_',
381
    'taxonomy_menu_sync_',
382
  );
383
  foreach ($variable_prefixes as $prefix) {
384
    variable_del($prefix . $vocabulary->name);
385
  }
348 386
}
349 387

  
350 388
/**
351 389
 * Implements hook_taxonomy_term_insert($term).
352 390
 */
353

  
354 391
function taxonomy_menu_taxonomy_term_insert($term) {
355 392
  _taxonomy_menu_taxonomy_termapi_helper($term, 'insert');
356 393
}
......
358 395
/**
359 396
 * Implements hook_taxonomy_term_update().
360 397
 */
361

  
362 398
function taxonomy_menu_taxonomy_term_update($term) {
363 399
  _taxonomy_menu_taxonomy_termapi_helper($term, 'update');
364 400
}
......
366 402
/**
367 403
 * Implements hook_taxonomy_term_delete().
368 404
 */
369

  
370 405
function taxonomy_menu_taxonomy_term_delete($term) {
371 406
  _taxonomy_menu_taxonomy_termapi_helper($term, 'delete');
372 407
}
......
377 412
function taxonomy_menu_node_insert($node) {
378 413
  $terms_old = &drupal_static('taxonomy_menu_terms_old');
379 414
  // We use this direct table pull to avoid the cache and because
380
  // free tags are not formated in a matter where extrating the
415
  // free tags are not formatted in a matter where extrating the
381 416
  // tid's is easy.
382 417
  $terms_new = _taxonomy_menu_get_node_terms($node);
383 418

  
......
390 425
 * Implements hook_node_update().
391 426
 */
392 427
function taxonomy_menu_node_update($node) {
393
  $terms_old = &drupal_static('taxonomy_menu_terms_old');
394
  //we use this direct table pull to avoid the cache and because
395
  //free tags are not formated in a matter where extrating the
396
  //tid's is easy
397
  $terms_new = _taxonomy_menu_get_node_terms($node);
398

  
399
  //merge current terms and previous terms to update both menu items.
400
  $terms = array_unique(array_merge((array)$terms_new, (array)$terms_old));
401
  _taxonomy_menu_nodeapi_helper('update', $terms, $node);
428
  if (isset($node->original->status) and $node->original->status != $node->status) {
429
    $terms_old = &drupal_static('taxonomy_menu_terms_old');
430
    // We use this direct table pull to avoid the cache and because
431
    // free tags are not formatted in a matter where extracting the
432
    // tid's is easy.
433
    $terms_new = _taxonomy_menu_get_node_terms($node);
434

  
435
    // Merge current terms and previous terms to update both menu items.
436
    $terms = array_unique(array_merge((array)$terms_new, (array)$terms_old));
437
    _taxonomy_menu_nodeapi_helper('update', $terms, $node);
438
  }
402 439
}
403 440

  
404 441
/**
......
406 443
 */
407 444
function taxonomy_menu_node_presave($node) {
408 445
  $terms_old = &drupal_static('taxonomy_menu_terms_old');
409
  //get the terms from the database before the changes are made.
410
  //these will be used to update the menu item's name if needed
411
  //we go directly to the db to bypass any caches
446
  // Get the terms from the database before the changes are made. These will be
447
  // used to update the menu item's name if needed we go directly to the db to
448
  // bypass any caches.
412 449
  if (isset($node->nid)) {
413 450
    $node_old = node_load($node->nid);
414 451
    $terms_old = _taxonomy_menu_get_node_terms($node_old);
......
422 459
 * Implements hook_node_delete().
423 460
 */
424 461
function taxonomy_menu_node_delete($node) {
425
  // since the delete operation is run after the data is deleted
426
  // pull the terms from the node object
462
  // Since the delete operation is run after the data is deleted pull the terms
463
  // from the node object.
427 464
  $terms =  _taxonomy_menu_get_node_terms($node);
428 465
  _taxonomy_menu_nodeapi_helper('delete', $terms, $node);
429 466
}
......
436 473
  // option has been checked.
437 474
  $menu_name = variable_get(_taxonomy_menu_build_variable('vocab_menu', $term->vid), 0);
438 475
  $sync = variable_get(_taxonomy_menu_build_variable('sync', $term->vid), 0);
476
  $depth = variable_get(_taxonomy_menu_build_variable('max_depth', $term->vid), 0);
439 477

  
440
  if ($menu_name && $sync) {
478
  if ($menu_name && $sync && !_taxonomy_menu_term_too_deep($term->tid, $depth)) {
441 479
    $item = array(
442 480
      'tid' => $term->tid,
443 481
      'vid' => $term->vid,
......
459 497
    }
460 498
    $message = t($text, array('%term' => $term->name, '%menu_name' => $menu_name));
461 499

  
462
      // run function
500
    // Run function.
463 501
    taxonomy_menu_handler($operation, $item);
464 502

  
465
    // report status
503
    // Report status.
466 504
    drupal_set_message($message, 'status');
467 505

  
468
    // rebuild the menu
506
    // Rebuild the menu.
469 507
    menu_cache_clear($menu_name);
470 508
  }
471 509
}
......
473 511
/**
474 512
 * Builds argument arrays calls taxonomy_menu_handler.
475 513
 *
476
 * @param $op
477
 *  A string of the operation to be performed [update|insert|delete]
478
 * @param $terms
479
 *  An array of tids.
514
 * @param string $op
515
 *   The operation to be performed [update|insert|delete]
516
 * @param array $terms
517
 *   The taxonomy terms.
480 518
 * @param $node
519
 *   The node object.
481 520
 */
482 521
function _taxonomy_menu_nodeapi_helper($op, $terms = array(), $node) {
483 522
  foreach ($terms as $key => $tid) {
484

  
485
    // taxonomy_term_load($tid) return FALSE if the term was not found
486
    // if taxonomy $term is false, then go to the next $term
523
    // If taxonomy $term is false, then go to the next $term.
524
    // taxonomy_term_load($tid) returns FALSE if the term was not found.
487 525
    if (!$term = taxonomy_term_load($tid)) {
488 526
      continue;
489 527
    }
490 528

  
491
    // update the menu for each term if necessary
529
    // Update the menu for each term if necessary.
492 530
    $menu_name = variable_get(_taxonomy_menu_build_variable('vocab_menu', $term->vid), FALSE);
493 531
    $vocb_sync = variable_get(_taxonomy_menu_build_variable('sync', $term->vid), TRUE);
494 532
    $menu_num = variable_get(_taxonomy_menu_build_variable('display_num', $term->vid), TRUE);
533
    $menu_num_inc_children = variable_get(_taxonomy_menu_build_variable('display_num_incl_children', $term->vid), TRUE);
495 534
    $hide_empty = variable_get(_taxonomy_menu_build_variable('hide_empty_terms', $term->vid), FALSE);
496 535
    if ($menu_name && $vocb_sync && ($menu_num || $hide_empty)) {
497
      //build argument array to save menu_item
536
      // Build argument array to save menu_item.
498 537
      $args = array(
499 538
        'tid' => $term->tid,
500 539
        'vid' => $term->vid,
......
512 551
      }
513 552

  
514 553
      taxonomy_menu_handler($op, $args, $node);
515
      if (variable_get(_taxonomy_menu_build_variable('hide_empty_terms', $term->vid), FALSE)) {
554
      if ($hide_empty || $menu_num && $menu_num_inc_children) {
516 555
        _taxonomy_menu_update_all_parents($term, $menu_name);
517 556
      }
518 557
    }
......
520 559
}
521 560

  
522 561
/**
523
 * Update all parent items
524
 *
525
 * @param $op
526
 *  options are 'insert', 'update', 'delete' or path
562
 * Updates all parent items.
527 563
 *
564
 * @param string $op
565
 *   options are 'insert', 'update', 'delete' or path.
528 566
 * @param $node
529
 *  The node object.
567
 *   The node object.
530 568
 */
531 569
function _taxonomy_menu_update_all_parents($term, $menu_name) {
532 570
  $parents = taxonomy_get_parents($term->tid);
......
546 584
}
547 585

  
548 586
/**
549
 * HANDLING
587
 * Taxonomy Menu Handler: Creates a menu item for each taxonomy term.
550 588
 *
551 589
 * @param $op
552
 *  options are 'insert', 'update', 'delete' or path
553
 *
590
 *   options are 'insert', 'update', 'delete' or path.
591
 * @param $args
592
 *  if $op == 'insert' then args is an array with the following key/value pairs:
593
 *     'term': taxonomy term object,
594
 *     'menu_name' : menu that the item is set to apply to
595
 *  if $op == 'delete' then then args is an array with the following key/value pairs:
596
 *     'tid': TermID
597
 *     'mlid': Menu ID
598
 *  if $op == 'update' then then args is an array with the following key/value pairs:
599
 *     'term': term object,
600
 *     'menu_name': menu that the item is set to apply to
601
 *     'mlid': Menu ID
554 602
 * @param $node
555
 *  The node object.
603
 *   The node object.
604
 * @param $item array
605
 *   Taxonomy menu item.
556 606
 *
557
 * @param $args
558
 *  if $op == 'insert' then
559
 *    array with the following key/value pairs:
560
 *     'term' => term object,
561
 *     'menu_name' => menu that the item is set to apply to
562
 *  if $op == 'delete' then
563
 *    array(
564
 *      'tid' => TermID
565
 *      'mlid => Menu ID
566
 *    )
567
 *  if $op == 'update' then
568
 *     'term' => term object,
569
 *     'menu_name' => menu that the item is set to apply to
570
 *     'mlid' => Menu ID
607
 * @return array
608
 *   Menu link ID for the taxonomy menu item.
571 609
 */
572 610
function taxonomy_menu_handler($op, $args = array(), $node = NULL, $item = array()) {
573
  // Get the initial $item
611
  // Get the initial $item.
574 612
  if (empty($item)) {
575 613
    $item = _taxonomy_menu_create_item($args, $node);
576 614
  }
577 615

  
578
  // Let other modules make edits
616
  // Let other modules make edits.
579 617
  $hook = 'taxonomy_menu_' . $op;
580 618
  foreach (module_implements($hook) as $module) {
581 619
    $function = $module . '_' . $hook;
582 620
    $function($item);
583 621
  }
584 622

  
585
  // Update the menu and return the mlid if the remove element is not true
623
  // Update the menu and return the mlid if the remove element is not true.
586 624
  if ($op != 'delete') {
587 625
    return _taxonomy_menu_save($item);
588 626
  }
......
609 647
 *     'mlid' => if this is filled in then the mlid will be updated
610 648
 */
611 649
function _taxonomy_menu_save($item) {
650
  if (empty($item)) return;
651

  
612 652
  $insert = TRUE;
613 653

  
614
  $flatten_menu = variable_get(_taxonomy_menu_build_variable('flat',
615
$item['vid']));
654
  $flatten_menu = variable_get(_taxonomy_menu_build_variable('flat', $item['vid']));
616 655
  // Child items should appear around the parent/root, so set their weight
617
  // equal to the root term's
656
  // equal to the root term's weight.
618 657
  if ($flatten_menu) {
619 658
    $item['weight'] = $item['root_term_weight'];
620 659
  }
621 660

  
622 661
  // create the path.
623 662
  $path = taxonomy_menu_create_path($item['vid'], $item['tid']);
624
  // get the parent mlid: this is either:
663
  // Get the parent mlid: this is either:
625 664
  // - the parent tid's mlid
626 665
  // - the vocab menu item's mlid
627 666
  // - the menu parent setting for this vocab
......
630 669
    $plid = variable_get(_taxonomy_menu_build_variable('vocab_parent', $item['vid']), NULL);
631 670
  }
632 671

  
633
  // Make sure the path has less then 256 characters
672
  // Make sure the path has less then 256 characters.
634 673
  if (drupal_strlen($path) > 256) {
635 674
    preg_match('/(.{256}.*?)\b/', $path, $matches);
636 675
    $path = rtrim($matches[1]);
......
640 679
    'link_title' => $item['name'],
641 680
    'menu_name' => $item['menu_name'],
642 681
    'plid' => $plid,
643
    'options' => array('attributes' => array('title' => trim($item['description'])
644
      ? $item['description'] : $item['name'])),
645 682
    'weight' => $item['weight'],
646 683
    'module' => 'taxonomy_menu',
647 684
    'expanded' => variable_get(_taxonomy_menu_build_variable('expanded', $item['vid']), TRUE),
648 685
    'link_path' => $path,
649 686
  );
650 687

  
651
  // Add setup the query paramater in the URL correctly
688
  // Be sure to load the original menu link to preserve non-standard properties.
689
  if (isset($item['mlid']) && !empty($item['mlid']) && $original_link = menu_link_load($item['mlid'])) {
690
    $link = array_merge($original_link, $link);
691
  }
692
  else {
693
    $link['options'] = array(
694
      'attributes' => array(
695
        'title' => trim($item['description']) ? $item['description'] : $item['name'],
696
      ),
697
    );
698
  }
699

  
700
  // Add setup the query paramater in the URL correctly.
652 701
  if (strpos($path, '?') !== FALSE) {
653 702
    $split = explode('?', $path);
654 703
    if (strpos($split[1], '?') !== FALSE) {
......
661 710
    }
662 711
  }
663 712

  
664
  // If passed a mlid then add it
713
  // If passed a mlid then add it.
665 714
  if (isset($item['mlid']) && $item['mlid']) {
666 715
    $link['mlid'] = $item['mlid'];
667 716
    $insert = FALSE;
717
    $menu_link = menu_link_load($item['mlid']);
718
    $is_hidden = $menu_link['hidden'];
719
  }
720
  else {
721
    $is_hidden = 0;
668 722
  }
669 723

  
670
  // FIXME: i18nmenu need to be cleaned up to allow translation from other menu module
724
  // @todo i18nmenu needs to be cleaned up to allow translation from other menu modules.
671 725
  if (module_exists('i18n_menu')) {
672 726
    $link['options']['alter'] = TRUE;
673 727
    $link['language'] = $item['language'];
674 728
    $link['customized'] = 1;
675 729
  }
676 730

  
677
  // set the has_children property
678
  // if tid=0 then adding a vocab item and had children
679
  // if the term has any children then set it to true
731
  // Set the has_children property.
732
  // If tid=0 then adding a vocab item and had children.
733
  // If the term has any children then set it to true.
680 734
  if ($item['tid'] == 0) {
681 735
    $link['has_children'] = 1;
682 736
  }
......
687 741
    }
688 742
  }
689 743

  
690
  // If remove is true then set hidden to 1
691
  $link['hidden'] = (isset($item['remove']) && $item['remove']) ? 1 : 0;
744
  // If remove is true then set hidden to 1.
745
  $link['hidden'] = (isset($item['remove']) && $item['remove']) ? 1 : $is_hidden;
692 746

  
693
  // Save the menu item
747
  // Save the menu item.
694 748
  if ($mlid = menu_link_save($link)) {
695
    // if inserting a new menu item then insert a record into the table
749
    // if inserting a new menu item then insert a record into the table.
696 750
    if ($insert) {
697 751
      _taxonomy_menu_insert_menu_item($mlid, $item['tid'], $item['vid']);
698 752
    }
......
705 759
}
706 760

  
707 761
/**
708
 * Create the path to use in the menu item
762
 * Create the path to use in the menu item.
709 763
 *
710 764
 * @return array
711
 *  path selections
765
 *   Path selections.
712 766
 */
713 767
function _taxonomy_menu_get_paths() {
714 768
  return module_invoke_all('taxonomy_menu_path');
......
718 772
 * Creates the path for the vid/tid combination.
719 773
 *
720 774
 * @param $vid
775
 *   Vocablary ID.
721 776
 * @param $tid
777
 *   Taxonomy term ID.
778
 *
722 779
 * @return string
723
 *  path
780
 *   Path
724 781
 */
725 782
function taxonomy_menu_create_path($vid, $tid) {
726
  // get the path function for this vocabulary
783
  // Get the path function for this vocabulary.
727 784
  $function = variable_get(_taxonomy_menu_build_variable('path', $vid), 'taxonomy_menu_path_default');
728
  // run the function
785
  // Run the function.
729 786
  return $function($vid, $tid);
730 787
}
731 788

  
732 789
/**
733 790
 * Implements hook_taxonomy_menu_path().
734 791
 *
735
 * Invoked from _taxonomy_menu_get_paths.
736
 *
737 792
 * @return array
738
 *  function name => Display Title
739
 *  a list of the path options.
793
 *   A list of the path options in the form: function_name => Display Title.
794
 *
795
 * @see _taxonomy_menu_get_paths().
740 796
 */
741 797
function taxonomy_menu_taxonomy_menu_path() {
742 798
  $output = array(
......
747 803
}
748 804

  
749 805
/**
750
 * Callback for hook_taxonomy_menu_path
806
 * Callback for hook_taxonomy_menu_path.
751 807
 */
752 808
function taxonomy_menu_path_default($vid, $tid) {
753
  // if tid = 0 then we are creating the vocab menu item format will be taxonomy/term/$tid+$tid+$tid....
809
  // If tid = 0 then we are creating the vocab menu item format will be taxonomy/term/$tid+$tid+$tid...
754 810
  if ($tid == 0) {
755
    // get all of the terms for the vocab
811
    // Get all of the terms for the vocab.
756 812
    $vtids = _taxonomy_menu_get_terms($vid);
757
    $end = implode(' ', $vtids);
813
    $end = implode('/', $vtids);
758 814
    $path = "taxonomy/term/$end";
759 815
  }
760 816
  else {
761 817
    $path = 'taxonomy/term/' . $tid;
762 818
    if (variable_get(_taxonomy_menu_build_variable('display_descendants', $vid), FALSE)) {
763
      // Use 'all' at the end of the path
819
      // Use 'all' at the end of the path.
764 820
      if (variable_get(_taxonomy_menu_build_variable('end_all', $vid), FALSE)) {
765 821
        $path .= '/all';
766 822
      }
767 823
      else {
768
        // we wait to run this instead of during the if above
769
        // because we only wan to run it once.
824
        // We wait to run this instead of during the if above because we only
825
        // want to run it once.
770 826
        $terms = taxonomy_get_tree($vid, $tid);
771 827
        foreach ($terms as $term) {
772 828
          $tids[] = $term->tid;
773 829
        }
774
        if ($tids) {
775
          $end = implode(' ', $tids);
776
          $path .= ' ' . $end;
830
        if (isset($tids)) {
831
          $end = implode('/', $tids);
832
          $path .= '/ ' . $end;
777 833
        }
778 834
      }
779 835
    }
......
783 839
}
784 840

  
785 841
/**
786
 * hook_taxonomy_menu_delete
787
 *
788
 * @param $args
789
 *  array(
790
 *   'vid' => Vocab ID
791
 *   'tid' => TermID
792
 *   'mlid' => Menu ID
793
 *  )
842
 * Implements hook_taxonomy_menu_delete().
794 843
 *
844
 * @param array $item
845
 *   Taxonomy menu item array, containing the following key/value pairs:
846
 *     'vid': Vocabulary ID.
847
 *     'tid': Taxonomy term ID.
848
 *     'mlid': Menu link ID.
795 849
 */
796 850
function taxonomy_menu_taxonomy_menu_delete(&$item) {
797 851
  menu_link_delete($item['mlid']);
798 852
  _taxonomy_menu_delete_item($item['vid'], $item['tid']);
799 853
  unset($item['mlid']);
800

  
801 854
}
802 855

  
803 856
/**
804
 * Create the initial $item array
857
 * Creates the initial $item array.
805 858
 *
806 859
 * @param $args
807
 *  array with the following key/value pairs:
808
 *   'term' => term object, if updating a term
809
 *   'menu_name' => menu that the item is set to apply to
810
 *   'vid' => vocab id.  if editing vocab item
811
 *   'mlid' => menu id
860
 *   array with the following key/value pairs:
861
 *     'term': Taxonomy term object, if updating a term.
862
 *     'menu_name': menu that the item is set to apply to.
863
 *     'vid': Vocabuary id, if editing vocab item.
864
 *     'mlid': Menu link id.
812 865
 *
813 866
 * @param $node
814
 *  The node object.
867
 *   The node object.
815 868
 */
816 869
function _taxonomy_menu_create_item($args = array(), $node) {
817

  
818
  // If tid = 0, then we are creating a vocab item
870
  // If tid = 0, then we are creating a vocab item.
819 871
  if (isset($args['tid']) && isset($args['vid']) && $args['tid'] == 0 && variable_get(_taxonomy_menu_build_variable('voc_item', $args['vid']), 0)) {
820 872
    $vocab = taxonomy_vocabulary_load($args['vid']);
821 873
    $item = array(
......
838 890
    if (empty($term->parents)) {
839 891
      $term->parents = _taxonomy_menu_get_parents($term->tid);
840 892
      if (empty($term->parents)) {
841
        // even without parents, create one with $ptid = 0
893
        // Even without parents, create one with $ptid = 0.
842 894
        $term->parents = array(0 => '0');
843 895
      }
844 896
    }
......
847 899
    // a flat taxonomy menu.
848 900
    if (is_object($term)) {
849 901
      $term_parents = taxonomy_get_parents_all($term->tid);
850
      $root_term_weight = $term_parents[count($term_parents) - 1]->weight;
902
      $root_term_weight = ($term_parents) ? $term_parents[count($term_parents) - 1]->weight : 0;
851 903
    }
852 904
    else {
853 905
      $root_term_weight = 0;
......
855 907

  
856 908
    foreach ($term->parents as $parent) {
857 909
      $ptid = $parent;
858
      // turn the term into the correct $item array form
910
      // Turn the term into the correct $item array form.
859 911
      $item = array(
912
        'term' => $term,
860 913
        'tid' => $term->tid,
861 914
        'name' => $term->name,
862 915
        'description' => variable_get(_taxonomy_menu_build_variable('term_item_description', $term->vid), 0) ? $term->description : '',
863
        'weight' => $term->weight,
916
        'weight' => !empty($term->weight) ? $term->weight : 0,
864 917
        'vid' => $term->vid,
865 918
        'ptid' => $ptid,
866 919
        'root_term_weight' => $root_term_weight,
......
870 923
      if (isset($args['mlid'])) {
871 924
        $item['mlid'] = $args['mlid'];
872 925
      }
873
      // Mutiple parents are not supported yet, hence this break.
874
      // without the break, the item is inserted multiple under one parent, instead once under each parent.
926
      // Mutiple parents are not supported yet. Without the break, the item is
927
      // inserted multiple under one parent, instead of once under each parent.
875 928
      break;
876 929
    }
877 930
  }
......
880 933
}
881 934

  
882 935
/**
883
 * Helper function to see if any of the children have any nodes
936
 * Helper function: See if any of the children have any nodes.
884 937
 *
885 938
 * @param $tid
939
 *   Taxonomy term ID.
886 940
 * @param $vid
941
 *   Vocabulary ID.
942
 *
887 943
 * @return boolean
888 944
 */
889 945
function _taxonomy_menu_children_has_nodes($tid, $vid, $return = FALSE) {
......
900 956
}
901 957

  
902 958
/**
903
 * Helper function for insert and update hooks
959
 * Helper function: Inserts and updates menu along with taxonomy changes.
960
 *
961
 * @param array $item
962
 *   Taxonomy menu item.
904 963
 *
905
 * @param $item
906 964
 * @return array
965
 *   Taxonomy menu item.
907 966
 */
908 967
function _taxonomy_menu_item($item) {
909
  // if tid is 0 then do not change any settings
968
  if (empty($item)) return;
969

  
970
  // If tid is 0 then do not change any settings.
910 971
  if ($item['tid'] > 0) {
911
    // get the number of node attached to this term
972
    // Get the number of node attached to this term.
912 973
    $num = _taxonomy_menu_term_count($item['tid']);
913 974

  
914
    // if hide menu is selected and the term count is 0 and the term has no children then do not create the menu item
975
    // If hide menu is selected and the term count is 0 and the term has no
976
    // children then do not create the menu item.
915 977
    if ($num == 0 &&
916
        variable_get(_taxonomy_menu_build_variable('hide_empty_terms', $item['vid']), FALSE) &&
917
        !_taxonomy_menu_children_has_nodes($item['tid'], $item['vid'])) {
918

  
978
      variable_get(_taxonomy_menu_build_variable('hide_empty_terms', $item['vid']), FALSE) &&
979
      !_taxonomy_menu_children_has_nodes($item['tid'], $item['vid'])) {
919 980
        $item['remove'] = TRUE;
... Ce différentiel a été tronqué car il excède la taille maximale pouvant être affichée.

Formats disponibles : Unified diff