I have my site split up into an admin theme and a custom front-end theme.

For some reason when I go to Administer -> Blocks the page is rendered in the front-end theme instead of the admin theme.

this snippet from system.module shows that any url starting with 'admin' should be rendered using the admin theme:

function system_init() {
  // Use the administrative theme if the user is looking at a page in the admin/* path.
  if (arg(0) == 'admin' || (variable_get('node_admin_theme', '0') && arg(0) == 'node' && (arg(1) == 'add' || arg(2) == 'edit'))) {
    global $custom_theme;
    $custom_theme = variable_get('admin_theme', '0');
    drupal_add_css(drupal_get_path('module', 'system') .'/admin.css', 'module');
  }

can anyone explain this behavior?

Comments

WorldFallz’s picture

The Blocks page uses the front end theme because it's previewing the block positions while you setup your blocks (which is usually more important for the front end theme than the admin theme). I'm not sure if/how this can be overridden, but it's not a bug.

===
"Give a man a fish and you feed him for a day.
Teach a man to fish and you feed him for a lifetime."
-- Lao Tzu
"God helps those who help themselves." -- Benjamin Franklin
"Search is your best friend." -- Worldfallz

aspafford’s picture

That makes sense but could lead to some problems. For example, when admin->blocks is rendered in my custom-theme I see no options to 'add' or 'list' blocks. I also didn't see the intro paragraph until I switched back to the 'garland' theme.

In D6 they added the option to use the administration theme for content editing. this is a good start, but I think it would be nice to be able to add any url to a 'show-in-admin-theme' option.

WorldFallz’s picture

I agree this might be a useful thing for core, but you can sort of mimic this functionality by using http://drupal.org/project/sections and just specifying the paths that you wish to use the admin theme.

===
"Give a man a fish and you feed him for a day.
Teach a man to fish and you feed him for a lifetime."
-- Lao Tzu
"God helps those who help themselves." -- Benjamin Franklin
"Search is your best friend." -- Worldfallz

aspafford’s picture

Thanks for the tip on the sections module. This looks pretty handy, but still won't work for the Block Admin page. 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, so any suggestions for making this nicer are welcome.

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

I find that MOST of the time in the themes I build for clients, it's NOT appropriate for the admin pages. So, I use the default garland theme, or RoodCandy for the admin theme, but it just blows everything all to hell on the block mgmt page.

And it's not like it even previews the blocks live or anything like that, just a lil gay yellow bar pointing out the name of that region. I use descriptive names for my regions, so I really dont need this feature, and would also like to modify this WITHOUT core hacking.

But for now, hacking it is...

Jake Strawn
Himerus Inc. - http://himerusinc.com
Online Resume - http://jakestrawn.com

WorldFallz’s picture

Yeah-- i agree it's not a very useful view. At the least, it should be an admin selection for which theme to use on this page--- i'll have to see about patch for that, for all we know someone already submitted one.

===
"Give a man a fish and you feed him for a day.
Teach a man to fish and you feed him for a lifetime."
-- Lao Tzu
"God helps those who help themselves." -- Benjamin Franklin
"Search is your best friend." -- Worldfallz

himerus’s picture

Actually, this doesn't work since it updates the regions being used to the regions associated with the admin theme only, and not the front-end theme.

There does need to be some work around for this somehow.

Jake Strawn
Himerus Inc. - http://himerusinc.com
Online Resume - http://jakestrawn.com

bartezz’s picture

Agreed!!!

Hope some one will build a non-core-hack fix for this....

________________
Live fast die young

bartezz’s picture

I've looked all over for a module that would make your core modification unessecary but i couldn't find one.
And since you're modification worked I jsut hacked core, working great... untill....

Well untill I just wanted to edit a block. I shows the page in the admin theme, yes. But the block dropdown options (regions) are also from the admin theme and not the default theme :(

Thanx tho for posting your solution....

________________
Live fast die young

Jeff Burnz’s picture

Well the whole point of the default way is so you can see & select the regions for your live theme. There's nothing to stop you theming the blocks page to display a representation of your live theme AND works as an administrative UI.

Not seeing the point, waste of time imho, just theme it and be happy...

bartezz’s picture

Thanx for the reply. I understand the point very well. Yet if my live theme really isn't fit as a page to fit a administrative UI in then what? Build a page especially for this purpose? It would be nice if there just was a setting and let people who use the module decide what to do... make it default as it is now but give people at least a option to overwrite this default and use the admin theme if they think it's nessecary!

Cheers

________________
Live fast die young

Jeff Burnz’s picture

Would it be nice or would it be simply bloat 99% of users will never want/need/ want to remove? Your argument is simplistic, arrogant and makes unfounded assumptions with little or no consideration to the 1000 other people who built the drupal core.

I don't really see the point in this discussion at all, frankly there is a well worn path of core feature requests you can go down OR get of your ass and build a module and contribute it back. Quit the whining and do something.

Nough said.

bartezz’s picture

Dude chill.... why the aggression??? Was I in my post?

Why is it simplistic or arrogant? And why unfound... if you look for a way to show the blocks ui in the admin theme you will find that there are more people trying to achieve this. That's why I was saying that it would be nice to have a setting for this. Not telling or requesting you to make one for me?!?! Just giving my opinion isn't that what a forum is for?

I have been working on a work around for it but somehow the module overwrites my settings. If I manage to build a module to show the blocks ui in the admin theme I will contribute....

Cheers

________________
Live fast die young

Jeff Burnz’s picture

Aggression! LOL, harden up pal, that's practically a hug and kiss!

I think its simplistic because it's your opinion, and it takes more than an opinion to build an application.

I think its a bit arrogant because you're presenting an opinion as if it were "an obvious fact".

I think its unfounded because a) in my 2 years here I have perhaps seen one or two requests for this (as far as I can remember), b) none of my 100 odd clients in the last 3.5 years have requested this, and c) you offer nothing beyond hearsay evidence that this is a coveted feature.

