commerce_kickstart_menus.module

Tracking 7.x-2.x branch
  1. drupal
    1. 7 contributions/commerce_kickstart/modules/commerce_kickstart/commerce_kickstart_menus/commerce_kickstart_menus.module

Functions & methods

NameDescription
commerce_kickstart_menus_menuImplements hook_menu().
commerce_kickstart_menus_menu_alterImplements hook_menu_alter().
commerce_kickstart_menus_menu_breadcrumb_alterImplements hook_menu_breadcrumb_alter().
commerce_kickstart_menus_menu_link_alterImplements hook_menu_link_alter().
commerce_kickstart_menus_module_implements_alterImplements hook_module_implements_alter().
commerce_kickstart_menus_views_apiImplements hook_views_api().
_commerce_kickstart_menu_find_router

File

View source
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
<?php

/**
 * Implements hook_menu().
 */
function commerce_kickstart_menus_menu() {
  $items['admin/help'] = array(
    'title' => 'Getting Started',
    'description' => '',
    'page callback' => 'advanced_help_topic_page',
    'page arguments' => array('commerce_kickstart_help', 'first-steps'),
    'access arguments' => array('view advanced help topic'),
    'file path' => drupal_get_path('module', 'advanced_help'),
    'weight' => 100,
  );

  $items['admin/site-config/layout'] = array(
    'title' => 'Visual & Layout',
    'description' => 'Administer the appearance and layout of your store.',
    'page callback' => 'system_admin_menu_block_page',
    'access arguments' => array('access administration pages'),
    'file path' => drupal_get_path('module', 'system'),
    'file' => 'system.admin.inc',
    'weight' => 150,
  );

  $items['admin/site-config'] = array(
    'title' => 'Configure site',
    'description' => 'Administer the site configuration.',
    'page callback' => 'system_admin_menu_block_page',
    'access arguments' => array('access administration pages'),
    'file path' => drupal_get_path('module', 'system'),
    'file' => 'system.admin.inc',
    'weight' => 100,
  );

  $items['admin/site-config/advanced'] = array(
    'title' => 'Advanced settings',
    'description' => 'Administer the site configuration.',
    'page callback' => 'system_admin_menu_block_page',
    'access arguments' => array('access administration pages'),
    'file path' => drupal_get_path('module', 'system'),
    'file' => 'system.admin.inc',
    'weight' => 200,
  );

  $items['admin/commerce/config/types'] = array(
    'title' => 'Product & content types',
    'description' => 'Manage products types for your store.',
    'page callback' => 'commerce_product_ui_types_overview',
    'access arguments' => array('administer product types'),
    'file' => 'includes/commerce_product_ui.types.inc',
    'file path' => drupal_get_path('module', 'commerce_product_ui'),
  );
  $items['admin/commerce/config/types/product'] = array(
    'title' => 'Product types',
    'type' => MENU_DEFAULT_LOCAL_TASK,
  );
  $items['admin/commerce/config/types/product/add'] = array(
    'title' => 'Add product type',
    'page callback' => 'commerce_product_ui_product_type_form_wrapper',
    'page arguments' => array(commerce_product_ui_product_type_new()),
    'access arguments' => array('administer product types'),
    'type' => MENU_LOCAL_ACTION,
    'file' => 'includes/commerce_product_ui.types.inc',
    'file path' => drupal_get_path('module', 'commerce_product_ui'),
  );
  $items['admin/commerce/config/types/content'] = array(
    'title' => 'Content types',
    'description' => 'Manage content types, including default status, front page promotion, comment settings, etc.',
    'page callback' => 'node_overview_types',
    'access arguments' => array('administer content types'),
    'type' => MENU_LOCAL_TASK,
    'file' => 'content_types.inc',
    'file path' => drupal_get_path('module', 'node'),
  );
  $items['admin/commerce/config/types/content/add'] = array(
    'title' => 'Add content type',
    'page callback' => 'drupal_get_form',
    'page arguments' => array('node_type_form'),
    'access arguments' => array('administer content types'),
    'type' => MENU_LOCAL_ACTION,
    'file' => 'content_types.inc',
    'file path' => drupal_get_path('module', 'node'),
  );

  $items['admin/commerce/config/products-categories'] = array(
    'title' => 'Product categories',
    'description' => 'Manage tagging, categorization, and classification of your products.',
    'page callback' => 'drupal_get_form',
    'page arguments' => array('taxonomy_overview_vocabularies'),
    'access arguments' => array('administer taxonomy'),
    'file' => 'taxonomy.admin.inc',
    'file path' => drupal_get_path('module', 'taxonomy'),
  );
  $items['admin/commerce/config/products-categories/add'] = array(
    'title' => 'Add categories',
    'page callback' => 'drupal_get_form',
    'page arguments' => array('taxonomy_form_vocabulary'),
    'access arguments' => array('administer taxonomy'),
    'type' => MENU_LOCAL_ACTION,
    'file' => 'taxonomy.admin.inc',
    'file path' => drupal_get_path('module', 'taxonomy'),
  );

  return $items;
}

