mb_extra.module 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. <?php
  2. /**
  3. * @file
  4. * Provides various functions for the expansion of core modules.
  5. *
  6. * Implemented:
  7. * - Alter menu local task links from node to insert destination parameter.
  8. * Children tabs supported to level 1.
  9. * - Alter the confirm form cancel link to display the link as button.
  10. */
  11. /**
  12. * Implements hook_menu().
  13. */
  14. function mb_extra_menu() {
  15. $items = array();
  16. $items['admin/config/mb/buttons/more-buttons-extra'] = array(
  17. 'page callback' => 'drupal_get_form',
  18. 'page arguments' => array('mb_extra_admin'),
  19. 'title' => 'Extras',
  20. 'access arguments' => array('administer site configuration'),
  21. 'file' => 'mb_extra.admin.inc',
  22. 'type' => MENU_LOCAL_TASK,
  23. 'weight' => 15
  24. );
  25. $items['admin/config/mb/buttons/more-buttons-extra/reset'] = array(
  26. 'page callback' => 'drupal_get_form',
  27. 'page arguments' => array('mb_extra_reset'),
  28. 'access arguments' => array('administer site configuration'),
  29. 'type' => MENU_CALLBACK,
  30. 'file' => 'mb_extra.admin.inc'
  31. );
  32. return $items;
  33. }
  34. /**
  35. * Alter the local tasks to use an destination parameter.
  36. */
  37. function mb_extra_menu_local_tasks_alter(&$data, $router_item, $root_path) {
  38. if (module_exists('overlay')) {
  39. return;
  40. }
  41. global $base_url;
  42. $module = 'mb_extra';
  43. if ($router_item['tab_root'] == 'node/%') {
  44. if (variable_get($module . '_destination_tabs', 0) == TRUE && count($data['tabs']) > 0) {
  45. $destination = drupal_get_destination();
  46. foreach (element_children($data['tabs'][0]['output']) as $key) {
  47. if ($data['tabs'][0]['output'][$key]['#link']['tab_root_href'] != $destination['destination'] && !stristr($destination['destination'], $data['tabs'][0]['output'][$key]['#link']['tab_root_href'])) {
  48. $params = $data['tabs'][0]['output'][$key]['#link'];
  49. $data['tabs'][0]['output'][$key]['#link']['href'] = $base_url . '/' . $params['href'] . '?destination=' . $destination['destination'];
  50. //$data['tabs'][0]['output'][$key]['#link']['tab_root_href'] = $base_url . '/' . $params['tab_root_href'] . '?destination=' . $destination['destination'];
  51. //$data['tabs'][0]['output'][$key]['#link']['tab_parent_href'] = $base_url . '/' . $params['tab_parent_href'] . '?destination=' . $destination['destination'];
  52. }
  53. }
  54. // Children tabs level 1.
  55. if (isset($data['tabs'][1])) {
  56. foreach (element_children($data['tabs'][1]['output']) as $key) {
  57. if ($data['tabs'][1]['output'][$key]['#link']['tab_root_href'] != $destination['destination']) {
  58. $params = $data['tabs'][1]['output'][$key]['#link'];
  59. $data['tabs'][1]['output'][$key]['#link']['href'] = $base_url . '/' . $params['href'] . '?destination=' . $destination['destination'];
  60. //$data['tabs'][0]['output'][$key]['#link']['tab_root_href'] = $base_url . '/' . $params['tab_root_href'] . '?destination=' . $destination['destination'];
  61. //$data['tabs'][0]['output'][$key]['#link']['tab_parent_href'] = $base_url . '/' . $params['tab_parent_href'] . '?destination=' . $destination['destination'];
  62. if (isset($data['tabs'][1]['output'][$key]['#active'])) {
  63. $data['tabs'][1]['output'][$key]['#link']['localized_options'] = array(
  64. 'attributes' => array(
  65. 'class' => 'active'
  66. )
  67. );
  68. }
  69. }
  70. }
  71. }
  72. }
  73. }
  74. }
  75. /**
  76. * Implements hook_theme().
  77. */
  78. function mb_extra_theme() {
  79. return array(
  80. 'mb_extra_admin' => array(
  81. 'variables' => array('form' => NULL),
  82. )
  83. );
  84. }
  85. /**
  86. * Implements hook_form_alter().
  87. */
  88. function mb_extra_form_alter(&$form, &$form_state, $form_id) {
  89. $module = 'mb_extra';
  90. // Alter the confirm form cancel link to display the link as button.
  91. if (isset($form['confirm']) && variable_get($module . '_confirm_cancel', 0) == TRUE) {
  92. $form['actions']['cancel']['#attributes']['class'][] = 'button';
  93. }
  94. }