Projet

Général

Profil

Paste
Télécharger (8,17 ko) Statistiques
| Branche: | Révision:

root / drupal7 / sites / all / modules / module_filter / module_filter.theme.inc @ 18596a08

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
  if (variable_get('module_filter_version_column', 0)) {
41
    array_splice($header, 2, 0, array(array('data' => t('Version'), 'class' => array('version'))));
42
  }
43
  $package_ids = array('all');
44
  $enabled['all'] = array();
45

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

    
51
    $package_ids[] = 'recent';
52
    $enabled['recent'] = array();
53
  }
54

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

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

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

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

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

    
84
      $row = array();
85

    
86
      $version = !empty($module['version']['#markup']);
87
      $requires = !empty($module['#requires']);
88
      $required_by = !empty($module['#required_by']);
89

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

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

    
107
      if (variable_get('module_filter_version_column', 0) && $version) {
108
        $row[] = array('class' => array('version'), 'data' => drupal_render($module['version']));
109
      }
110

    
111
      // Add the description, along with any modules it requires.
112
      if (empty($module['description']['#markup'])) {
113
        $module['description']['#markup'] = '<em>' . t('No description available.') . '</em>';
114
      }
115
      $description = '<span class="details"><span class="text">' . drupal_render($module['description']) . '</span></span>';
116
      if ($requires || $required_by || (!variable_get('module_filter_version_column', 0) && $version)) {
117
        $description .= '<div class="requirements">';
118
        if (!variable_get('module_filter_version_column', 0) && $version) {
119
          $description .= '<div class="admin-requirements">' . t('Version: !module-version', array('!module-version' => drupal_render($module['version']))) . '</div>';
120
        }
121
        if ($requires) {
122
          $description .= '<div class="admin-requirements">' . t('Requires: !module-list', array('!module-list' => implode(', ', $module['#requires']))) . '</div>';
123
        }
124
        if ($required_by) {
125
          $description .= '<div class="admin-requirements">' . t('Required by: !module-list', array('!module-list' => implode(', ', $module['#required_by']))) . '</div>';
126
        }
127
        $description .= '</div>';
128
      }
129
      $row[] = array('data' => '<div class="inner expand" role="button">' . $description . '</div>', 'class' => array('description'));
130

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

    
134
      $class = array(module_filter_get_id($package) . '-tab', 'module', $stripe);
135
      if (isset($recent_modules[$key])) {
136
        $class[] = 'recent-module';
137
      }
138
      if (isset($new_modules[$key])) {
139
        $class[] = 'new-module';
140
      }
141
      $rows[] = array('data' => $row, 'no_striping' => TRUE, 'class' => $class);
142
      $stripe = $flip[$stripe];
143
    }
144

    
145
    // Set the package as printed.
146
    $form['modules'][$package]['#printed'] = TRUE;
147
  }
148

    
149
  //Get packages and count number of modules
150
  $enabled_counts = array();
151
  foreach ($enabled as $package_id => $value) {
152
    $enabled_counts[$package_id] = array(
153
      'enabled' => count(array_filter($value)),
154
      'total' => count($value),
155
    );
156
  }
157
  drupal_add_js(array(
158
    'moduleFilter' => array(
159
      'packageIDs' => $package_ids,
160
      'enabledCounts' => $enabled_counts,
161
    )
162
  ), 'setting');
163

    
164
  // Add first and last class to rows.
165
  $rows[0]['class'][] = 'first';
166
  $rows[count($rows) - 1]['class'][] = 'last';
167

    
168
  $output = '<div id="module-filter-wrapper">';
169
  $output .= '<div id="module-filter-modules">' . drupal_render($form['module_filter']);
170
  $output .= theme('table', array('header' => $header, 'rows' => $rows));
171
  $output .= drupal_render_children($form);
172
  $output .= '</div>';
173
  $output .= '</div>';
174
  return $output;
175
}
176

    
177
/**
178
 * Theme function for module filter operations.
179
 * @param $variables
180
 * @return
181
 *   HTML for admin status operations.
182
 */
183
function theme_module_filter_operations(&$vars) {
184
  $links = &$vars['links'];
185
  $dropbutton = $vars['dropbutton'];
186

    
187
  $operations = array();
188
  foreach (element_children($links) as $key) {
189
    if ($dropbutton) {
190
      hide($links[$key]);
191
      if (!empty($links[$key]['#href'])) {
192
        $operations[$key] = array(
193
          'title' => $links[$key]['#title'],
194
          'href' => $links[$key]['#href'],
195
        );
196
        if (isset($links[$key]['#options'])) {
197
          $operations[$key] += $links[$key]['#options'];
198
        }
199
      }
200
    }
201
    else {
202
      $data = drupal_render($links[$key]);
203
      if (!empty($data)) {
204
        $operations[$key] = array('data' => $data);
205
      }
206
    }
207
  }
208
  if (!empty($operations)) {
209
    if ($dropbutton) {
210
      return '<div class="admin-operations">' . theme('links__ctools_dropbutton', array('title' => t('Operations'), 'links' => $operations, 'attributes' => array('class' => array('links')))) . '</div>';
211
    }
212
    return '<div class="admin-operations">' . theme('item_list', array('items' => $operations, 'attributes' => array('class' => array('links', 'inline')))) . '</div>';
213
  }
214
}