Can't figure out why, but going to /admin/structure/features/FOO loads in the site default theme, not the admin theme as expected.

Something to do with the custom theme template?

Comments

emarchak’s picture

I'm on the latest dev version of Features, and none of the patches will correct this error for me.

fearlsgroove’s picture

Triggering this bug requires having something call menu_get_item() in hook_custom_theme (or possibly hook_init -- something before full boostrap). Domain_theme from Domain was the module that made me look into this.

This problem occurs because features_load is invoked by menu_get_item() since the feature object is the menu argument. Inside the feature_load chain is system_rebuild_module_info. If a module calls menu_get_item in a pre-bootstrap hook like custom_theme (which domain theme does), it will attempt to load the feature, which triggers the module info rebuild. At least the field module, and possibly many others, call theme functions or functions that depend on theme calls (i.e. l()) during the module rebuild. Since theme initialization hasn't happened, the theme gets pre-initialized as the default regardless of what custom_theme hook invokes set.

I have no idea whether to blame domain for calling menu_get_item before initialization, features for calling system_rebuild_module_info as part of an entity load function or core for allowing API calls to exist that can't safely be called from hooks that core also provides pre bootstrap.

agentrickard’s picture

Hm. That sounds like a bug in Features still.

agentrickard’s picture

Status: Active » Closed (duplicate)

We fixed this over in DA.

devuo’s picture

Title: View / Recreate feature ignores admin theme » View / Recreate feature ignores admin theme when menu_get_item() is used in hook_custom_theme().
Status: Closed (duplicate) » Active

This problem still exists, and must be solved within the scope of the Features module. Features breaking due to the use menu_get_item() with an implementation of hook_custom_theme() is quite restricting.

mpotter’s picture

Drupal is invoking menu_get_item in order to execute the path /admin/structure/features/FOO (Drupal needs to load the FOO feature to pass is to the menu hook). This happens with any path that uses menu arguments, such as %feature or %node (loads a node). Drupal calls feature_load in order to load the feature object.

In order to load a feature, Features must call system_rebuild_module_info in order to get the module file list to loop through. I don't see any other Drupal core API function to return the list of module files.

So my question back is what is being done in your hook_custom_theme() that is interfering with this as it sounds like this was fixed with Domain already? Sounds like you are calling something too early in the bootstrap order.

Unfortunately I don't see anything I can do in Features to help with this, but if somebody wants to post a patch solution, I'll take a look.

agentrickard’s picture

In Domain, we fixed this with #1419090: Domain theme, admin theme broken broken for certain paths in Features module. Anything that causes this error and _does not_ use DA needs to be properly reported and validated by @devuo.

My understanding is that menu_get_item() is unreliable when any module uses AJAX on a page.

wiifm’s picture

I was having the exact same issue, managed to follow @agentrickard's advice and apply the fix:

/**
 * Implements hook_custom_theme().
 */
function mts_config_custom_theme() {
  // fix for bug http://drupal.org/node/1309128 - this is where the front end
  // theme would show in features.
  if (arg(0) == 'admin') {
    return;
  }

...

And now I finally get the admin theme when re-creating features. Would be keen on a features/core patch here, rather than a contrib module hack.

agentrickard’s picture

Status: Active » Closed (duplicate)

I think it's a core issue. I used to have the same problem with AJAX from the Media module. You should open a core bug.

jeffschuler’s picture

Issue summary: View changes

Cross-referencing #2347825: CustomError causing admin pages to appear in default theme, where the same issue occurs with the CustomError module due to a call to menu_get_item() from hook_custom_theme().