-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodules_weight.module
More file actions
126 lines (110 loc) · 3.16 KB
/
modules_weight.module
File metadata and controls
126 lines (110 loc) · 3.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
<?php
/**
* Implementation of hook_permission().
*/
function modules_weight_permission() {
return array(
'access modules weight' => array(
'title' => t('Access Module Weights'),
'description' => t('Access the Module Weights admin section.'),
),
);
}
/**
* Implementation of hook_menu().
*/
function modules_weight_menu(){
$items=Array();
$items['admin/config/system/module_weight']=Array(
'title' => t('Module Weights'),
'description' => '',
'page callback' => 'drupal_get_form',
'page arguments' => array('modules_weight_form'),
'access arguments' => array('access modules weight'),
);
return $items;
}
/**
* Implementation of hook_theme().
*/
function modules_weight_theme($existing, $type, $theme, $path) {
return array(
'modules_weight_form' => array(
'arguments' => array('form' => NULL),
'render element' => 'form',
),
);
}
function modules_weight_form($form_state){
$modules=Array();
foreach(module_list(true) as $module){
if($module=='standard') continue;
$res=db_query("SELECT `weight`,`info` FROM {system} WHERE `type`=:type AND `name`=:name LIMIT 1",Array(':type'=>'module',':name'=>$module));
foreach($res as $obj){
$w=$obj->weight;
$infos=unserialize($obj->info);
$name=$infos['name'];
$desc=$infos['description'];
$modules[]=Array(
'machine_name'=>$module,
'weight'=>$w,
'name'=>$name,
'description'=>$desc,
);
}
}
$form=Array();
foreach($modules as $module){
$form['module_'.$module['machine_name']]=Array(
'#type'=>'textfield',
'#title'=>$module['name'],
'#description'=>$module['description'],
'#default_value'=>$module['weight'],
'#attributes'=>Array('class'=> Array('my-elements-weight')),
);
}
$form['submit']=Array(
'#type'=>'submit',
'#value'=>t('Submit'),
);
//$form['#theme'] = 'modules_weight_form';
$form['#submit'][] = 'modules_weight_form_submit';
return $form;
}
function theme_modules_weight_form($variables) {
$form=$variables['form'];
drupal_add_tabledrag('modules-weight-table', 'order', 'sibling', 'my-elements-weight');
$header=Array(t('Machine Name'),t('Module'),t('Weight'));
$rows=Array();
foreach($form as $key=>&$elem){
if(strpos($key,"module_")===0){
$cell1=preg_replace("/^module_/","",$key);
$cell2=$elem['#title'].'<br />'.$elem['#description'];
$elem['#title']='';$elem['#description']='';
$cell3="";
$cell3=drupal_render($elem);
$row=Array(Array('data'=>$cell1),Array('data'=>$cell2),Array('data'=>$cell3));
$rows[] = array(
'data' => $row,
'class' => array('draggable'),
);
}
}
//var_dump($form);die();
$output = theme('table', array('header' => $header, 'rows' => $rows, 'attributes' => array('id' => 'modules-weight-table')));
$output .= drupal_render_children($form);
return $output;
}
function modules_weight_form_submit($form,$form_state){
foreach($form_state['values'] as $key=>$weight){
if(strpos($key,"module_")===0 && is_numeric($weight)){
$modulename=preg_replace("/^module_/","",$key);
if(trim($modulename)=='') continue;
db_update('system')
->fields(array('weight' => $weight))
->condition('name', $modulename, '=')
->execute();
}
}
drupal_flush_all_caches();
}