123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186 |
- <?php
- /**
- * @file
- * Modules weight functionlity implementation.
- */
- /**
- * Implements hook_menu().
- */
- function modules_weight_menu() {
- $items = array();
- $items['admin/config/system/modules-weight'] = array(
- 'title' => 'Modules Weight',
- 'description' => 'Provide admin interface to order the modules execution.',
- 'type' => MENU_NORMAL_ITEM,
- 'page callback' => 'drupal_get_form',
- 'page arguments' => array('modules_weight_admin_config_page_form'),
- 'access arguments' => array('administer site configuration'),
- );
- $items['admin/config/system/modules-weight/default'] = array(
- 'title' => 'Modules Weight',
- 'description' => 'jQuery twitter search block config',
- 'type' => MENU_DEFAULT_LOCAL_TASK,
- 'weight' => 2,
- );
- $items['admin/config/system/modules-weight/configration'] = array(
- 'title' => 'Modules Weight configurations',
- 'description' => 'Configure Modules Weight.',
- 'page callback' => 'drupal_get_form',
- 'page arguments' => array('modules_weight_configuration_form'),
- 'access arguments' => array('administer system'),
- 'type' => MENU_LOCAL_TASK,
- 'weight' => 2,
- );
- return $items;
- }
- function modules_weight_admin_config_page_form($form, &$form_state) {
- $form['modules_weight']['#tree'] = TRUE;
- $result = db_select('system', 's')
- ->condition('s.type', 'module')
- ->condition('s.status', 1)
- ->fields('s', array('weight', 'info', 'name'))
- ->orderBy('weight', 'ASC')
- ->execute();
- $show_system_module = variable_get('show_system_modules', 0);
- foreach ($result as $module) {
- $info = unserialize($module->info);
- if ($info['package'] != 'Core' || $show_system_module) {
- $delta = modules_weight_prepare_delta($module->weight);
- $form['modules_weight'][$module->name] = array(
- 'name' => array(
- '#markup' => t($info['name']),
- ),
- 'description' => array(
- '#markup' => t($info['description']),
- ),
- 'weight' => array(
- '#type' => 'weight',
- '#title' => t('Weight'),
- '#default_value' => $module->weight,
- '#delta' => $delta,
- '#title-display' => 'invisible',
- ),
- 'package' => array(
- '#markup' => t($info['package']),
- ),
- 'old_weight_value' => array(
- '#type' => 'hidden',
- '#value' => $module->weight,
- ),
- );
- }
- }
- $form['actions'] = array('#type' => 'actions');
- $form['actions']['submit'] = array('#type' => 'submit', '#value' => t('Save Changes'));
- return $form;
- }
- /**
- * Implements hook_theme().
- */
- function modules_weight_theme() {
- return array(
- 'modules_weight_admin_config_page_form' => array(
- 'render element' => 'form',
- ),
- );
- }
- function theme_modules_weight_admin_config_page_form($variables) {
- $form = $variables['form'];
- $rows = array();
- foreach (element_children($form['modules_weight']) as $id) {
- $form['modules_weight'][$id]['weight']['#attributes']['class'] = array('module-weight');
- $rows[] = array(
- 'data' => array(
- drupal_render($form['modules_weight'][$id]['name']),
- drupal_render($form['modules_weight'][$id]['description']),
- drupal_render($form['modules_weight'][$id]['weight']),
- drupal_render($form['modules_weight'][$id]['package']),
- ),
- 'class' => array('draggable'),
- );
- }
- $header = array(t('Name'), t('Description'), t('Weight'), t('Package'));
- $table_id = 'module-items-table';
- $output = theme('table', array(
- 'header' => $header,
- 'rows' => $rows,
- 'attributes' => array('id' => $table_id),
- ));
- $output .= drupal_render_children($form);
- //Remove tabledrage functionlity due to issue related to re-weight all module
- // for more info : https://www.drupal.org/node/2205787
-
- //drupal_add_tabledrag($table_id, 'order', 'self', 'module-weight');
- return $output;
- }
- /**
- * Submit callback for the modules_weight_admin_config_page_form form.
- *
- * Updates the 'weight' column for each module in our table, taking into
- * account that item's new order after the drag and drop actions have been
- * performed.
- */
- function modules_weight_admin_config_page_form_submit($form, $form_state) {
- foreach ($form_state['values']['modules_weight'] as $name => $weight) {
- if($weight['weight'] != $weight['old_weight_value']) {
- db_query(
- "UPDATE {system} SET weight = :weight WHERE name = :name",
- array(':weight' => $weight['weight'], ':name' => $name)
- );
- }
- }
- }
- function modules_weight_configuration_form() {
- $form = array();
- $form['show_system_modules'] = array(
- '#type' => 'checkbox',
- '#title' => t('Show system modules'),
- '#return_value' => 1,
- '#default_value' => variable_get('show_system_modules', 0),
- );
- $form['notice'] = array(
- '#markup' => '<strong>' . t("cautions: This module just display non-core module by, if you check this option it will cause unexpected behavior in system, (USE IT ON YOUR OWN RISCK) that's because displaying core module in the configuration form will reorder the system core modules execution even if you didn't change them and as you might notice all core modules has 0 weight value by default.") . '',
- );
- return system_settings_form($form);
- }
- /**
- * Prepares the delta for the weight field on the administration form.
- * If a module has a weight higher then 100 (or lower than 100), it will use that
- * value as delta and the '#weight' field will turn into a textfield most likely
- *
- * @param $weight
- * @return int
- */
- function modules_weight_prepare_delta($weight) {
- $delta = 100;
- if ((int) $weight > $delta) {
- return (int) $weight;
- }
- if ((int) $weight < -100) {
- return (int) $weight * -1;
- }
- return $delta;
- }
|