See details here - http://groups.drupal.org/node/68798#comment-209898

The solution might be different than mine, but for my cause it solves the problem -

  // Option #1 - admin/build/themes/settings/theme name
  if ((arg($index + 1) == 'build') && (arg($index + 2) == 'themes') && (arg($index + 3) == 'settings')) {
    $theme_name = arg($index + 4);
  } elseif ((arg($index + 1) == 'build') && (arg($index + 2) == 'domain') && (arg($index + 3) == 'theme')) {
    // Option #2 - admin/build/domain/theme/theme name/56/theme-settings
    $theme_name = arg($index + 4);
  }

Regards,
Shushu

Comments

sociotech’s picture

Status: Needs review » Postponed (maintainer needs more info)

Shushu,

Just wondering if you've had any luck finding a more generic approach to getting the theme name in phptemplate_settings().

shushu’s picture

No, I didn't, but I didn't have time to look for it either...

shushu’s picture

I think that since each module might use this feature, the right solution would be creating a specific hook for it, and invoking it from here, so each module will be able to give his own solution.

Meanwhile, I just wanted to show the full solution I got, solving core + domains module cases. It is based on finding the 'admin' argument in the URL, and counting from it.

function _find_theme_name() {
  for ($index = 0; $index < count(arg()); $index++) {
    if (arg($index) == 'admin') {
      break;
    }
  }
  // Option #1 - admin/build/themes/settings/theme name
  if ((arg($index + 1) == 'build') && (arg($index + 2) == 'themes') && (arg($index + 3) == 'settings')) {
    $theme_name = arg($index + 4);
  } elseif ((arg($index + 1) == 'build') && (arg($index + 2) == 'domain') && (arg($index + 3) == 'theme')) {
    // Option #2 - admin/build/domain/theme/theme name/56/theme-settings
    $theme_name = arg($index + 4);
  }
  return $theme_name;
}
/**
* Implementation of THEMEHOOK_settings() function.
*
* @param $saved_settings
*   array An array of saved settings for this theme.
* @return
*   array A form array.
*/
function phptemplate_settings($saved_settings) {
  global $base_url;

  // Get theme name from url (admin/.../theme_name)
  // Bug #1 - when using the theme form in the domain theme, this won't give the theme name...
  $theme_name = _find_theme_name();

  // Combine default theme settings from .info file & theme-settings.php
  $theme_data = list_themes();   // get data for all themes
...
coltrane’s picture

Woh, domain access does some funky stuff to the URL. I wonder if core functions like menu_get_item() respect (or ignore well enough) what domain access does to extract the theme name correctly.

coltrane’s picture

domain_theme form alters the system_theme_settings form where Fusion's phptemplate_settings() gets called and extracts the theme name from arg(4) http://drupalcode.org/project/domain.git/blob/4c1f88e07b490f6f67acc3645b... arg(4) matches what the code in #3 gets to so perhaps rather than searching through the URL args instead we do:

if (module_exists('domain_theme')) {
  $theme_name = arg(4);
}
else {
  $theme_name = arg(count(arg()) - 1);
}
dvessel’s picture

Status: Postponed (maintainer needs more info) » Active

I was looking into a different problem with "hook_form_system_theme_settings_alter" and ran into this. Thought I'd chime in if you didn't find a fix already.

There are two global variables that holds the theme name. One is $theme and the other is $theme_key. What I do with my themes is to provide a function to access the correct key depending what you need. Hope the comments below is clear.

/**
 * Returns the current active theme. Use this instead of the global variable.
 *
 * @param $page_relative
 *  When set to TRUE, this will always return the theme used for the current
 *  page. When set to FALSE, it will return the internal theme that is in
 *  focus. For example, if the site has a different admin theme, setting this
 *  to FALSE will return the site wide active theme while TRUE will return the
 *  admin theme used for the displayed page. When inside the theme settings
 *  api form, the internal focus will be on the theme specific form so FALSE
 *  will point to the theme associated with that form. TRUE will still return
 *  the theme that is relative to the page. 
 */
function MYTHEME_active_theme($page_relative = TRUE) {
  return $page_relative ? $GLOBALS['theme'] : $GLOBALS['theme_key'];
}

I've been using this in Drupal 7 but I'm pretty sure it hasn't changed since 6.

Poieo’s picture

Issue summary: View changes
Status: Active » Closed (won't fix)

Closing as won't fix since the D6 version is not getting any new development.