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_products_settings_accessAccess callback for the Products settings menu item.
commerce_kickstart_menus_views_apiImplements hook_views_api().
commerce_kickstart_menus_visual_layout_accessAccess callback for the Visual & Layout menu item.
_commerce_kickstart_menus_get_itemReturns a menu router item.
_commerce_kickstart_menu_find_router

File

View source
  1. <?php
  2. /**
  3. * Implements hook_menu().
  4. */
  5. function commerce_kickstart_menus_menu() {
  6. // Site settings
  7. $items['admin/site-config'] = array(
  8. 'title' => 'Site settings',
  9. 'description' => 'Administer the site configuration.',
  10. 'page callback' => 'system_admin_menu_block_page',
  11. 'access arguments' => array('access administration pages'),
  12. 'file path' => drupal_get_path('module', 'system'),
  13. 'file' => 'system.admin.inc',
  14. 'weight' => 40,
  15. 'options' => array(
  16. 'toolbar_expanded' => TRUE,
  17. 'toolbar_break' => TRUE,
  18. 'toolbar_css' => 'site-settings',
  19. ),
  20. );
  21. // Products
  22. $items['admin/commerce/manage-products'] = array(
  23. 'title' => 'Products',
  24. 'description' => 'Manage products.',
  25. 'page callback' => 'drupal_goto',
  26. 'page arguments' => array('admin/commerce/products'),
  27. 'access arguments' => array('administer commerce_product entities'),
  28. 'weight' => -20,
  29. 'parent' => 'admin',
  30. 'options' => array(
  31. 'toolbar_expanded' => TRUE,
  32. 'toolbar_break' => TRUE,
  33. 'toolbar_css' => 'products',
  34. ),
  35. );
  36. // Products > Actions
  37. $items['admin/commerce/manage-products/actions'] = array(
  38. 'title' => 'Actions',
  39. 'description' => 'Products actions.',
  40. 'page callback' => 'system_admin_menu_block_page',
  41. 'access arguments' => array('access administration pages'),
  42. 'file path' => drupal_get_path('module', 'system'),
  43. 'file' => 'system.admin.inc',
  44. 'weight' => 0,
  45. 'options' => array(
  46. 'toolbar_expanded' => TRUE,
  47. 'toolbar_break' => TRUE,
  48. 'toolbar_css' => 'actions',
  49. ),
  50. );
  51. // Products > Settings
  52. $items['admin/commerce/manage-products/settings'] = array(
  53. 'title' => 'Settings',
  54. 'description' => 'Products settings.',
  55. 'page callback' => 'system_admin_menu_block_page',
  56. 'access callback' => 'commerce_kickstart_menus_products_settings_access',
  57. 'file path' => drupal_get_path('module', 'system'),
  58. 'file' => 'system.admin.inc',
  59. 'weight' => 1,
  60. 'options' => array(
  61. 'toolbar_expanded' => TRUE,
  62. 'toolbar_break' => TRUE,
  63. ),
  64. );
  65. // Products > Settings > Categories
  66. $items['admin/commerce/manage-products/settings/categories'] = array(
  67. 'title' => 'Categories',
  68. 'description' => 'Manage tagging, categorization, and classification of your products.',
  69. 'page callback' => 'drupal_goto',
  70. 'page arguments' => array('admin/commerce/config/products-categories'),
  71. 'access arguments' => array('administer taxonomy'),
  72. );
  73. // Products > Settings > Variation types
  74. $items['admin/commerce/manage-products/settings/product-variation-types'] = array(
  75. 'title' => 'Variation types',
  76. 'description' => 'Manage products variation types for your store.',
  77. 'page callback' => 'drupal_goto',
  78. 'page arguments' => array('admin/commerce/config/product-variation-types'),
  79. 'access arguments' => array('administer product types'),
  80. );
  81. // Orders
  82. $items['admin/commerce/manage-orders'] = array(
  83. 'title' => 'Orders',
  84. 'description' => 'Manage Orders.',
  85. 'page callback' => 'drupal_goto',
  86. 'page arguments' => array('admin/commerce/orders'),
  87. 'access arguments' => array('access administration pages'),
  88. 'weight' => -15,
  89. 'parent' => 'admin',
  90. 'options' => array(
  91. 'toolbar_expanded' => TRUE,
  92. 'toolbar_break' => TRUE,
  93. 'toolbar_css' => 'orders',
  94. ),
  95. );
  96. // Orders > Actions
  97. $items['admin/commerce/manage-orders/actions'] = array(
  98. 'title' => 'Actions',
  99. 'description' => 'Orders actions.',
  100. 'page callback' => 'system_admin_menu_block_page',
  101. 'access arguments' => array('access administration pages'),
  102. 'file path' => drupal_get_path('module', 'system'),
  103. 'file' => 'system.admin.inc',
  104. 'weight' => 0,
  105. 'options' => array(
  106. 'toolbar_expanded' => TRUE,
  107. 'toolbar_break' => TRUE,
  108. ),
  109. );
  110. // Content
  111. $items['admin/commerce/manage-content'] = array(
  112. 'title' => 'Content',
  113. 'description' => 'Manage content.',
  114. 'page callback' => 'drupal_goto',
  115. 'page arguments' => array('admin/content'),
  116. 'access arguments' => array('access administration pages'),
  117. 'weight' => -10,
  118. 'parent' => 'admin',
  119. 'options' => array(
  120. 'toolbar_expanded' => TRUE,
  121. 'toolbar_break' => TRUE,
  122. 'toolbar_css' => 'content',
  123. ),
  124. );
  125. // Content > Actions
  126. $items['admin/commerce/manage-content/actions'] = array(
  127. 'title' => 'Actions',
  128. 'description' => 'Content actions.',
  129. 'page callback' => 'system_admin_menu_block_page',
  130. 'access arguments' => array('access administration pages'),
  131. 'file path' => drupal_get_path('module', 'system'),
  132. 'file' => 'system.admin.inc',
  133. 'weight' => 0,
  134. 'options' => array(
  135. 'toolbar_expanded' => TRUE,
  136. 'toolbar_break' => TRUE,
  137. ),
  138. );
  139. // Content > Settings
  140. $items['admin/commerce/manage-content/settings'] = array(
  141. 'title' => 'Settings',
  142. 'description' => 'Content settings.',
  143. 'page callback' => 'system_admin_menu_block_page',
  144. 'access arguments' => array('administer content types'),
  145. 'file path' => drupal_get_path('module', 'system'),
  146. 'file' => 'system.admin.inc',
  147. 'weight' => 1,
  148. 'options' => array(
  149. 'toolbar_expanded' => TRUE,
  150. 'toolbar_break' => TRUE,
  151. ),
  152. );
  153. // Content > Settings > Content types
  154. $items['admin/commerce/manage-content/settings/content-types'] = array(
  155. 'title' => 'Content types',
  156. 'description' => 'Manage content types for your store.',
  157. 'page callback' => 'drupal_goto',
  158. 'page arguments' => array('admin/structure/types'),
  159. 'access arguments' => array('administer content types'),
  160. );
  161. // Store settings > Advanced store settings
  162. $items['admin/commerce/config/advanced-settings'] = array(
  163. 'title' => 'Advanced store settings',
  164. 'description' => 'Advanced store settings.',
  165. 'page callback' => 'system_admin_menu_block_page',
  166. 'access arguments' => array('access administration pages'),
  167. 'file path' => drupal_get_path('module', 'system'),
  168. 'file' => 'system.admin.inc',
  169. 'weight' => 0,
  170. 'options' => array(
  171. 'toolbar_expanded' => TRUE,
  172. 'toolbar_break' => TRUE,
  173. ),
  174. );
  175. // Store settings > Product settings
  176. $items['admin/commerce/config/product-settings'] = array(
  177. 'title' => 'Product settings',
  178. 'description' => 'Administer the product settings.',
  179. 'page callback' => 'system_admin_menu_block_page',
  180. 'access callback' => 'commerce_kickstart_menus_products_settings_access',
  181. 'file path' => drupal_get_path('module', 'system'),
  182. 'file' => 'system.admin.inc',
  183. 'weight' => 5,
  184. 'options' => array(
  185. 'toolbar_expanded' => TRUE,
  186. 'toolbar_break' => TRUE,
  187. ),
  188. );
  189. if (module_exists('commerce_discount')) {
  190. // Store settings > Promotions
  191. $items['admin/commerce/config/promotions'] = array(
  192. 'title' => 'Promotions',
  193. 'description' => 'Administer promotions.',
  194. 'page callback' => 'system_admin_menu_block_page',
  195. 'access arguments' => array('administer commerce discounts'),
  196. 'file path' => drupal_get_path('module', 'system'),
  197. 'file' => 'system.admin.inc',
  198. 'weight' => 10,
  199. 'options' => array(
  200. 'toolbar_expanded' => TRUE,
  201. 'toolbar_break' => TRUE,
  202. ),
  203. );
  204. }
  205. // Site settings > Visual & Layout
  206. $items['admin/site-config/layout'] = array(
  207. 'title' => 'Visual & Layout',
  208. 'description' => 'Administer the appearance and layout of your store.',
  209. 'page callback' => 'system_admin_menu_block_page',
  210. 'access callback' => 'commerce_kickstart_menus_visual_layout_access',
  211. 'file path' => drupal_get_path('module', 'system'),
  212. 'file' => 'system.admin.inc',
  213. 'weight' => 0,
  214. 'options' => array(
  215. 'toolbar_expanded' => TRUE,
  216. 'toolbar_break' => TRUE,
  217. ),
  218. );
  219. // Site settings > Advanced settings
  220. $items['admin/site-config/advanced'] = array(
  221. 'title' => 'Advanced settings',
  222. 'description' => 'Administer the site configuration.',
  223. 'page callback' => 'system_admin_menu_block_page',
  224. 'access arguments' => array('access administration pages'),
  225. 'file path' => drupal_get_path('module', 'system'),
  226. 'file' => 'system.admin.inc',
  227. 'weight' => 1,
  228. 'options' => array(
  229. 'toolbar_expanded' => TRUE,
  230. 'toolbar_break' => TRUE,
  231. ),
  232. );
  233. // Store settings > Product settings > Categories
  234. $items['admin/commerce/config/products-categories'] = array(
  235. 'title' => 'Categories',
  236. 'description' => 'Manage tagging, categorization, and classification of your products.',
  237. 'page callback' => 'drupal_get_form',
  238. 'page arguments' => array('taxonomy_overview_vocabularies'),
  239. 'access arguments' => array('administer taxonomy'),
  240. 'file' => 'taxonomy.admin.inc',
  241. 'file path' => drupal_get_path('module', 'taxonomy'),
  242. );
  243. // Store settings > Product settings > Categories > Add categories
  244. $items['admin/commerce/config/products-categories/add'] = array(
  245. 'title' => 'Add categories',
  246. 'page callback' => 'drupal_get_form',
  247. 'page arguments' => array('taxonomy_form_vocabulary'),
  248. 'access arguments' => array('administer taxonomy'),
  249. 'type' => MENU_LOCAL_ACTION,
  250. 'file' => 'taxonomy.admin.inc',
  251. 'file path' => drupal_get_path('module', 'taxonomy'),
  252. );
  253. return $items;
  254. }
  255. /**
  256. * Access callback for the Products settings menu item.
  257. */
  258. function commerce_kickstart_menus_products_settings_access() {
  259. return user_access('administer taxonomy') || user_access('administer product types');
  260. }
  261. /**
  262. * Access callback for the Visual & Layout menu item.
  263. */
  264. function commerce_kickstart_menus_visual_layout_access() {
  265. return user_access('administer themes') || user_access('administer blocks') || user_access('administer views');
  266. }
  267. /**
  268. * Implements hook_menu_alter().
  269. */
  270. function commerce_kickstart_menus_menu_alter(&$items) {
  271. // Move the pages under the "Getting Started" entry.
  272. foreach (array('admin/help/getting-started', 'admin/help/first-steps', 'admin/demo') as $path) {
  273. if (isset($items[$path])) {
  274. $items[$path]['parent'] = 'admin/help';
  275. $items[$path]['context'] = MENU_CONTEXT_PAGE | MENU_CONTEXT_INLINE;
  276. if ($path == 'admin/demo') {
  277. $items[$path]['title'] = 'Reset your Demo Site';
  278. }
  279. }
  280. }
  281. // Products > Manage products
  282. if (isset($items['admin/commerce/products'])) {
  283. $items['admin/commerce/products']['parent'] = 'admin/commerce/manage-products/actions';
  284. $items['admin/commerce/products']['title'] = 'Manage products';
  285. $items['admin/commerce/products']['weight'] = -30;
  286. $items['admin/commerce/products']['type'] = MENU_NORMAL_ITEM;
  287. }
  288. // Products > Add a product
  289. if (isset($items['node/add/add-product'])) {
  290. $items['node/add/add-product']['parent'] = 'admin/commerce/manage-products/actions';
  291. $items['node/add/add-product']['title'] = 'Add a product';
  292. $items['node/add/add-product']['type'] |= MENU_NORMAL_ITEM;
  293. }
  294. // Orders > Manage orders
  295. if (isset($items['admin/commerce/orders'])) {
  296. $items['admin/commerce/orders']['title'] = 'Manage orders';
  297. $items['admin/commerce/orders']['parent'] = 'admin/commerce/manage-orders/actions';
  298. $items['admin/commerce/orders']['weight'] = -25;
  299. }
  300. // Orders > Add an order
  301. if (isset($items['admin/commerce/orders/add'])) {
  302. $items['admin/commerce/orders/add']['parent'] = 'admin/commerce/manage-orders/actions';
  303. $items['admin/commerce/orders/add']['title'] = 'Add an order';
  304. $items['admin/commerce/orders/add']['weight'] = -24;
  305. }
  306. // Content > Manage content
  307. if (isset($items['admin/content'])) {
  308. $items['admin/content']['parent'] = 'admin/commerce/manage-content/actions';
  309. $items['admin/content']['title'] = 'Manage content';
  310. $items['admin/content']['weight'] = -15;
  311. $items['admin/content']['type'] = MENU_NORMAL_ITEM;
  312. }
  313. // Content > Manage comments
  314. if (isset($items['admin/content/comment'])) {
  315. $items['admin/content/comment']['parent'] = 'admin/commerce/manage-content/actions';
  316. $items['admin/content/comment']['title'] = 'Manage comments';
  317. $items['admin/content/comment']['weight'] = -14;
  318. $items['admin/content/comment']['type'] = MENU_NORMAL_ITEM;
  319. }
  320. // Content > Add content
  321. if (isset($items['node/add/add-content'])) {
  322. $items['node/add/add-content']['parent'] = 'admin/commerce/manage-content/actions';
  323. $items['node/add/add-content']['title'] = 'Add content';
  324. $items['node/add/add-content']['type'] |= MENU_NORMAL_ITEM;
  325. }
  326. // Disable "Store" entry point.
  327. if (isset($items['admin/commerce'])) {
  328. $items['admin/commerce']['hidden'] = TRUE;
  329. }
  330. // "Store settings" entry point.
  331. if (isset($items['admin/commerce/config'])) {
  332. $items['admin/commerce/config']['title'] = 'Store settings';
  333. $items['admin/commerce/config']['parent'] = 'admin';
  334. $items['admin/commerce/config']['weight'] = 30;
  335. $items['admin/commerce/config']['options'] = array(
  336. 'toolbar_expanded' => TRUE,
  337. 'toolbar_break' => TRUE,
  338. 'toolbar_css' => 'store-settings',
  339. );
  340. }
  341. if (isset($items['admin/help'])) {
  342. $items['admin/help']['weight'] = 50;
  343. $items['admin/help']['options'] = array(
  344. 'toolbar_expanded' => TRUE,
  345. 'toolbar_break' => TRUE,
  346. 'toolbar_css' => 'help',
  347. );
  348. }
  349. if (isset($items['admin/commerce/config/product-pricing'])) {
  350. // Just because the default title 'Product pricing rules' is too long.
  351. $items['admin/commerce/config/product-pricing']['title'] = 'Pricing rules';
  352. }
  353. if (isset($items['admin/commerce/config/products-categories'])) {
  354. $items['admin/commerce/config/products-categories']['parent'] = 'admin/commerce/config/product-settings';
  355. }
  356. if (isset($items['admin/commerce/config/product-variation-types'])) {
  357. $items['admin/commerce/config/product-variation-types']['title'] = 'Variation types';
  358. $items['admin/commerce/config/product-variation-types']['parent'] = 'admin/commerce/config/product-settings';
  359. }
  360. // Show the Discounts link under "Store settings".
  361. if (module_exists('commerce_discount') && isset($items['admin/commerce/store/discounts'])) {
  362. $items['admin/commerce/store/discounts']['parent'] = 'admin/commerce/config/promotions';
  363. }
  364. $advanced_store_items = array(
  365. 'admin/commerce/customer-profiles',
  366. 'admin/commerce/config/shipping',
  367. 'admin/commerce/config/taxes',
  368. 'admin/commerce/config/payment-methods',
  369. 'admin/commerce/config/checkout',
  370. 'admin/commerce/config/currency',
  371. 'admin/commerce/config/line-items',
  372. 'admin/commerce/config/order',
  373. 'admin/commerce/config/product-pricing',
  374. 'admin/commerce/config/commerce_search_api',
  375. 'admin/commerce/config/demo',
  376. );
  377. $weight = 0;
  378. foreach ($advanced_store_items as $advanced_store_item) {
  379. if (isset($items[$advanced_store_item])) {
  380. $items[$advanced_store_item]['parent'] = 'admin/commerce/config/advanced-settings';
  381. $items[$advanced_store_item]['weight'] = $weight++;
  382. }
  383. }
  384. // Move the appearance and layout entries under admin/site-config/layout.
  385. foreach (array('admin/appearance', 'admin/structure/block', 'admin/structure/views') as $path) {
  386. if (isset($items[$path])) {
  387. $items[$path]['parent'] = 'admin/site-config/layout';
  388. }
  389. }
  390. // Move the main Drupal entry points below admin/site-config/advanced.
  391. foreach (array('admin/structure', 'admin/people', 'admin/modules', 'admin/config', 'admin/reports', 'admin/advanced_help') as $path) {
  392. if (isset($items[$path])) {
  393. $items[$path]['parent'] = 'admin/site-config/advanced';
  394. }
  395. $items['admin/reports']['title'] = 'Site reports';
  396. }
  397. // Lingotek alteration.
  398. if (isset($items['admin/settings/lingotek'])) {
  399. $items['admin/settings/lingotek']['options'] = array(
  400. 'toolbar_break' => TRUE,
  401. 'toolbar_css' => 'lingotek',
  402. );
  403. }
  404. if (isset($items['commerceguys-marketplace'])) {
  405. $items['commerceguys-marketplace']['title'] = 'Marketplace';
  406. $items['commerceguys-marketplace']['parent'] = 'admin';
  407. $items['commerceguys-marketplace']['weight'] = 49;
  408. $items['commerceguys-marketplace']['options'] = array(
  409. 'toolbar_break' => TRUE,
  410. 'toolbar_css' => 'marketplace',
  411. );
  412. }
  413. }
  414. /**
  415. * Implements hook_menu_link_alter().
  416. *
  417. * Apply some link configuration stored in the router during the menu
  418. * rebuild process.
  419. */
  420. function commerce_kickstart_menus_menu_link_alter(&$link) {
  421. // Check if the item belongs to a shortcut menu.
  422. if (module_exists('shortcut') && shortcut_set_load($link['menu_name'])) {
  423. // Don't change the plid of shortcut menu items.
  424. return;
  425. }
  426. // Don't change the plid for customized menu items.
  427. if (!empty($link['customized'])) {
  428. return;
  429. }
  430. $item = _commerce_kickstart_menu_find_router($link['link_path']);
  431. if ($item && isset($item['options'])) {
  432. if (!isset($link['options'])) {
  433. $link['options'] = array();
  434. }
  435. $link['options'] += $item['options'];
  436. }
  437. if ($item && isset($item['parent'])) {
  438. $plid = db_query('SELECT mlid FROM {menu_links} WHERE link_path = :path', array(':path' => $item['parent']))->fetchField();
  439. if ($plid) {
  440. $link['plid'] = $plid;
  441. }
  442. }
  443. }
  444. function _commerce_kickstart_menu_find_router($link_path) {
  445. $router = menu_get_router();
  446. $parts = explode('/', $link_path, MENU_MAX_PARTS);
  447. $ancestors = menu_get_ancestors($parts);
  448. // Add an empty router path as a fallback.
  449. $ancestors[] = '';
  450. foreach ($ancestors as $key => $router_path) {
  451. if (isset($router[$router_path])) {
  452. // Exit the loop leaving $router_path as the first match.
  453. break;
  454. }
  455. }
  456. return isset($router[$router_path]) ? $router[$router_path] : NULL;
  457. }
  458. /**
  459. * Implements hook_module_implements_alter().
  460. */
  461. function commerce_kickstart_menus_module_implements_alter(&$implementations, $hook) {
  462. if (in_array($hook, array('menu_alter'))) {
  463. // Move our hook implementation to the bottom.
  464. $group = $implementations['commerce_kickstart_menus'];
  465. unset($implementations['commerce_kickstart_menus']);
  466. $implementations['commerce_kickstart_menus'] = $group;
  467. }
  468. }
  469. /**
  470. * Implements hook_views_api().
  471. */
  472. function commerce_kickstart_menus_views_api() {
  473. return array(
  474. 'api' => 3,
  475. 'path' => drupal_get_path('module', 'commerce_kickstart_menus') . '/views',
  476. );
  477. }
  478. /**
  479. * Implements hook_menu_breadcrumb_alter().
  480. */
  481. function commerce_kickstart_menus_menu_breadcrumb_alter(&$active_trail, $item) {
  482. // Home > Administration > Content > Settings > Content types
  483. if (drupal_match_path($item['path'], "admin/structure/types") || drupal_match_path($item['path'], "admin/structure/types/*")) {
  484. if (drupal_match_path($item['path'], "admin/structure/types/add")) {
  485. return;
  486. }
  487. $active_trail_end = array_slice($active_trail, 6);
  488. $active_trail = array_slice($active_trail, 0, 1);
  489. $active_trail[] = _commerce_kickstart_menus_get_item('admin');
  490. $active_trail[] = _commerce_kickstart_menus_get_item('admin/commerce/manage-content');
  491. $active_trail[] = _commerce_kickstart_menus_get_item('admin/commerce/manage-content/settings');
  492. $active_trail[] = _commerce_kickstart_menus_get_item('admin/commerce/manage-content/settings/content-types');
  493. $active_trail = array_merge($active_trail, $active_trail_end);
  494. }
  495. // Set the breadcrumb for the "Add content" tab of node/add.
  496. else if (drupal_match_path($item['path'], 'node/add')) {
  497. $active_trail = array_slice($active_trail, 0, 1);
  498. $active_trail[] = _commerce_kickstart_menus_get_item('admin');
  499. $active_trail[] = _commerce_kickstart_menus_get_item('admin/commerce/manage-content');
  500. $active_trail[] = _commerce_kickstart_menus_get_item('admin/commerce/manage-content/actions');
  501. $active_trail[] = _commerce_kickstart_menus_get_item('node/add/add-content');
  502. }
  503. }
  504. /**
  505. * Returns a menu router item.
  506. *
  507. * If the Crumbs module is enabled, uses the Crumbs-provided function and
  508. * sets additional keys later expected by that module.
  509. *
  510. * @param $path
  511. * The path, for example node/5.
  512. *
  513. * @return
  514. * The loaded router item, with additional keys set if the Crumbs module is
  515. * present.
  516. */
  517. function _commerce_kickstart_menus_get_item($path) {
  518. if (module_exists('crumbs')) {
  519. static $loaded = FALSE;
  520. if (!$loaded) {
  521. module_load_include('inc', 'crumbs', 'crumbs.trail');
  522. $loaded = TRUE;
  523. }
  524. $item = crumbs_get_router_item($path);
  525. $item['link_title'] = $item['title'];
  526. $item['link_options'] = array();
  527. return $item;
  528. }
  529. else {
  530. return menu_get_item($path);
  531. }
  532. }