Fix for Module for setting a separate permission for theme management

  1. <?php
  2. // $Id$
  3.  
  4. /*
  5.  * Created by Greg Harvey on 20 Oct 2009
  6.  *
  7.  * http://www.drupaler.co.uk
  8.  */
  9.  
  10. /**
  11.  * Implementation of hook_perm().
  12.  *
  13.  * Provide a new permission for theme admin access.
  14.  */
  15. function access_theme_settings_perm() {
  16.   return array(
  17.     'administer default theme settings',
  18.   );
  19. }
  20.  
  21. /**
  22.  * Implementation of hook_menu_alter().
  23.  *
  24.  * Altering the theme settings menu items so they have
  25.  * their own permission.
  26.  */
  27. function access_theme_settings_menu_alter(&$items) {
  28.  
  29.   // Get the full system file path to the include file.
  30.   $file = './' . drupal_get_path('module', 'system') . '/system.admin.inc';
  31.   $file = realpath($file);
  32.  
  33.   // Re-define all theme admin menu items using the old access argument.
  34.   // We need to rebuild totally - for some reason hook_menu() "forgets"
  35.   // values set in system.module.
  36.   $items['admin/build/themes'] = array(
  37.     'title' => 'Themes',
  38.     'description' => 'Change which theme your site uses or allows users to set.',
  39.     'page callback' => 'drupal_get_form',
  40.     'page arguments' => array('system_themes_form', NULL),    
  41.     'access arguments' => array('administer default theme settings'),
  42.     'file' => $file,
  43.   );
  44.   $items['admin/build/themes/settings'] = array(
  45.     'title' => 'Configure',
  46.     'page arguments' => array('system_theme_settings'),
  47.     'access arguments' => array('administer default theme settings'),
  48.     'type' => MENU_LOCAL_TASK,
  49.   );
  50.  
  51.   foreach (list_themes() as $theme) {
  52.     $items['admin/build/themes/settings/'. $theme->name] = array(
  53.       'title' => $theme->info['name'],
  54.       'page arguments' => array('system_theme_settings', $theme->name),
  55.       'type' => MENU_LOCAL_TASK,
  56.       'access callback' => '_access_theme_settings_themes_access',
  57.       'access arguments' => array($theme),
  58.     );
  59.   }
  60. }
  61.  
  62. /**
  63.  * Menu item access callback - only admin or enabled themes can be accessed.
  64.  *
  65.  * Overrides _system_themes_access().
  66.  */
  67. function _access_theme_settings_themes_access($theme) {
  68.   return user_access('administer default theme settings') && ($theme->status || $theme->name == variable_get('admin_theme', '0'));
  69. }

Submit Fix

Any tags you'd like to associate with your code, delimitered by commas (example: Views, CCK, Module, etc).
Select the syntax highlighting mode to use.