You are here

function admin_menu_toggle_modules in Administration menu 5.2

Same name and namespace in other branches
  1. 5.3 admin_menu.module \admin_menu_toggle_modules()
  2. 6.3 admin_menu.inc \admin_menu_toggle_modules()
  3. 6 admin_menu.inc \admin_menu_toggle_modules()

Menu callback to enable/disable developer modules.

This saves up to 150ms on each uncached page request. Not much, but on larger Drupal sites this is actually a 10% performance increase.

1 string reference to 'admin_menu_toggle_modules'
admin_menu_menu in ./admin_menu.module
Implementation of hook_menu().

File

./admin_menu.module, line 520
Renders a menu tree for administrative purposes as dropdown menu at the top of the window.

Code

function admin_menu_toggle_modules() {
  $saved_state = variable_get('admin_menu_devel_modules_enabled', NULL);
  if (isset($saved_state)) {

    // Re-enable modules that were enabled before.
    module_enable($saved_state);
    variable_del('admin_menu_devel_modules_enabled');
    drupal_set_message(t('Re-enabled these modules: !module-list.', array(
      '!module-list' => implode(', ', $saved_state),
    )));
  }
  else {

    // Allow site admins to override this variable via settings.php.
    $devel_modules = variable_get('admin_menu_devel_modules', array(
      'cache_disable',
      'coder',
      'content_copy',
      'debug',
      'delete_all',
      'demo',
      'devel',
      'devel_node_access',
      'devel_themer',
      'macro',
      'form_controller',
      'imagecache_ui',
      'journal',
      'trace',
      'upgrade_status',
      'user_display_ui',
      'util',
      'views_ui',
      'views_theme_wizard',
    ));

    // Store currently enabled modules in a variable.
    $devel_modules = array_intersect(module_list(FALSE, FALSE), $devel_modules);
    if (!empty($devel_modules)) {
      variable_set('admin_menu_devel_modules_enabled', $devel_modules);

      // Disable developer modules.
      module_disable($devel_modules);
      drupal_set_message(t('Disabled these modules: !module-list.', array(
        '!module-list' => implode(', ', $devel_modules),
      )));
    }
    else {
      drupal_set_message(t('No developer modules are enabled.'));
    }
  }
  drupal_goto(referer_uri());
}