module_filter.theme.inc 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  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. $package_ids = array('all');
  35. $enabled['all'] = array();
  36. if (variable_get('module_filter_track_recent_modules', 1)) {
  37. $recent_modules = array_filter(variable_get('module_filter_recent_modules', array()), 'module_filter_recent_filter');
  38. // Save the filtered results.
  39. variable_set('module_filter_recent_modules', $recent_modules);
  40. $package_ids[] = 'recent';
  41. $enabled['recent'] = array();
  42. }
  43. // Determine what modules are new (within a week).
  44. $new_modules = module_filter_new_modules();
  45. $package_ids[] = 'new';
  46. $enabled['new'] = array();
  47. $rows = array();
  48. $flip = array('even' => 'odd', 'odd' => 'even');
  49. foreach (element_children($form['modules']) as $package) {
  50. $package_id = module_filter_get_id($package);
  51. $package_ids[] = $package_id;
  52. // Package title and header.
  53. $rows[] = array('data' => array(array('data' => '<h3>' . $form['modules'][$package]['#title'] . '</h3>', 'colspan' => 4)), 'id' => $package_id . '-package', 'class' => array('admin-package-title'));
  54. $rows[] = array('data' => $header, 'class' => array('admin-package-header'));
  55. $stripe = 'odd';
  56. $enabled[$package_id] = array();
  57. foreach (element_children($form['modules'][$package]) as $key) {
  58. $module = &$form['modules'][$package][$key];
  59. $is_enabled = isset($module['enable']['#default_value']) ? $module['enable']['#default_value'] : '';
  60. $enabled['all'][] = $enabled[$package_id][] = $is_enabled;
  61. if (isset($recent_modules[$key])) {
  62. $enabled['recent'][] = $is_enabled;
  63. }
  64. if (isset($new_modules[$key])) {
  65. $enabled['new'][] = $is_enabled;
  66. }
  67. $row = array();
  68. $version = !empty($module['version']['#markup']);
  69. $requires = !empty($module['#requires']);
  70. $required_by = !empty($module['#required_by']);
  71. $toggle_enable = '';
  72. if (isset($module['enable']['#type']) && $module['enable']['#type'] == 'checkbox') {
  73. unset($module['enable']['#title']);
  74. $class = ($is_enabled ? 'enabled' : 'off');
  75. if (!empty($module['enable']['#disabled'])) {
  76. $class .= ' disabled';
  77. }
  78. $toggle_enable = '<div class="js-hide toggle-enable ' . $class . '"><div>&nbsp;</div></div>';
  79. }
  80. $row[] = array('class' => array('checkbox'), 'data' => $toggle_enable . drupal_render($module['enable']));
  81. $label = '<label';
  82. if (isset($module['enable']['#id'])) {
  83. $label .= ' for="' . $module['enable']['#id'] . '"';
  84. }
  85. $row[] = array('class' => array('name'), 'data' => $label . '><strong>' . drupal_render($module['name']) . '</strong> <span class="module-machine-name">(' . $key . ')</span></label>');
  86. // Add the description, along with any modules it requires.
  87. $description = '<span class="details"><span class="text">' . drupal_render($module['description']) . '</span></span>';
  88. if ($version || $requires || $required_by) {
  89. $description .= '<div class="requirements">';
  90. if ($version) {
  91. $description .= '<div class="admin-requirements">' . t('Version: !module-version', array('!module-version' => drupal_render($module['version']))) . '</div>';
  92. }
  93. if ($requires) {
  94. $description .= '<div class="admin-requirements">' . t('Requires: !module-list', array('!module-list' => implode(', ', $module['#requires']))) . '</div>';
  95. }
  96. if ($required_by) {
  97. $description .= '<div class="admin-requirements">' . t('Required by: !module-list', array('!module-list' => implode(', ', $module['#required_by']))) . '</div>';
  98. }
  99. $description .= '</div>';
  100. }
  101. $row[] = array('data' => '<div class="inner expand" role="button">' . $description . '</div>', 'class' => array('description'));
  102. $operations = (module_exists('ctools')) ? theme('module_filter_operations', array('links' => $module['links'], 'dropbutton' => TRUE)) : theme('module_filter_operations', array('links' => $module['links']));
  103. $row[] = array('data' => '<div class="links">' . $operations . '</div>', 'class' => array('links'));
  104. $class = array(module_filter_get_id($package) . '-tab', 'module', $stripe);
  105. if (isset($recent_modules[$key])) {
  106. $class[] = 'recent-module';
  107. }
  108. if (isset($new_modules[$key])) {
  109. $class[] = 'new-module';
  110. }
  111. $rows[] = array('data' => $row, 'no_striping' => TRUE, 'class' => $class);
  112. $stripe = $flip[$stripe];
  113. }
  114. // Set the package as printed.
  115. $form['modules'][$package]['#printed'] = TRUE;
  116. }
  117. if (variable_get('module_filter_count_enabled', 1)) {
  118. $enabled_counts = array();
  119. foreach ($enabled as $package_id => $value) {
  120. $enabled_counts[$package_id] = array(
  121. 'enabled' => count(array_filter($value)),
  122. 'total' => count($value),
  123. );
  124. }
  125. drupal_add_js(array(
  126. 'moduleFilter' => array(
  127. 'packageIDs' => $package_ids,
  128. 'enabledCounts' => $enabled_counts,
  129. )
  130. ), 'setting');
  131. }
  132. // Add first and last class to rows.
  133. $rows[0]['class'][] = 'first';
  134. $rows[count($rows) - 1]['class'][] = 'last';
  135. $output = '<div id="module-filter-wrapper">';
  136. $output .= '<div id="module-filter-modules">' . drupal_render($form['module_filter']);
  137. $output .= theme('table', array('header' => $header, 'rows' => $rows));
  138. $output .= drupal_render_children($form);
  139. $output .= '</div>';
  140. $output .= '</div>';
  141. return $output;
  142. }
  143. function theme_module_filter_operations(&$vars) {
  144. $links = &$vars['links'];
  145. $dropbutton = $vars['dropbutton'];
  146. $operations = array();
  147. foreach (element_children($links) as $key) {
  148. if ($dropbutton) {
  149. hide($links[$key]);
  150. if (!empty($links[$key]['#href'])) {
  151. $operations[] = array(
  152. 'title' => $links[$key]['#title'],
  153. 'href' => $links[$key]['#href'],
  154. );
  155. }
  156. }
  157. else {
  158. $data = drupal_render($links[$key]);
  159. if (!empty($data)) {
  160. $operations[] = array('data' => $data);
  161. }
  162. }
  163. }
  164. if (!empty($operations)) {
  165. if ($dropbutton) {
  166. return '<div class="admin-operations">' . theme('links__ctools_dropbutton', array('title' => t('Operations'), 'links' => $operations, 'attributes' => array('class' => array('links')))) . '</div>';
  167. }
  168. return '<div class="admin-operations">' . theme('item_list', array('items' => $operations, 'attributes' => array('class' => array('links', 'inline')))) . '</div>';
  169. }
  170. }