I may have a bit of an attitude at times but I am not aggressive, actually I'm rather helpful if you get to know that side me.

Good luck with the module, hope you get it sorted. Rock on.

bartezz’s picture

Alright then.... :)

I was thinking about this last night a bit more and I was wondering about the following (and no it's not for my personal use, it's just a possibility).

What if one builds a theme with various regions for different page.tpl.php? Let's say page-frontpage.tpl.php, page-products.tpl.php, page-information.tpl.php and page-news.tpl.php. These templates have different regions. I would be easy to imagine that for the products.tpl.php there would be regions for product pictures, product downloads etc etc, for page-news.tpl.php there might be regions for video, relateded news views etc. Hope you get what I mean.

Then the preview of regions idea in the blocks ui doesn't work or am I mistaken? The idea of viewing the blocks in the live theme wouldn't work here I think because the idea behind this concept (from what I understand) is that the defined regions work for every page.tpl. I could be wrong?

Cheers

________________
Live fast die young

Jeff Burnz’s picture

Yes, that is quite right. However - you are making up the classic "what if" scenarios that we all love to - yes they are worthy questions, absolute - you can keep posing these what-if scenarios till the cows come home, but Drupal provides many of the answers already.

Drupal possesses the flexibility to deal with the situation you raise via theming (amongst other methods) - it gets this flexibility by being a generic framework, and not trying to be too specific. The whole Drupal philosophy is about being modular, flexible and agile - a toolbox of hooks and API's that developers can leverage to build their applications.

Out of the box Drupal can't make my coffee, and I hope it never does - but it most certainly gives me the hooks & API's by the truckload to build my coffee.module should I want to.

Like I said earlier - there nothing stopping you from theming the blocks page as a representation of your theme, in a usable UI (which is just one possible solution amongst many) - Drupal has the tools to do this already and you are the one building your specific application - I don't think its up to Drupal to deliver that specificity out of the box, but rather provide the building blocks allowing you to do so yourself.

bartezz’s picture

I agree that Drupal shouldn't be specific. Although some parts of the system and core sometimes are rather specific. A lot of times this specificity is overridable, sometimes not or at least not as easy as I think it could be.