/**
 * Implements hook_menu_alter().
 */
function commerce_kickstart_menus_menu_alter(&$items) {


  // "Getting Started" (help) entry point.
  if (isset($items['admin/help'])) {
    $items['admin/help']['title'] = 'Getting Started';
    $items['admin/help']['parent'] = 'admin';
    $items['admin/help']['weight'] = -100;
    $items['admin/help']['options'] = array(
      'toolbar_expanded' => TRUE,
      'toolbar_break' => TRUE,
    );
  }

  // Move the pages under the "Getting Started" entry.
  foreach (array('admin/help/getting-started', 'admin/help/first-steps', 'admin/demo') as $path) {
    if (isset($items[$path])) {
      $items[$path]['parent'] = 'admin/help';
      $items[$path]['context'] = MENU_CONTEXT_PAGE | MENU_CONTEXT_INLINE;
      if ($path == 'admin/demo') {
        $items[$path]['title'] = 'Reset your Demo Site';
      }
    }
  }

  // "Products" entry point.
  if (isset($items['admin/commerce/products'])) {
    $items['admin/commerce/products']['parent'] = 'admin';
    $items['admin/commerce/products']['weight'] = -30;
  }
  // "Orders" entry point.
  if (isset($items['admin/commerce/orders'])) {
    $items['admin/commerce/orders']['parent'] = 'admin';
    $items['admin/commerce/orders']['weight'] = -20;
  }

  // Disable "Store" entry point.
  if (isset($items['admin/commerce'])) {
    $items['admin/commerce']['hidden'] = TRUE;
  }

  // "Store settings" entry point.
  if (isset($items['admin/commerce/config'])) {
    $items['admin/commerce/config']['title'] = 'Store settings';
    $items['admin/commerce/config']['parent'] = 'admin';
    $items['admin/commerce/config']['weight'] = 10;
    $items['admin/commerce/config']['options'] = array(
      'toolbar_expanded' => TRUE,
      'toolbar_break' => TRUE,
    );
  }

  if (isset($items['admin/commerce/config/product-pricing'])) {
    // Just because the default title 'Product pricing rules' is too long.
    $items['admin/commerce/config/product-pricing']['title'] = 'Pricing rules';
  }

  // Show the Discounts link under "Store settings".
  if (isset($items['admin/commerce/store/discounts'])) {
    $items['admin/commerce/store/discounts']['parent'] = 'admin/commerce/config';
  }

  // - Visual & Layout subentry.
  if (isset($items['admin/site-config/layout'])) {
    $items['admin/site-config/layout']['options'] = array(
      'toolbar_expanded' => TRUE,
      'toolbar_break' => TRUE,
    );
  }

  // Move the appearance and layout entries under admin/site-config/layout.
  foreach (array('admin/appearance', 'admin/structure/block', 'admin/structure/views') as $path) {
    if (isset($items[$path])) {
      $items[$path]['parent'] = 'admin/site-config/layout';
    }
  }

  // - Site configuration subentry.
  if (isset($items['admin/site-config'])) {
    $items['admin/site-config']['options'] = array(
      'toolbar_expanded' => TRUE,
      'toolbar_break' => TRUE,
    );
  }
  // - Advanced site configuration subentry.
  if (isset($items['admin/site-config/advanced'])) {
    $items['admin/site-config/advanced']['options'] = array(
      'toolbar_expanded' => TRUE,
      'toolbar_break' => TRUE,
    );
  }

  // Move the main Drupal entry points below admin/site-config/advanced.
  foreach (array('admin/structure', 'admin/people', 'admin/modules', 'admin/config', 'admin/reports', 'admin/advanced_help') as $path) {
    if (isset($items[$path])) {
      $items[$path]['parent'] = 'admin/site-config/advanced';
    }
  }
}

