module_filter.module 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. <?php
  2. /**
  3. * @file
  4. * This is the file description for Module Filter module.
  5. *
  6. * In this more verbose, multi-line description, you can specify what this
  7. * file does exactly. Make sure to wrap your documentation in column 78 so
  8. * that the file can be displayed nicely in default-sized consoles.
  9. *
  10. * @author greenSkin
  11. */
  12. /**
  13. * Implementation of hook_perm().
  14. */
  15. function module_filter_permission() {
  16. return array(
  17. 'administer module filter' => array(
  18. 'title' => t('Administer Module Filter'),
  19. 'description' => t('Configure how Module Filter performs.')
  20. )
  21. );
  22. }
  23. /**
  24. * Implementation of hook_menu().
  25. */
  26. function module_filter_menu() {
  27. $items['admin/config/user-interface/modulefilter'] = array(
  28. 'title' => 'Module filter',
  29. 'description' => 'Configure settings for Module Filter.',
  30. 'access arguments' => array('administer module filter'),
  31. 'page callback' => 'drupal_get_form',
  32. 'page arguments' => array('module_filter_settings'),
  33. 'file' => 'module_filter.admin.inc'
  34. );
  35. return $items;
  36. }
  37. /**
  38. * Implementation of hook_form_FORM_ID_alter().
  39. */
  40. function module_filter_form_system_modules_alter(&$form, &$form_state, $form_id) {
  41. // Don't alter the form when confirming.
  42. if (isset($form['confirm'])) {
  43. return;
  44. }
  45. $form['module_filter'] = array(
  46. '#tree' => TRUE,
  47. '#weight' => -1,
  48. '#attached' => array(
  49. 'css' => array(
  50. drupal_get_path('module', 'module_filter') .'/css/module_filter.css',
  51. ),
  52. ),
  53. );
  54. $form['module_filter']['name'] = array(
  55. '#type' => 'textfield',
  56. '#title' => t('Filter list')
  57. );
  58. $form['module_filter']['show'] = array(
  59. '#type' => 'checkboxes',
  60. '#default_value' => array('enabled', 'disabled', 'required', 'unavailable'),
  61. '#options' => array('enabled' => t('Enabled'), 'disabled' => t('Disabled'), 'required' => t('Required'), 'unavailable' => t('Unavailable')),
  62. '#prefix' => '<div id="module-filter-show-wrapper">',
  63. '#suffix' => '</div>'
  64. );
  65. if (variable_get('module_filter_tabs', 1)) {
  66. $form['module_filter']['#attached']['css'][] = drupal_get_path('module', 'module_filter') .'/css/module_filter_tab.css';
  67. $form['module_filter']['#attached']['js'][] = drupal_get_path('module', 'module_filter') .'/js/module_filter_tab.js';
  68. $form['module_filter']['#attached']['js'][] = array(
  69. 'data' => array('moduleFilter' => array('visualAid' => variable_get('module_filter_visual_aid', 1))),
  70. 'type' => 'setting',
  71. );
  72. if (variable_get('module_filter_dynamic_save_position', 0)) {
  73. $form['module_filter']['#attached']['js'][] = drupal_get_path('module', 'module_filter') .'/js/dynamic_position.js';
  74. }
  75. $form['module_filter']['#size'] = 45;
  76. // Remove the fieldsets for each package since we will be using tabs
  77. // instead. Put all modules into one array.
  78. $modules = array(
  79. '#theme' => 'module_filter_modules_table',
  80. '#header' => array(
  81. array('data' => t('Enabled'), 'class' => 'checkbox'),
  82. t('Name'),
  83. t('Version'),
  84. t('Description'),
  85. array('data' => t('Operations'), 'colspan' => 3)
  86. )
  87. );
  88. $all = t('All');
  89. $tab_counts = array($all => array('id' => 'all', 'enabled' => 0, 'total' => 0));
  90. $form['#packages'] = array();
  91. foreach (element_children($form['modules']) as $package) {
  92. // Add the package to $form['#packages']. Tabs are built from this.
  93. $form['#packages'][$package] = $package;
  94. if (!isset($tab_counts[$package])) {
  95. $tab_counts[$package] = array('enabled' => 0, 'total' => 0);
  96. }
  97. foreach (element_children($form['modules'][$package]) as $module) {
  98. $tab_counts[$all]['total']++;
  99. $tab_counts[$package]['total']++;
  100. if (!empty($form['modules'][$package][$module]['enable']['#default_value'])) {
  101. $tab_counts[$all]['enabled']++;
  102. $tab_counts[$package]['enabled']++;
  103. }
  104. $modules[$module] = $form['modules'][$package][$module];
  105. $modules[$module]['#package'] = $package;
  106. $modules[$module]['#parents'] = array('modules', $package, $module);
  107. }
  108. }
  109. // Sort the array of modules alphabetically.
  110. uasort($modules, 'module_filter_sort_modules_by_display_name');
  111. // Replace the $form['modules'] with our $modules array.
  112. $form['modules'] = $modules;
  113. // Add our $tab_counts array to the form.
  114. $form['#tab_counts'] = $tab_counts;
  115. $form['#theme'] = 'module_filter_system_modules_tabs';
  116. }
  117. else {
  118. $form['module_filter']['#attached']['js'][] = drupal_get_path('module', 'module_filter') .'/js/module_filter.js';
  119. $form['module_filter']['#prefix'] = '<div id="module-filter-wrapper" style="display: none;">';
  120. $form['module_filter']['#suffix'] = '</div>';
  121. }
  122. }
  123. /**
  124. * Implementation of hook_theme().
  125. */
  126. function module_filter_theme() {
  127. return array(
  128. 'module_filter_modules_table' => array(
  129. 'render element' => 'form',
  130. 'file' => 'module_filter.theme.inc',
  131. ),
  132. 'module_filter_system_modules_tabs' => array(
  133. 'render element' => 'form',
  134. 'file' => 'module_filter.theme.inc'
  135. )
  136. );
  137. }
  138. function module_filter_sort_modules_by_display_name($a, $b) {
  139. if (is_array($a) && is_array($b) && isset($a['#package'], $b['#package'])) {
  140. return strcasecmp($a['name']['#markup'], $b['name']['#markup']);
  141. }
  142. return 0;
  143. }
  144. function module_filter_get_id($text) {
  145. $id = strtolower($text);
  146. return preg_replace('/([^a-z])([\/( )])*/', '-', $id);
  147. }