I hope to learn more about Drupal and that way to be able to contribute back. "What if" scenarios are great ey :) Not just for discussion but also to make a better product.

Thanx for the reply!

________________
Live fast die young

bailey86’s picture

The request is perfectly valid - and you're attitude is completely wrong.

I'd prefer to build up the tpl.php file from scratch - and don't see why I should try to bodge on $content etc to my new template just so I can administer the blocks.

Also, we are all Drupal fans - if you've put time into getting this far then we've extremely grateful to the original developers. But this is a programming issue - extra functionality has been applied without choice - i.e. rendering page in different theme linked to blocks you are editing. If there is an admin/administrator theme applied to the admin system then this should really be applied to all pages as is implied - after all - it doesn't say 'Apply admin theme (except to block admin pages)' It says 'Apply admin theme'.

The choice to view the block admin page in it's relevant theme should be the option.

Your attitude is a little immature - the way it's set up may be suitable for you - but as I've said - the point the poster raises is perfectly valid.

WorldFallz’s picture

No need to dredge up this ancient thread-- this is a now non issue and has been addressed in d7.

Sunshiney’s picture

Newbie here. I cannot see the blocks/region table on my blocks page, although I can see my custom theme and the new region I created. The latter is fine. Happy to see it there. But I cannot manage any of my blocks. I read JMBURNZ post and I am not understanding. Are you saying that my block/region table will show on my admin/block page if I theme the block tpl file? Is that what I need to do to make the region/block table display? Thanks for the advice.

elsvandeveire’s picture

Hi, I've made a little change in the modules/block/block.admin.inc file.

Original (around line 16)
$custom_theme = isset($theme) ? $theme : variable_get('theme-default›', 'garland');

Changed into:
$custom_theme = isset($theme) ? $theme : variable_get('admin-theme›', 'garland');

This works fine for me.

One problem though: all new made regions disappear. Anyone who knows how to solve this?
Kind regards

Els

illSleepWheniDie’s picture

Hi Everybady!

It's farking March 2010 and it seems we still don't know
1) how to make non-core fixes, and
2) how to avoid disappearing regions

.. the blocks list page is a very core page to all site admins. Can we find a solution to this? Lets think outside the box, maybe we've overlooked something simple? Or maybe we can just go around the problem altogether?

Cheers
Alex

WorldFallz’s picture

Just an fyi-- this has been fixed in d7!

hellolindsay’s picture

I have managed to successfully force the blocks module to use the admin theme without side-effects. Yes, core needs to be hacked to do this, there does not seem to be a way around that in Drupal 6. I am using Drupal 6.16.

The changes needed are below. I made about a dozen changes in 2 files and 4 functions. Every time I changed something, I added a comment "// core hacked" to the end of the line. I also kept a commented-out copy of the each line I changed right before the change.

If you want to use these changes, I suggest copying them as whole functions and paste them over existing functions.

block.module: 1 function changed

