Admin theme for node (add, edit) and user (edit)

Peter76 - April 3, 2008 - 13:45

I would like to know in which file i must apply this: http://drupal.org/node/122578 ?
Im new at Drupal so I have a lot of problems :)

Anyone?

Peter76 - April 3, 2008 - 16:42

Anyone?

Try this

roopletheme - April 3, 2008 - 18:19

Drupal 5.7 and 6.x already have this feature built in. On the admin/settings/admin page, there's a checkbox to 'use administration theme for content editing'. If you're using an older version of 5.x, then you need the code in the post that you referenced.

To use the code, you need to create a new module. So do this: create a folder called adminedit. In this folder, create two files. The first will be the module info file. Give it a name of adminedit.info, and insert this code:

name = Admin Edit
description = "This module allows editing content with the admin theme."

Give the second file a name of adminedit.module, and insert this code:

<?php
function adminedit_help($section='') {

  $output = '';
  switch ($section) {
    case "admin/help#adminedit":
      $output = '<p>'.  t("Allows editing content using the admin theme"). '</p>';
      break;
  }

  return $output;
} // function adminedit_help

function adminedit_menu() {

if ((arg(0) == 'node' && arg(1) == 'add') ||  (arg(0) == 'node' && arg(2) == 'edit') ||  (arg(0) == 'user' && arg(2) == 'edit') ) {
      global $custom_theme;
      $custom_theme = variable_get('admin_theme', '0');
      drupal_add_css(drupal_get_path('module', 'system') .'/admin.css', 'module');
  }
}

Now copy the adminedit folder to your sites/all/modules folder, enable the module, and you're good to go.

Thanks for help. It

Peter76 - April 3, 2008 - 23:48

Thanks for help. It works.

And just one thing Drupal 5.7 doesnt have this feature built in.

Yep

roopletheme - April 4, 2008 - 00:04

You're right... it was in 5.6, and appears to have been backed out of 5.7.

Timing issue

davej - May 15, 2008 - 18:11

I came across a timing issue with this on one site. On some node/N/edit pages (editing events), init_theme (includes/theme.inc) was being called before the hook_menu function, so the non-admin theme was used. This was fixed by putting the code in hook_init instead of hook_menu. However this may not be suitable if you use aggressive mode caching.

Dave Jenkins
Circle Interactive - UK Drupal development and hosting

Works like a charm! Thank

Bartezz - July 22, 2008 - 13:22

Works like a charm! Thank you very much.

I've changed some of the code to also use admin theme for blocks but I think I did something wrong cause it doesn't work for blocks:

# (arg(0) == 'admin' && arg(1) == 'build' && arg(2) == 'block')
if ((arg(0) == 'admin' && arg(1) == 'build' && arg(2) == 'block') || (arg(0) == 'node' && arg(1) == 'add') ||  (arg(0) == 'node' && arg(2) == 'edit') ||  (arg(0) == 'user' && arg(2) == 'edit') ) {
      global $custom_theme;
      $custom_theme = variable_get('admin_theme', '0');
      drupal_add_css(drupal_get_path('module', 'system') .'/admin.css', 'module');
  }

Any ideas on this?

Excellent!

Marc-e-Labs - August 28, 2008 - 18:30

This plug & play module code is great!
Works like a charm, really have no idea why it's not part of:
- http://drupal.org/node/122578

Thnx very much!

___________________
discover new oceans
lose sight of the shore

It looks pretty handy, but

arif_mandra - September 6, 2008 - 00:37

It looks pretty handy, but still won't work for the Block Admin page.The probable reason, I think because the block module is applying the theme while it's building the form, it's able to override whatever theme is set globally.

I found that if I override the global $custom_theme variable in block.admin.inc I can force it to display the admin theme. I know that making modifications inside of core is frowned upon though.

<?php
/**
* Menu callback for admin/build/block.
*/
function block_admin_display($theme = NULL) {
  global
$custom_theme;

 
// If non-default theme configuration has been selected, set the custom theme.
  //$custom_theme = isset($theme) ? $theme : variable_get('theme_default', 'garland');
  // Display admin theme
 
$custom_theme = variable_get('admin_theme', '0');

 
// Fetch and sort blocks
 
$blocks = _block_rehash();
 
usort($blocks, '_block_compare');

  return
drupal_get_form('block_admin_display_form', $blocks, $theme);
}
?>

I've looked into that as

Bartezz - September 9, 2008 - 22:28

I've looked into that as well but then quickly stopped after reading so many posts about altering core or modules...
Haven't had time for it but if I understand Drupal correctly there should be a way to alter this function without altering the module. Remember reading about hook_alter.... will try to look into it when I have time!

Cheers

 
 

Drupal is a registered trademark of Dries Buytaert.