| 1 |
<?php
|
| 2 |
// $Id: moduleweight.module,v 1.4 2007/05/18 15:06:19 darrenoh Exp $
|
| 3 |
|
| 4 |
/**
|
| 5 |
* Implementation of hook_help().
|
| 6 |
*/
|
| 7 |
function moduleweight_help($section) {
|
| 8 |
$output = '';
|
| 9 |
switch ($section) {
|
| 10 |
case 'admin/help#moduleweight':
|
| 11 |
$output .= '<p>'. t('Drupal assigns each module a weight. For most operations involving any module that defines a particular hook, the modules are invoked in order first by weight, then by name.') .'</p>';
|
| 12 |
$output .= '<p>'. t('This module adds a weight column to the modules table at !modules, allowing weights to be viewed and edited. Once activated, a weight column appears on the modules table. To change a module weight, edit its value and press "Save configuration". Any user who can submit the !modules form will be able to change module weights.', array('!modules' => l('admin/build/modules', 'admin/build/modules'))) .'</p>';
|
| 13 |
break;
|
| 14 |
}
|
| 15 |
return $output;
|
| 16 |
}
|
| 17 |
|
| 18 |
/**
|
| 19 |
* Implementation of hook_form_alter().
|
| 20 |
*
|
| 21 |
* Alter the system_modules form to include fields for module weight. Use
|
| 22 |
* #pre_render to set #theme after drupal_get_form() does. Use #submit to
|
| 23 |
* get invoked when the form is submitted.
|
| 24 |
*/
|
| 25 |
function moduleweight_form_alter($form_id, &$form) {
|
| 26 |
switch ($form_id) {
|
| 27 |
case 'system_modules':
|
| 28 |
$result = db_query("SELECT name, weight FROM {system} WHERE type = 'module'");
|
| 29 |
while ($row = db_fetch_object($result)) {
|
| 30 |
if (isset($form['name'][$row->name])) {
|
| 31 |
$form['weight'][$row->name] = array(
|
| 32 |
'#type' => 'textfield',
|
| 33 |
'#size' => 3,
|
| 34 |
'#default_value' => $row->weight
|
| 35 |
);
|
| 36 |
}
|
| 37 |
}
|
| 38 |
$form['#theme'] = 'moduleweight_system_modules';
|
| 39 |
$form['weight']['#tree'] = TRUE;
|
| 40 |
foreach ($form['name'] as $module => $values) {
|
| 41 |
$modules[$module] = $values['#value'];
|
| 42 |
}
|
| 43 |
$form['weight']['#validate'] = array('_moduleweight_validate' => array('names' => $modules));
|
| 44 |
// Do my #submit before system.module's so all the rebuilding
|
| 45 |
// operations in system_module_submit use the new weights.
|
| 46 |
$form['#submit'] = array('_moduleweight_submit' => array()) + (array) $form['#submit'];
|
| 47 |
break;
|
| 48 |
}
|
| 49 |
}
|
| 50 |
|
| 51 |
/**
|
| 52 |
* Make sure each module weight is a numeric value.
|
| 53 |
*/
|
| 54 |
function _moduleweight_validate($args) {
|
| 55 |
foreach ($args['#post']['weight'] as $module => $weight) {
|
| 56 |
if (!is_numeric($weight)) {
|
| 57 |
form_set_error("weight][$module", t(
|
| 58 |
'The !module module weight must be a number.',
|
| 59 |
array('!module' => $args['#validate']['_moduleweight_validate']['names'][$module])
|
| 60 |
));
|
| 61 |
}
|
| 62 |
}
|
| 63 |
}
|
| 64 |
|
| 65 |
/**
|
| 66 |
* Submit module weights.
|
| 67 |
*/
|
| 68 |
function _moduleweight_submit($form_id, &$form_values) {
|
| 69 |
foreach ($form_values['weight'] as $module => $weight) {
|
| 70 |
db_query("UPDATE {system} SET weight = %d WHERE type = 'module' and name = '%s'", $weight, $module);
|
| 71 |
}
|
| 72 |
}
|
| 73 |
|
| 74 |
/**
|
| 75 |
* Custom theme function for the system_modules form.
|
| 76 |
*/
|
| 77 |
function theme_moduleweight_system_modules($form) {
|
| 78 |
if (isset($form['confirm'])) {
|
| 79 |
return drupal_render($form);
|
| 80 |
}
|
| 81 |
$header = array(t('Enabled'));
|
| 82 |
if (module_exists('throttle')) {
|
| 83 |
$header[] = t('Throttle');
|
| 84 |
}
|
| 85 |
$header[] = t('Weight');
|
| 86 |
$header[] = t('Name');
|
| 87 |
$header[] = t('Version');
|
| 88 |
$header[] = t('Description');
|
| 89 |
$modules = $form['validation_modules']['#value'];
|
| 90 |
foreach ($modules as $module) {
|
| 91 |
if (!isset($module->info['package']) || !$module->info['package']) {
|
| 92 |
$module->info['package'] = t('Other');
|
| 93 |
}
|
| 94 |
$packages[$module->info['package']][$module->name] = $module->info;
|
| 95 |
}
|
| 96 |
ksort($packages);
|
| 97 |
$output = '';
|
| 98 |
foreach ($packages as $package => $modules) {
|
| 99 |
$rows = array();
|
| 100 |
foreach ($modules as $key => $module) {
|
| 101 |
$row = array();
|
| 102 |
$row[] = array('data' => drupal_render($form['status'][$key]), 'align' => 'center');
|
| 103 |
if (module_exists('throttle')) {
|
| 104 |
$row[] = array('data' => drupal_render($form['throttle'][$key]), 'align' => 'center');
|
| 105 |
}
|
| 106 |
$row[] = drupal_render($form['weight'][$key]);
|
| 107 |
$row[] = '<strong>'. drupal_render($form['name'][$key]) .'</strong>';
|
| 108 |
$row[] = drupal_render($form['version'][$key]);
|
| 109 |
$row[] = array('data' => drupal_render($form['description'][$key]), 'class' => 'description');
|
| 110 |
$rows[] = $row;
|
| 111 |
}
|
| 112 |
$fieldset = array(
|
| 113 |
'#title' => t($package),
|
| 114 |
'#collapsible' => TRUE,
|
| 115 |
'#collapsed' => ($package == 'Core - required'),
|
| 116 |
'#value' => theme('table', $header, $rows, array('class' => 'package')),
|
| 117 |
);
|
| 118 |
$output .= theme('fieldset', $fieldset);
|
| 119 |
}
|
| 120 |
$output .= drupal_render($form);
|
| 121 |
return $output;
|
| 122 |
}
|
| 123 |
|