function _block_rehash($theme = NULL) { // core hacked: added
//function _block_rehash() { // core hacked: removed
  global $theme_key;

  init_theme();
  $theme = isset($theme) ? $theme : $theme_key; // core hacked: added

  //$result = db_query("SELECT * FROM {blocks} WHERE theme = '%s'", $theme_key); // core hacked: removed
  $result = db_query("SELECT * FROM {blocks} WHERE theme = '%s'", $theme); // core hacked: added
  $old_blocks = array();
  while ($old_block = db_fetch_array($result)) {
    $old_blocks[$old_block['module']][$old_block['delta']] = $old_block;
  }

  $blocks = array();
  // Valid region names for the theme.
  //$regions = system_region_list($theme_key); // core hacked: removed
  $regions = system_region_list($theme); // core hacked: added

  foreach (module_list() as $module) {
    $module_blocks = module_invoke($module, 'block', 'list');
    if ($module_blocks) {
      foreach ($module_blocks as $delta => $block) {
        if (empty($old_blocks[$module][$delta])) {
          // If it's a new block, add identifiers.
          $block['module'] = $module;
          $block['delta']  = $delta;
          //$block['theme']  = $theme_key; // core hacked: removed
          $block['theme']  = $theme; // core hacked: added
          if (!isset($block['pages'])) {
            // {block}.pages is type 'text', so it cannot have a
            // default value, and not null, so we need to provide
            // value if the module did not.
            $block['pages']  = '';
          }
          // Add defaults and save it into the database.
          drupal_write_record('blocks', $block);
          // Set region to none if not enabled.
          $block['region'] = $block['status'] ? $block['region'] : BLOCK_REGION_NONE;
          // Add to the list of blocks we return.
          $blocks[] = $block;
        }
        else {
          // If it's an existing block, database settings should overwrite
          // the code. But aside from 'info' everything that's definable in
          // code is stored in the database and we do not store 'info', so we
          // do not need to update the database here.
          // Add 'info' to this block.
          $old_blocks[$module][$delta]['info'] = $block['info'];
          // If the region name does not exist, disable the block and assign it to none.
          if (!empty($old_blocks[$module][$delta]['region']) && !isset($regions[$old_blocks[$module][$delta]['region']])) {
            drupal_set_message(t('The block %info was assigned to the invalid region %region and has been disabled.', array('%info' => $old_blocks[$module][$delta]['info'], '%region' => $old_blocks[$module][$delta]['region'])), 'warning');
            $old_blocks[$module][$delta]['status'] = 0;
            $old_blocks[$module][$delta]['region'] = BLOCK_REGION_NONE;
          }
          else {
            $old_blocks[$module][$delta]['region'] = $old_blocks[$module][$delta]['status'] ? $old_blocks[$module][$delta]['region'] : BLOCK_REGION_NONE;
          }
          // Add this block to the list of blocks we return.
          $blocks[] = $old_blocks[$module][$delta];
          // Remove this block from the list of blocks to be deleted.
          unset($old_blocks[$module][$delta]);
        }
      }
    }
  }

  // Remove blocks that are no longer defined by the code from the database.
  foreach ($old_blocks as $module => $old_module_blocks) {
    foreach ($old_module_blocks as $delta => $block) {
      //db_query("DELETE FROM {blocks} WHERE module = '%s' AND delta = '%s' AND theme = '%s'", $module, $delta, $theme_key); // core hacked: removed
      db_query("DELETE FROM {blocks} WHERE module = '%s' AND delta = '%s' AND theme = '%s'", $module, $delta, $theme); // core hacked: added
    }
  }
  return $blocks;
}

