module_filter.theme.inc 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  1. <?php
  2. /**
  3. * @file
  4. *
  5. * @author greenSkin
  6. */
  7. function theme_module_filter($variables) {
  8. $element = $variables['element'];
  9. return '<div class="module-filter-inputs-wrapper">' . drupal_render_children($element) . '</div>';
  10. }
  11. /**
  12. * Theme callback for the modules tabbed form.
  13. */
  14. function theme_module_filter_system_modules_tabs($variables) {
  15. if (module_exists('views_ui')) {
  16. // Hack to get consistent style with views ctools dropbutton.
  17. if (module_load_include('inc', 'views_ui', 'includes/admin')) {
  18. foreach (views_ui_get_admin_css() as $file => $options) {
  19. drupal_add_css($file, $options);
  20. }
  21. }
  22. }
  23. $form = $variables['form'];
  24. if (!module_exists('page_actions')) {
  25. $form['actions']['#prefix'] = '<div id="module-filter-submit">';
  26. $form['actions']['#suffix'] = '</div>';
  27. }
  28. $header = array(
  29. array('data' => '', 'class' => array('checkbox')),
  30. array('data' => t('Name'), 'class' => array('name')),
  31. array('data' => t('Description'), 'class' => array('description')),
  32. array('data' => t('Links'), 'class' => array('links')),
  33. );
  34. if (variable_get('module_filter_version_column', 0)) {
  35. array_splice($header, 2, 0, array(array('data' => t('Version'), 'class' => array('version'))));
  36. }
  37. $package_ids = array('all');
  38. $enabled['all'] = array();
  39. if (variable_get('module_filter_track_recent_modules', 1)) {
  40. $recent_modules = array_filter(variable_get('module_filter_recent_modules', array()), 'module_filter_recent_filter');
  41. // Save the filtered results.
  42. variable_set('module_filter_recent_modules', $recent_modules);
  43. $package_ids[] = 'recent';
  44. $enabled['recent'] = array();
  45. }
  46. // Determine what modules are new (within a week).
  47. $new_modules = module_filter_new_modules();
  48. $package_ids[] = 'new';
  49. $enabled['new'] = array();
  50. $rows = array();
  51. $flip = array('even' => 'odd', 'odd' => 'even');
  52. foreach (element_children($form['modules']) as $package) {
  53. $package_id = module_filter_get_id($package);
  54. $package_ids[] = $package_id;
  55. // Package title and header.
  56. $rows[] = array('data' => array(array('data' => '<h3>' . $form['modules'][$package]['#title'] . '</h3>', 'colspan' => 4)), 'id' => $package_id . '-package', 'class' => array('admin-package-title'));
  57. $rows[] = array('data' => $header, 'class' => array('admin-package-header'));
  58. $stripe = 'odd';
  59. $enabled[$package_id] = array();
  60. foreach (element_children($form['modules'][$package]) as $key) {
  61. $module = &$form['modules'][$package][$key];
  62. $is_enabled = isset($module['enable']['#default_value']) ? $module['enable']['#default_value'] : '';
  63. $enabled['all'][] = $enabled[$package_id][] = $is_enabled;
  64. if (isset($recent_modules[$key])) {
  65. $enabled['recent'][] = $is_enabled;
  66. }
  67. if (isset($new_modules[$key])) {
  68. $enabled['new'][] = $is_enabled;
  69. }
  70. $row = array();
  71. $version = !empty($module['version']['#markup']);
  72. $requires = !empty($module['#requires']);
  73. $required_by = !empty($module['#required_by']);
  74. $toggle_enable = '';
  75. if (isset($module['enable']['#type']) && $module['enable']['#type'] == 'checkbox') {
  76. unset($module['enable']['#title']);
  77. $class = ($is_enabled ? 'enabled' : 'off');
  78. if (!empty($module['enable']['#disabled'])) {
  79. $class .= ' disabled';
  80. }
  81. $toggle_enable = '<div class="js-hide toggle-enable ' . $class . '"><div>&nbsp;</div></div>';
  82. }
  83. $row[] = array('class' => array('checkbox'), 'data' => $toggle_enable . drupal_render($module['enable']));
  84. $label = '<label';
  85. if (isset($module['enable']['#id'])) {
  86. $label .= ' for="' . $module['enable']['#id'] . '"';
  87. }
  88. $row[] = array('class' => array('name'), 'data' => $label . '><strong>' . drupal_render($module['name']) . '</strong> <span class="module-machine-name">(' . $key . ')</span></label>');
  89. if (variable_get('module_filter_version_column', 0) && $version) {
  90. $row[] = array('class' => array('version'), 'data' => drupal_render($module['version']));
  91. }
  92. // Add the description, along with any modules it requires.
  93. if (empty($module['description']['#markup'])) {
  94. $module['description']['#markup'] = '<em>' . t('No description available.') . '</em>';
  95. }
  96. $description = '<span class="details"><span class="text">' . drupal_render($module['description']) . '</span></span>';
  97. if ($requires || $required_by || (!variable_get('module_filter_version_column', 0) && $version)) {
  98. $description .= '<div class="requirements">';
  99. if (!variable_get('module_filter_version_column', 0) && $version) {
  100. $description .= '<div class="admin-requirements">' . t('Version: !module-version', array('!module-version' => drupal_render($module['version']))) . '</div>';
  101. }
  102. if ($requires) {
  103. $description .= '<div class="admin-requirements">' . t('Requires: !module-list', array('!module-list' => implode(', ', $module['#requires']))) . '</div>';
  104. }
  105. if ($required_by) {
  106. $description .= '<div class="admin-requirements">' . t('Required by: !module-list', array('!module-list' => implode(', ', $module['#required_by']))) . '</div>';
  107. }
  108. $description .= '</div>';
  109. }
  110. $row[] = array('data' => '<div class="inner expand" role="button">' . $description . '</div>', 'class' => array('description'));
  111. $operations = (module_exists('ctools')) ? theme('module_filter_operations', array('links' => $module['links'], 'dropbutton' => TRUE)) : theme('module_filter_operations', array('links' => $module['links']));
  112. $row[] = array('data' => '<div class="links">' . $operations . '</div>', 'class' => array('links'));
  113. $class = array(module_filter_get_id($package) . '-tab', 'module', $stripe);
  114. if (isset($recent_modules[$key])) {
  115. $class[] = 'recent-module';
  116. }
  117. if (isset($new_modules[$key])) {
  118. $class[] = 'new-module';
  119. }
  120. $rows[] = array('data' => $row, 'no_striping' => TRUE, 'class' => $class);
  121. $stripe = $flip[$stripe];
  122. }
  123. // Set the package as printed.
  124. $form['modules'][$package]['#printed'] = TRUE;
  125. }
  126. //Get packages and count number of modules
  127. $enabled_counts = array();
  128. foreach ($enabled as $package_id => $value) {
  129. $enabled_counts[$package_id] = array(
  130. 'enabled' => count(array_filter($value)),
  131. 'total' => count($value),
  132. );
  133. }
  134. drupal_add_js(array(
  135. 'moduleFilter' => array(
  136. 'packageIDs' => $package_ids,
  137. 'enabledCounts' => $enabled_counts,
  138. )
  139. ), 'setting');
  140. // Add first and last class to rows.
  141. $rows[0]['class'][] = 'first';
  142. $rows[count($rows) - 1]['class'][] = 'last';
  143. $output = '<div id="module-filter-wrapper">';
  144. $output .= '<div id="module-filter-modules">' . drupal_render($form['module_filter']);
  145. $output .= theme('table', array('header' => $header, 'rows' => $rows));
  146. $output .= drupal_render_children($form);
  147. $output .= '</div>';
  148. $output .= '</div>';
  149. return $output;
  150. }
  151. /**
  152. * Theme function for module filter operations.
  153. * @param $variables
  154. * @return
  155. * HTML for admin status operations.
  156. */
  157. function theme_module_filter_operations(&$vars) {
  158. $links = &$vars['links'];
  159. $dropbutton = $vars['dropbutton'];
  160. $operations = array();
  161. foreach (element_children($links) as $key) {
  162. if ($dropbutton) {
  163. hide($links[$key]);
  164. if (!empty($links[$key]['#href'])) {
  165. $operations[$key] = array(
  166. 'title' => $links[$key]['#title'],
  167. 'href' => $links[$key]['#href'],
  168. );
  169. if (isset($links[$key]['#options'])) {
  170. $operations[$key] += $links[$key]['#options'];
  171. }
  172. }
  173. }
  174. else {
  175. $data = drupal_render($links[$key]);
  176. if (!empty($data)) {
  177. $operations[$key] = array('data' => $data);
  178. }
  179. }
  180. }
  181. if (!empty($operations)) {
  182. if ($dropbutton) {
  183. return '<div class="admin-operations">' . theme('links__ctools_dropbutton', array('title' => t('Operations'), 'links' => $operations, 'attributes' => array('class' => array('links')))) . '</div>';
  184. }
  185. return '<div class="admin-operations">' . theme('item_list', array('items' => $operations, 'attributes' => array('class' => array('links', 'inline')))) . '</div>';
  186. }
  187. }