/**
 * Implements hook_menu_link_alter().
 *
 * Apply some link configuration stored in the router during the menu
 * rebuild process.
 */
function commerce_kickstart_menus_menu_link_alter(&$link) {
  // Check if the item belongs to a shortcut menu.
  if (module_exists('shortcut') && shortcut_set_load($link['menu_name'])) {
    // Don't change the plid of shortcut menu items.
    return;
  }

  $item = _commerce_kickstart_menu_find_router($link['link_path']);
  if ($item && isset($item['options'])) {
    if (!isset($link['options'])) {
      $link['options'] = array();
    }
    $link['options'] += $item['options'];
  }
  if ($item && isset($item['parent'])) {
    $plid = db_query('SELECT mlid FROM {menu_links} WHERE link_path = :path', array(':path' => $item['parent']))->fetchField();
    if ($plid) {
      $link['plid'] = $plid;
    }
  }
}

function _commerce_kickstart_menu_find_router($link_path) {
  $router = menu_get_router();
  $parts = explode('/', $link_path, MENU_MAX_PARTS);

  $ancestors = menu_get_ancestors($parts);
  // Add an empty router path as a fallback.
  $ancestors[] = '';
  foreach ($ancestors as $key => $router_path) {
    if (isset($router[$router_path])) {
      // Exit the loop leaving $router_path as the first match.
      break;
    }
  }

  return isset($router[$router_path]) ? $router[$router_path] : NULL;
}

/**
 * Implements hook_module_implements_alter().
 */
function commerce_kickstart_menus_module_implements_alter(&$implementations, $hook) {
  if (in_array($hook, array('menu_alter'))) {
    // Move our hook implementation to the bottom.
    $group = $implementations['commerce_kickstart_menus'];
    unset($implementations['commerce_kickstart_menus']);
    $implementations['commerce_kickstart_menus'] = $group;
  }
}

/**
 * Implements hook_views_api().
 */
function commerce_kickstart_menus_views_api() {
  return array(
    'api' => 3,
    'path' => drupal_get_path('module', 'commerce_kickstart_menus') . '/views',
  );
}

/**
 * Implements hook_menu_breadcrumb_alter().
 */
function commerce_kickstart_menus_menu_breadcrumb_alter(&$active_trail, $item) {
  // Home > Administration > Products
  if (drupal_match_path($item['path'], 'admin/commerce/products/types')) {
    $active_trail_end = array_slice($active_trail, 3);
    $active_trail = array_slice($active_trail, 0, 1);
    $active_trail[] = menu_get_item('admin');
    $active_trail[] = menu_get_item('admin/commerce/products');
    $active_trail = array_merge($active_trail, $active_trail_end);
  }
  // Home > Administration > Store settings > Product & content types > Content types OR Product types
  if (drupal_match_path($item['path'], "admin/structure/types/*\nadmin/commerce/products/types/*")) {
    if (drupal_match_path($item['path'], 'admin/structure/types/*')) {
      $active_trail_end = array_slice($active_trail, 6);
    }
    else {
      $active_trail_end = array_slice($active_trail, 4);
    }
    $active_trail = array_slice($active_trail, 0, 1);
    $active_trail[] = menu_get_item('admin');
    $active_trail[] = menu_get_item('admin/commerce/config');
    $active_trail[] = menu_get_item('admin/commerce/config/types');
    $is_product_type = in_array(strtr(arg(4),'-','_'), array_keys(commerce_product_reference_node_types()));
    if ($is_product_type) {
      $active_trail[] = menu_get_item('admin/commerce/config/types/product');
    }
    else {
      $active_trail[] = menu_get_item('admin/commerce/config/types/content');
    }
    $active_trail = array_merge($active_trail, $active_trail_end);
  }
  // Home > Administration > Content > Add content OR Add product
  if (drupal_match_path($item['path'], 'node/add*')) {
    $active_trail_end = array_slice($active_trail, 1);
    $active_trail = array_slice($active_trail, 0, 1);
    $active_trail[] = menu_get_item('admin');
    $active_trail[] = array('title' => 'Content') + menu_get_item('admin/content');
    $is_product_display_page = in_array(strtr(arg(2),'-','_'), array_keys(commerce_product_reference_node_types()));
    if (drupal_match_path($item['path'], 'node/add/add-product') || $is_product_display_page) {
      array_shift($active_trail_end);
      $active_trail_end[0] = menu_get_item('node/add/add-product');
    }
    $active_trail = array_merge($active_trail, $active_trail_end);
  }
}