block.admin.inc: 3 functions changed

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'); // core hacked: removed
  $theme = isset($theme) ? $theme : variable_get('theme_default', 'garland'); // core hacked: added

  // Fetch and sort blocks
  //$blocks = _block_rehash(); // core hacked: removed
  $blocks = _block_rehash($theme); // core hacked: added
  usort($blocks, '_block_compare');

  return drupal_get_form('block_admin_display_form', $blocks, $theme);
}
function block_admin_display_form(&$form_state, $blocks, $theme = NULL) {
  global $theme_key, $custom_theme;

  // Add CSS
  drupal_add_css(drupal_get_path('module', 'block') .'/block.css', 'module', 'all', FALSE);

  // If non-default theme configuration has been selected, set the custom theme.
  //$custom_theme = isset($theme) ? $theme : variable_get('theme_default', 'garland'); // core hacked: removed
  $theme = isset($theme) ? $theme : variable_get('theme_default', 'garland'); // core hacked: added
  init_theme();

  $throttle = module_exists('throttle');
  //$block_regions = system_region_list($theme_key) + array(BLOCK_REGION_NONE => '<'. t('none') .'>'); // core hacked: removed
  $block_regions = system_region_list($theme) + array(BLOCK_REGION_NONE => '<'. t('none') .'>'); // core hacked: added

  // Weights range from -delta to +delta, so delta should be at least half
  // of the amount of blocks present. This makes sure all blocks in the same
  // region get an unique weight.
  $weight_delta = round(count($blocks) / 2);

  // Build form tree
  $form = array(
    '#action' => arg(4) ? url('admin/build/block/list/'. $theme_key) : url('admin/build/block'),
    '#tree' => TRUE,
  );
  $form['_theme'] = array( // core hacked: added
      '#type' => 'hidden', // core hacked: added
      '#value' => $theme, // core hacked: added
  ); // core hacked: added

  foreach ($blocks as $i => $block) {
    $key = $block['module'] .'_'. $block['delta'];
    $form[$key]['module'] = array(
      '#type' => 'value',
      '#value' => $block['module'],
    );
    $form[$key]['delta'] = array(
      '#type' => 'value',
      '#value' => $block['delta'],
    );
    $form[$key]['info'] = array(
      '#value' => check_plain($block['info'])
    );
    $form[$key]['theme'] = array(
      '#type' => 'hidden',
      //'#value' => $theme_key // core hacked: removed
      '#value' => $theme // core hacked: added
    );
    $form[$key]['weight'] = array(
      '#type' => 'weight',
      '#default_value' => $block['weight'],
      '#delta' => $weight_delta,
    );
    $form[$key]['region'] = array(
      '#type' => 'select',
      '#default_value' => $block['region'],
      '#options' => $block_regions,
    );

    if ($throttle) {
      $form[$key]['throttle'] = array('#type' => 'checkbox', '#default_value' => isset($block['throttle']) ? $block['throttle'] : FALSE);
    }
    $form[$key]['configure'] = array('#value' => l(t('configure'), 'admin/build/block/configure/'. $block['module'] .'/'. $block['delta']));
    if ($block['module'] == 'block') {
      $form[$key]['delete'] = array('#value' => l(t('delete'), 'admin/build/block/delete/'. $block['delta']));
    }
  }

  $form['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Save blocks'),
  );

  return $form;
}
function template_preprocess_block_admin_display_form(&$variables) {
  global $theme_key;

  //$block_regions = system_region_list($theme_key); // core hacked: removed
  $block_regions = system_region_list($variables['form']['_theme']['#value']); // core hacked: added
  $variables['throttle'] = module_exists('throttle');
  $variables['block_regions'] = $block_regions + array(BLOCK_REGION_NONE => t('Disabled'));

  foreach ($block_regions as $key => $value) {
    // Highlight regions on page to provide visual reference.
    drupal_set_content($key, '<div class="block-region">'. $value .'</div>');
    // Initialize an empty array for the region.
    $variables['block_listing'][$key] = array();
  }

  // Initialize disabled blocks array.
  $variables['block_listing'][BLOCK_REGION_NONE] = array();

  // Set up to track previous region in loop.
  $last_region = '';
  foreach (element_children($variables['form']) as $i) {
    $block = &$variables['form'][$i];

    // Only take form elements that are blocks.
    if (isset($block['info'])) {
      // Fetch region for current block.
      $region = $block['region']['#default_value'];

      // Set special classes needed for table drag and drop.
      $variables['form'][$i]['region']['#attributes']['class'] = 'block-region-select block-region-'. $region;
      $variables['form'][$i]['weight']['#attributes']['class'] = 'block-weight block-weight-'. $region;

      $variables['block_listing'][$region][$i]->row_class = isset($block['#attributes']['class']) ? $block['#attributes']['class'] : '';
      $variables['block_listing'][$region][$i]->block_modified = isset($block['#attributes']['class']) && strpos($block['#attributes']['class'], 'block-modified') !== FALSE ? TRUE : FALSE;
      $variables['block_listing'][$region][$i]->block_title =  drupal_render($block['info']);
      $variables['block_listing'][$region][$i]->region_select = drupal_render($block['region']) . drupal_render($block['theme']);
      $variables['block_listing'][$region][$i]->weight_select = drupal_render($block['weight']);
      $variables['block_listing'][$region][$i]->throttle_check = $variables['throttle'] ? drupal_render($block['throttle']) : '';
      $variables['block_listing'][$region][$i]->configure_link = drupal_render($block['configure']);
      $variables['block_listing'][$region][$i]->delete_link = !empty($block['delete']) ? drupal_render($block['delete']) : '';
      $variables['block_listing'][$region][$i]->printed = FALSE;

      $last_region = $region;
    }
  }

  $variables['form_submit'] = drupal_render($variables['form']);
}