The template.php for the default theme, 'theme_default' is loaded for admin themes on first page view after a cache flush. This is particularly annoying because my default theme implements hook_css_alter() and unsets some admin specific css files. On first page view of a page rendered with the admin theme, the css alter hook gets fired and I'm missing some significant styling.

I solved this by putting a check in my css_alter for admin paths, but there's got to be a way that the template.php for the default theme doesn't get registered for the admin theme.

Comments

heddn’s picture

Here's the offending code in fences.module. The include_once registers the default theme template.php for the first page view. For me on cache flush this is usually an admin page. The bug can be be avoided if the first page view is not an admin page.

function _fences_get_fences_suggestion_info(&$fences) {
...
  $themes[$theme_default] = 'theme_engine';
  // Include the template.php files of the entire theme stack.
  foreach (array_keys($themes) as $theme) {
    $file = './' . drupal_get_path('theme', $theme) . '/template.php';
    if (file_exists($file)) {
      include_once $file;
    }
...
  }
heddn’s picture

In _fences_theme_registry_alter() I tried removing any preprocess or process functions for the admin theme, but that didn't help. In the problem at hand, the include_once makes all the code of template.php available on first page view. Not sure how to make the code not available on first page view.

heddn’s picture

Title: template.php & admin themes » include_once template.php & admin themes
azinck’s picture

Title: include_once template.php & admin themes » _fences_get_fences_suggestion_info (erroneously?) includes php from non-current theme

I don't think there's a good way to accomplish what the module is attempting to do here. It's attempting to fire hooks in the default theme even if it's not the current theme. I assume this is in order to load all of the Fences suggestions provided by the default theme so that they can be selected through the admin interface. Unfortunately, this has the side-effect of loading the default theme's template.php and running any code in there.

I should note: I'm working with heddn. The specific issue he mentioned of the hook_css_alter() being fired on the default theme was a bit of a red herring (and an error on our part). That was occurring because of a naming collision between our default theme and our install profile. So, to be clear, the problem with including the template.php of the default theme is *not* that it will lead to firing hooks that shouldn't get fired in the default theme, but only that any "naked" php in the default theme's template.php will get run, thus possibly impacting the current theme.

I'll confess that I'm not totally sure that putting "naked" php (code not in a class or function) in template.php is considered a good practice. Is there documentation about that anywhere?