Projet

Général

Profil

Paste
Télécharger (7,38 ko) Statistiques
| Branche: | Révision:

root / drupal7 / sites / all / modules / module_filter / module_filter.theme.inc @ 7d7b5830

1
<?php
2

    
3
/**
4
 * @file
5
 *
6
 * @author greenSkin
7
 */
8

    
9
function theme_module_filter($variables) {
10
  $element = $variables['element'];
11
  return '<div class="module-filter-inputs-wrapper">' . drupal_render_children($element) . '</div>';
12
}
13

    
14
/**
15
 * Theme callback for the modules tabbed form.
16
 */
17
function theme_module_filter_system_modules_tabs($variables) {
18
  if (module_exists('views_ui')) {
19
    // Hack to get consistent style with views ctools dropbutton.
20
    if (module_load_include('inc', 'views_ui', 'includes/admin')) {
21
      foreach (views_ui_get_admin_css() as $file => $options) {
22
        drupal_add_css($file, $options);
23
      }
24
    }
25
  }
26

    
27
  $form = $variables['form'];
28

    
29
  if (!module_exists('page_actions')) {
30
    $form['actions']['#prefix'] = '<div id="module-filter-submit">';
31
    $form['actions']['#suffix'] = '</div>';
32
  }
33

    
34
  $header = array(
35
    array('data' => '', 'class' => array('checkbox')),
36
    array('data' => t('Name'), 'class' => array('name')),
37
    array('data' => t('Description'), 'class' => array('description')),
38
    array('data' => t('Links'), 'class' => array('links')),
39
  );
40
  $package_ids = array('all');
41
  $enabled['all'] = array();
42

    
43
  if (variable_get('module_filter_track_recent_modules', 1)) {
44
    $recent_modules = array_filter(variable_get('module_filter_recent_modules', array()), 'module_filter_recent_filter');
45
    // Save the filtered results.
46
    variable_set('module_filter_recent_modules', $recent_modules);
47

    
48
    $package_ids[] = 'recent';
49
    $enabled['recent'] = array();
50
  }
51

    
52
  // Determine what modules are new (within a week).
53
  $new_modules = module_filter_new_modules();
54
  $package_ids[] = 'new';
55
  $enabled['new'] = array();
56

    
57
  $rows = array();
58
  $flip = array('even' => 'odd', 'odd' => 'even');
59
  foreach (element_children($form['modules']) as $package) {
60
    $package_id = module_filter_get_id($package);
61
    $package_ids[] = $package_id;
62

    
63
    // Package title and header.
64
    $rows[] = array('data' => array(array('data' => '<h3>' . $form['modules'][$package]['#title'] . '</h3>', 'colspan' => 4)), 'id' => $package_id . '-package', 'class' => array('admin-package-title'));
65
    $rows[] = array('data' => $header, 'class' => array('admin-package-header'));
66

    
67
    $stripe = 'odd';
68
    $enabled[$package_id] = array();
69
    foreach (element_children($form['modules'][$package]) as $key) {
70
      $module = &$form['modules'][$package][$key];
71

    
72
      $is_enabled = isset($module['enable']['#default_value']) ? $module['enable']['#default_value'] : '';
73
      $enabled['all'][] = $enabled[$package_id][] = $is_enabled;
74
      if (isset($recent_modules[$key])) {
75
        $enabled['recent'][] = $is_enabled;
76
      }
77
      if (isset($new_modules[$key])) {
78
        $enabled['new'][] = $is_enabled;
79
      }
80

    
81
      $row = array();
82

    
83
      $version = !empty($module['version']['#markup']);
84
      $requires = !empty($module['#requires']);
85
      $required_by = !empty($module['#required_by']);
86

    
87
      $toggle_enable = '';
88
      if (isset($module['enable']['#type']) && $module['enable']['#type'] == 'checkbox') {
89
        unset($module['enable']['#title']);
90
        $class = ($is_enabled ? 'enabled' : 'off');
91
        if (!empty($module['enable']['#disabled'])) {
92
          $class .= ' disabled';
93
        }
94
        $toggle_enable = '<div class="js-hide toggle-enable ' . $class . '"><div>&nbsp;</div></div>';
95
      }
96
      $row[] = array('class' => array('checkbox'), 'data' => $toggle_enable . drupal_render($module['enable']));
97

    
98
      $label = '<label';
99
      if (isset($module['enable']['#id'])) {
100
        $label .= ' for="' . $module['enable']['#id'] . '"';
101
      }
102
      $row[] = array('class' => array('name'), 'data' => $label . '><strong>' . drupal_render($module['name']) . '</strong> <span class="module-machine-name">(' . $key . ')</span></label>');
103

    
104
      // Add the description, along with any modules it requires.
105
      $description = '<span class="details"><span class="text">' . drupal_render($module['description']) . '</span></span>';
106
      if ($version || $requires || $required_by) {
107
        $description .= '<div class="requirements">';
108
        if ($version) {
109
          $description .= '<div class="admin-requirements">' . t('Version: !module-version', array('!module-version' => drupal_render($module['version']))) . '</div>';
110
        }
111
        if ($requires) {
112
          $description .= '<div class="admin-requirements">' . t('Requires: !module-list', array('!module-list' => implode(', ', $module['#requires']))) . '</div>';
113
        }
114
        if ($required_by) {
115
          $description .= '<div class="admin-requirements">' . t('Required by: !module-list', array('!module-list' => implode(', ', $module['#required_by']))) . '</div>';
116
        }
117
        $description .= '</div>';
118
      }
119
      $row[] = array('data' => '<div class="inner expand" role="button">' . $description . '</div>', 'class' => array('description'));
120

    
121
      $operations = (module_exists('ctools')) ? theme('module_filter_operations', array('links' => $module['links'], 'dropbutton' => TRUE)) : theme('module_filter_operations', array('links' => $module['links']));
122
      $row[] = array('data' => '<div class="links">' . $operations . '</div>', 'class' => array('links'));
123

    
124
      $class = array(module_filter_get_id($package) . '-tab', 'module', $stripe);
125
      if (isset($recent_modules[$key])) {
126
        $class[] = 'recent-module';
127
      }
128
      if (isset($new_modules[$key])) {
129
        $class[] = 'new-module';
130
      }
131
      $rows[] = array('data' => $row, 'no_striping' => TRUE, 'class' => $class);
132
      $stripe = $flip[$stripe];
133
    }
134

    
135
    // Set the package as printed.
136
    $form['modules'][$package]['#printed'] = TRUE;
137
  }
138

    
139
  if (variable_get('module_filter_count_enabled', 1)) {
140
    $enabled_counts = array();
141
    foreach ($enabled as $package_id => $value) {
142
      $enabled_counts[$package_id] = array(
143
        'enabled' => count(array_filter($value)),
144
        'total' => count($value),
145
      );
146
    }
147
    drupal_add_js(array(
148
      'moduleFilter' => array(
149
        'packageIDs' => $package_ids,
150
        'enabledCounts' => $enabled_counts,
151
      )
152
    ), 'setting');
153
  }
154

    
155
  // Add first and last class to rows.
156
  $rows[0]['class'][] = 'first';
157
  $rows[count($rows) - 1]['class'][] = 'last';
158

    
159
  $output = '<div id="module-filter-wrapper">';
160
  $output .= '<div id="module-filter-modules">' . drupal_render($form['module_filter']);
161
  $output .= theme('table', array('header' => $header, 'rows' => $rows));
162
  $output .= drupal_render_children($form);
163
  $output .= '</div>';
164
  $output .= '</div>';
165
  return $output;
166
}
167

    
168
function theme_module_filter_operations(&$vars) {
169
  $links = &$vars['links'];
170
  $dropbutton = $vars['dropbutton'];
171

    
172
  $operations = array();
173
  foreach (element_children($links) as $key) {
174
    if ($dropbutton) {
175
      hide($links[$key]);
176
      if (!empty($links[$key]['#href'])) {
177
        $operations[] = array(
178
          'title' => $links[$key]['#title'],
179
          'href' => $links[$key]['#href'],
180
        );
181
      }
182
    }
183
    else {
184
      $data = drupal_render($links[$key]);
185
      if (!empty($data)) {
186
        $operations[] = array('data' => $data);
187
      }
188
    }
189
  }
190
  if (!empty($operations)) {
191
    if ($dropbutton) {
192
      return '<div class="admin-operations">' . theme('links__ctools_dropbutton', array('title' => t('Operations'), 'links' => $operations, 'attributes' => array('class' => array('links')))) . '</div>';
193
    }
194
    return '<div class="admin-operations">' . theme('item_list', array('items' => $operations, 'attributes' => array('class' => array('links', 'inline')))) . '</div>';
195
  }
196
}