Projet

Général

Profil

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

root / htmltest / sites / all / modules / module_filter / module_filter.module @ dc45a079

1
<?php
2

    
3
/**
4
 * @file
5
 * This is the file description for Module Filter module.
6
 *
7
 * In this more verbose, multi-line description, you can specify what this
8
 * file does exactly. Make sure to wrap your documentation in column 78 so
9
 * that the file can be displayed nicely in default-sized consoles.
10
 *
11
 * @author greenSkin
12
 */
13

    
14
/**
15
 * Implementation of hook_perm().
16
 */
17
function module_filter_permission() {
18
  return array(
19
    'administer module filter' => array(
20
      'title' => t('Administer Module Filter'),
21
      'description' => t('Configure how Module Filter performs.')
22
    )
23
  );
24
}
25

    
26
/**
27
 * Implementation of hook_menu().
28
 */
29
function module_filter_menu() {
30
  $items['admin/config/user-interface/modulefilter'] = array(
31
    'title' => 'Module filter',
32
    'description' => 'Configure settings for Module Filter.',
33
    'access arguments' => array('administer module filter'),
34
    'page callback' => 'drupal_get_form',
35
    'page arguments' => array('module_filter_settings'),
36
    'file' => 'module_filter.admin.inc'
37
  );
38
  return $items;
39
}
40

    
41
/**
42
 * Implementation of hook_form_FORM_ID_alter().
43
 */
44
function module_filter_form_system_modules_alter(&$form, &$form_state, $form_id) {
45
  // Don't alter the form when confirming.
46
  if (isset($form['confirm'])) {
47
    return;
48
  }
49

    
50
  $form['module_filter'] = array(
51
    '#tree' => TRUE,
52
    '#weight' => -1,
53
    '#attached' => array(
54
      'css' => array(
55
        drupal_get_path('module', 'module_filter') .'/css/module_filter.css',
56
      ),
57
    ),
58
  );
59
  $form['module_filter']['name'] = array(
60
    '#type' => 'textfield',
61
    '#title' => t('Filter list')
62
  );
63

    
64
  $form['module_filter']['show'] = array(
65
    '#type' => 'checkboxes',
66
    '#default_value' => array('enabled', 'disabled', 'required', 'unavailable'),
67
    '#options' => array('enabled' => t('Enabled'), 'disabled' => t('Disabled'), 'required' => t('Required'), 'unavailable' => t('Unavailable')),
68
    '#prefix' => '<div id="module-filter-show-wrapper">',
69
    '#suffix' => '</div>'
70
  );
71

    
72
  if (variable_get('module_filter_tabs', 1)) {
73
    $form['module_filter']['#attached']['css'][] = drupal_get_path('module', 'module_filter') .'/css/module_filter_tab.css';
74
    $form['module_filter']['#attached']['js'][] = drupal_get_path('module', 'module_filter') .'/js/module_filter_tab.js';
75
    $form['module_filter']['#attached']['js'][] = array(
76
      'data' => array('moduleFilter' => array('visualAid' => variable_get('module_filter_visual_aid', 1))),
77
      'type' => 'setting',
78
    );
79

    
80
    if (variable_get('module_filter_dynamic_save_position', 0)) {
81
      $form['module_filter']['#attached']['js'][] = drupal_get_path('module', 'module_filter') .'/js/dynamic_position.js';
82
    }
83

    
84
    $form['module_filter']['#size'] = 45;
85

    
86
    // Remove the fieldsets for each package since we will be using tabs
87
    // instead. Put all modules into one array.
88
    $modules = array(
89
      '#theme' => 'module_filter_modules_table',
90
      '#header' => array(
91
        array('data' => t('Enabled'), 'class' => 'checkbox'),
92
        t('Name'),
93
        t('Version'),
94
        t('Description'),
95
        array('data' => t('Operations'), 'colspan' => 3)
96
      )
97
    );
98

    
99
    $all = t('All');
100
    $tab_counts = array($all => array('id' => 'all', 'enabled' => 0, 'total' => 0));
101
    $form['#packages'] = array();
102
    foreach (element_children($form['modules']) as $package) {
103
      // Add the package to $form['#packages']. Tabs are built from this.
104
      $form['#packages'][$package] = $package;
105

    
106
      if (!isset($tab_counts[$package])) {
107
        $tab_counts[$package] = array('enabled' => 0, 'total' => 0);
108
      }
109

    
110
      foreach (element_children($form['modules'][$package]) as $module) {
111
        $tab_counts[$all]['total']++;
112
        $tab_counts[$package]['total']++;
113
        if (!empty($form['modules'][$package][$module]['enable']['#default_value'])) {
114
          $tab_counts[$all]['enabled']++;
115
          $tab_counts[$package]['enabled']++;
116
        }
117

    
118
        $modules[$module] = $form['modules'][$package][$module];
119
        $modules[$module]['#package'] = $package;
120
        $modules[$module]['#parents'] = array('modules', $package, $module);
121
      }
122
    }
123

    
124
    // Sort the array of modules alphabetically.
125
    uasort($modules, 'module_filter_sort_modules_by_display_name');
126

    
127
    // Replace the $form['modules'] with our $modules array.
128
    $form['modules'] = $modules;
129

    
130
    // Add our $tab_counts array to the form.
131
    $form['#tab_counts'] = $tab_counts;
132

    
133
    $form['#theme'] = 'module_filter_system_modules_tabs';
134
  }
135
  else {
136
    $form['module_filter']['#attached']['js'][] = drupal_get_path('module', 'module_filter') .'/js/module_filter.js';
137
    $form['module_filter']['#prefix'] = '<div id="module-filter-wrapper" style="display: none;">';
138
    $form['module_filter']['#suffix'] = '</div>';
139
  }
140
}
141

    
142
/**
143
 * Implementation of hook_theme().
144
 */
145
function module_filter_theme() {
146
  return array(
147
    'module_filter_modules_table' => array(
148
      'render element' => 'form',
149
      'file' => 'module_filter.theme.inc',
150
    ),
151
    'module_filter_system_modules_tabs' => array(
152
      'render element' => 'form',
153
      'file' => 'module_filter.theme.inc'
154
    )
155
  );
156
}
157

    
158
function module_filter_sort_modules_by_display_name($a, $b) {
159
  if (is_array($a) && is_array($b) && isset($a['#package'], $b['#package'])) {
160
    return strcasecmp($a['name']['#markup'], $b['name']['#markup']);
161
  }
162
  return 0;
163
}
164

    
165
function module_filter_get_id($text) {
166
  $id = strtolower($text);
167
  return preg_replace('/([^a-z])([\/(  )])*/', '-', $id);
168
}