Problem/Motivation

This is a bit tricky to reproduce, but once the system is setup correctly it can be replicated consistently:

  1. Install a plain D7
  2. Make sure Seven is the admin theme
  3. Enable the Libraries and PHPExcel modules
  4. Enable the Bootstrap base theme
  5. Create a sub-theme having a name starting with A (actually lexicographically less then bootstrap) using the bootstrap_include() function, e.g.:
    /**
     * @file
     * template.php
     */
    bootstrap_include('my_custom_theme', 'theme/alter.inc');
    
  6. Clear library cache: drush cc libraries
  7. Visit the status report page

Expected result: the status report is displayed
Actual result: a reassuringly less colorful WSOD

Proposed resolution

Load base theme template files before loading theme template file.

Remaining tasks

  • Validate the proposed solution
  • Post a patch
  • Reviews

User interface changes

None

API changes

None

Data model changes

None

Comments

plach created an issue. See original summary.

plach’s picture

Issue summary: View changes
StatusFileSize
new1.33 KB
plach’s picture

Status: Active » Needs review
plach’s picture

Status: Needs review » Active
StatusFileSize
new10 KB

This is a custom theme I used to replicate the issue locally.

plach’s picture

Issue summary: View changes
tstoeckler’s picture

Status: Active » Needs work

Wow, nice catch!

I think we should build up a properly sorted list of themes outside of the foreach () in libraries_info(). That would (hopefully) make the code a bit more readable, IMO.

plach’s picture

Status: Needs work » Needs review
StatusFileSize
new1.98 KB

This implements the approach suggested in #6.

tstoeckler’s picture

StatusFileSize
new2.17 KB

Thanks again. I moved a bit of code around to make it PHP 5.2 compatible, but (hopefully) kept the logic the same. One question: you used strcmp() if neither theme is a base theme of the other. Is there any reason for that? I think in that case we should just punt and return 0. Attached patch does that.

tstoeckler’s picture

+++ b/libraries.module
@@ -80,6 +80,56 @@ function libraries_get_path($name, $base_path = FALSE) {
+};

Superfluous semi-colon. Can be fixed on commit.

manav’s picture

Assigned: Unassigned » manav
manav’s picture

StatusFileSize
new2.17 KB
manav’s picture

Assigned: manav » Unassigned
tstoeckler’s picture

Thanks for the patch @Manav, did the patch work for you? Did you try it out?

manav’s picture

Hi @Tobias

Sorry for late comment. Yes i have tested this patch on my local and apply the changes commented in #9. But after followed above steps (mentioned in Issue description) i got the following errors.

Attching screen-shot for the same.

Thanks
Manav

manav’s picture

Assigned: Unassigned » manav

Hi @Tobias
Please ignore above comment. #14
Sorry its my mistake. I have tested it again and find that everything is working fine without any error.

Thanks
Manav

tstoeckler’s picture

Status: Needs review » Reviewed & tested by the community

OK, awesome. Counting that as an RTBC ;-)

Thank you!

manav’s picture

Assigned: manav » Unassigned
plach’s picture

Sorry, lost track of this. I tested #11 and it still seems to fix the issue.

RTBC +1

proteo’s picture

Status: Reviewed & tested by the community » Needs work

Hi, I'm facing this very same issue with some admin screens (/admin/reports/status and /admin/reports/libraries). From what I gather the patch should fix the problem, yet it isn't. I have three themes enabled; in libraries_get_enabled_themes(), the $themes array come up from list_themes() in this order:

a21
adminimal
bootstrap

a21 (my custom theme) uses bootstrap as base theme. As such, I expected that after doing:

uasort($themes, 'libraries_compare_themes')

the $themes array should be sorted like this or something similar, putting boostrap before a21:

adminimal
bootstrap
a21

However, the $themes array is returned in the same, unchanged order, which of course causes the WSOD because the function tries to load a2's1 template.php file before bootstrap_include() is declared.

Not sure why the libraries_compare_themes() function is failing to perform properly, but I did some debugging and strangely it looks like the function is evaluating only consecutive pairs: first a21/adminimal and then adminimal/bootstrap, but it never gets to evaluate the a21/bootstrap pair.

proteo’s picture

Priority: Normal » Major
Status: Needs work » Needs review
StatusFileSize
new2.27 KB

OK, after taking some time to understand how uasort() works I realized that it will never be a good fit for the task, and a more robust approach is required. My case is just the tip of the iceberg, other cases may arise with more complex setups (for example, when a theme is both parent and subtheme at the same time). I'm attaching a patch that uses a recursive function to sort the array in such a way that subthemes always will be located after its base theme, no matter how complex or deep is the hierarchy.

Giving the fact that this bug breaks a very important part of the site (the Status Report page) I'm changing this to Major.

proteo’s picture

Status: Needs review » Reviewed & tested by the community

I've been using this patch for a while in several production sites, and it seems to work fine. After upgrading to the 2.4 release I reminded this still needs to be commited.

  • joseph.olstad committed d6ba0ba on 7.x-2.x authored by plach
    Issue #2815965 by plach, Manav, tstoeckler, Proteo: Base theme is not...
joseph.olstad’s picture

Status: Reviewed & tested by the community » Fixed

Pushed and creditted, thank you everyone!

  • joseph.olstad committed a720031 on 7.x-3.x authored by plach
    Issue #2815965 by plach, Manav, tstoeckler, Proteo: Base theme is not...
joseph.olstad’s picture

ignore the 7.x-3.x branch, use 7.x-2.x

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

steven jones’s picture

Thanks everyone, this change almost worked! There's a little bug that's resolved in #3178266: libraries_sort_themes will not allow libraries_load to work if the custom theme's base theme is not enabled.