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 :)

Comments

Peter76’s picture

Anyone?

roopletheme’s picture

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.

Peter76’s picture

Thanks for help. It works.

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

roopletheme’s picture

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

jeffkohn’s picture

You can always put the option back in with form alter if you need to turn it off and on

function adminedit_form_alter($form_id, &$form)
{
    if ($form_id == 'system_admin_theme_settings') {
        $form['admin_theme']['#weight'] = -10;
        $form['adminedit_content_editing'] = array('#type' => 'checkbox',
            '#default_value' => variable_get('adminedit_content_editing', true),
            '#title' => t('use administration theme for content editing'),
            '#weight' => -9,
        );
        $form['submit']['#weight'] = 10;		
    }
}

then remember to check if the variable is true when you change the $custom_theme global variable

davej’s picture

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

sillygwailo’s picture

For the people who are having trouble getting the module to work, what davej is saying is to replace

function adminedit_menu() {

with

function adminedit_init() {

and just to be sure that everything gets registered properly (actually voodoo magic?), go to the modules page and click "Save configuration".

(Username formerly my full name, Richard Eriksson.)

bartezz’s picture

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?

________________
Live fast die young

Marc Bijl’s picture

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

arif_mandra’s picture

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.

/**
* 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);
}
bartezz’s picture

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

________________
Live fast die young

open-keywords’s picture

I would suggest that the block module is looking at the theme files to identify the regions to propose for configuration. And then it becomes tricky :-)

bartezz’s picture

You are very right and I found it hard to alter it so that the block module gets the regions first and then still use the admin theme... haven't worked on it for a while. Might pick it up again when things calm down here...

Cheers

________________
Live fast die young