I was just configuring the sub-theme option in D6, which *mostly* worked fine. The only odd thing is that all of the custom regions of the base theme were negated, and in the block admin I could only see the default Drupal regions.

Does anyone know if this is a bug, or is there some extra setting required?

Thanks!

Kevin

Comments

dvessel’s picture

I haven't checked but if your subtheme doesn't declare any regions at all, then It's definitely a bug. It should inherit what's set in the base theme.

For now, you can redeclare what's set in the base theme.

kevin hankens’s picture

Correct, there were no regions[] definitions in the sub theme.

kevin hankens’s picture

StatusFileSize
new494 bytes

The helper function _system_theme_data in system.module doesn't appear to register the regions in the base theme. The following patch appears to fix it.

This is the first patch I've submitted, so thanks in advance for your patience :)

Kevin

kevin hankens’s picture

StatusFileSize
new501 bytes

Minor correction in patch - the extra step was inside the wrong conditional.

dvessel’s picture

Status: Active » Needs work

That looks good except that regions from the base theme should replace all the regions instead of going one-by-one having a mix of both the default and parent theme regions. I'm just scanning the code here and that's what it looks like it's doing.

It should also check if the current sub-theme has it's own regions set. When it does, it should skip interfering with the regions. Looks like it would add to what's already there.

kevin hankens’s picture

Actually, it appears that the problem is in the theme registration, not the _system_theme_data function.

Tracing the variables in the _system_theme_data function, you can see that if a subtheme has regions defined, it loads them into the theme object. If it does not have them defined it uses system defaults instead of base-theme regions.

I'll keep exploring :)

kevin hankens’s picture

Ok, here's another possibility. What's happening is that the function _system_theme_data() seems to load system defaults prior to loading theme regions and the system sees the sub-theme as having Drupal default regions.

This patch suggests that you could call drupal_parse_info_file() once to see if the sub-theme has empty regions. If so, and the base-theme regions are not empty, you could load the base-theme regions instead of the Drupal defaults.

It's a lot of extra overhead, but I think the concept is close. [edit]Oh, and you probably don't need an array in an object in an array for the empty region check ;)[/edit]

Thanks for the proofing and help! :)

[edit]--deleted patch, revised patch in next comment--[/edit]

kevin hankens’s picture

StatusFileSize
new713 bytes

This revision uses a simpler variable than the one from comment #7, sorry for the confusion!

dvessel’s picture

Parsing the info file shouldn't be done. It seems awkward. It's usually cached and placed within the global $theme_info but that already populates the regions even when none is set IIRC. There must be another way.

Thanks for the patch, I'll try and help look into this myself. Let me also verify this bug since I never tested it.

dvessel’s picture

Title: Sub-theme negates base theme regions » automatically inherit .info theme settings
Version: 6.4 » 7.x-dev
Status: Needs work » Needs review
StatusFileSize
new3.22 KB

Kevin, the patch wasn't working at all. I had some free time to work on this. Instead of focusing on the regions, this makes more sense to me.

Here are the changes:

Specific keys within the .info file will automatically be inherited from it's immediate base theme. It also cascades so it works with multiple levels of inheritance. For example, if a base theme is 2 or more levels apart and the intermediate themes do not define regions, it will inherit the regions from that distant parent. This is similar to how the rest of the system works with inheritance.

  • sub-theme 5
    - regions undefined (inherited from sub-theme 3)
  • sub-theme 4
    - regions undefined (inherited from sub-theme 3)
  • sub-theme 3
    - regions defined
  • sub-theme 2
    - regions undefined (inherited from base theme 0.)
  • sub-theme 1
    - regions undefined (inherited from base theme 0.)
  • base theme 0
    - regions defined

The keys with this behavior are 'regions', 'features', 'core' and 'php'. You can see all the options in the handbook. More can be added easily if needed. This would change the requirement that 'core' needs to be defined for sub-themes as it will carry over.

I'm pushing this to 7.x-dev since this "bug" was documented. I forgot that I already made those notes and changing it now could break some themes.

dvessel’s picture

StatusFileSize
new3.22 KB

Typo.

dvessel’s picture

This would be a nice enhancement. No takers?

floretan’s picture

This could be nice, but some properties like "core" should be defined for every sub-theme. Suppose that you have a base theme with version 'x' and a sub-theme with it's own set of template files. Now a new version 'y' of Drupal is released, and you update your base theme, but the sub-theme is not updated. How can Drupal know that the sub-theme is not compatible?

dvessel’s picture

Status: Needs review » Needs work

That could be an issue. Sub-themes will still be able to set its core version but I think your right. It shouldn't be automatic since updating could cause some confusion.

It's a single line change.

What do you think of 'php'? Less likely to be a problem but I'm not sure.

johnalbin’s picture

subscribing. Need sleep now.

sociotech’s picture

Is this fix definitely making it into D7? Region inheritance would be great. Would be willing to help depending on what needs to be done.

Also, there are a number of other modules/themes who are using the .info file for settings that would benefit from being inherited:

Zen default theme settings (http://drupal.org/node/248103)
Panels 3 theme plugins (http://drupal.org/node/495654)
Skinr styles (http://drupal.org/project/skinr)

Would it make sense to have core handle .info setting inheritance in general and define a protocol for any module/theme that wants to take advantage of inheritance through the .info file?

Or perhaps define an accepted/standard method for module/theme developers to use in their own code to enable inheritance?

Or just let folks continue to roll their own solutions on a case-by-case basis?

effulgentsia’s picture

Subscribing. +1. Anyone up for updating this issue with a comment explaining the current state of the problem (has anything changed since #11) and re-rolling a patch?

jacine’s picture

+1. It's very odd that subthemes don't inherit custom regions.

Not sure what needs to be done at this point, or if it's possible to get this into Drupal 7.

sun’s picture

Status: Needs work » Postponed (maintainer needs more info)
star-szr’s picture

Subscribe

johnalbin’s picture

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

Nope, that issue is dealing with the bug that default values for theme settings are supposed to be inherited, but aren't.

This one is dealing with the other data not being inherited.

johnalbin’s picture

Version: 7.x-dev » 8.x-dev

Needs to be fixed in D8 first, then backported to D7.

hydra’s picture

Status: Needs work » Reviewed & tested by the community
StatusFileSize
new872 bytes

How about using NestedArray::mergeDeep? We would use the base_themes .info data as default for the subtheme and then override anything wich is redefined in the subthemes .info file.

In my manual tests, this seems to work fine.

hydra’s picture

Status: Reviewed & tested by the community » Needs review

Ups, wrong status, sry -> updated

star-szr’s picture

Issue tags: +Needs tests

Tagging for tests.

fubhy’s picture

Was asked to review this... Code looks good and is indeed a desirable feature. However, we really need tests for this.

fubhy’s picture

Status: Needs review » Needs work
fubhy’s picture

Needs to be fixed in D8 first, then backported to D7.

I am not really sure that we can backport this at all. Potentially breaks existing sites that run with base themes.

star-szr’s picture

Status: Needs work » Needs review
StatusFileSize
new4.89 KB
new4.04 KB

Here are some tests. I thought it would make sense to test sub-sub-themes here as well. Leaving the "Needs tests" tag until we hear back from testbot and someone else has a chance to review.

Status: Needs review » Needs work

The last submitted patch, 301295-29.patch, failed testing.

star-szr’s picture

Assigned: Unassigned » star-szr

The ThemeTest class is passing locally, but ThemeInfoStylesTest is not. I'll take a look tomorrow.

star-szr’s picture

Assigned: star-szr » Unassigned

Actually the patch from #23 will make ThemeInfoStylesTest fail on its own, the test is exposing a legitimate bug. #575298: Provide non-PHP way to reliably override CSS got committed a day after #23 was posted, so that's why it showed up green here. I'll trigger a re-test.

It looks like we shouldn't be merging everything from the base theme's .info, in this case doing so breaks the behaviour of stylesheets-override and stylesheets-remove.

star-szr’s picture

Status: Needs work » Needs review

#23: info_inherit-301295-23.patch queued for re-testing.

star-szr’s picture

StatusFileSize
new1.11 KB
new6.17 KB
new5.02 KB

The test+fix patch in #29 was only passing locally because I had a copy of the test grandchild theme in sites/default/themes for manual testing. I've updated theme_test_system_theme_info() to add the grandchild theme.

Attached are a revised test-only patch and a revised test+fix patch, as well as an interdiff from #23. I've put in a fix for the bug exposed in ThemeInfoStylesTest (see #32).

The 3 exceptions thrown in ThemeInfoStylesTest with the test-only patch are exposing this bug as well, because test_subtheme isn't inheriting the regions from test_basetheme.

sun’s picture

Title: automatically inherit .info theme settings » Automatically inherit theme .info properties from base themes to subthemes
Status: Needs review » Needs work

I'm not sure whether this change proposal makes sense.

What if a subtheme does not want or need a region from its base themes? How would the subtheme remove inherited properties?

I think this is essential, since most base themes are developed in a very generic way — if they wouldn't, then they wouldn't be base themes.

Therefore, base themes have e.g. a full range of potentially needed regions. But as a themer with a concrete site + theme at hand, I most often don't want to inherit all of those regions, because instead of abstract/generic, I have a very concrete and specific use-case and know exactly what regions I want to offer.

In essence, with this change, you'd have to supply me a way to undo any .info property of any ancestor theme; e.g., for the case of the regions property, I'd need a regions-remove[] property.

Furthermore, certain .info properties MUST NOT be inherited to subthemes; e.g., starting with the 'base theme' property itself, continuing with others like 'hidden', etc.pp. You also cannot merge the 'stylesheets' and 'scripts' properties, since all of the specified files would be additionally loaded from the subtheme otherwise.

In turn, this proposed merge algorithm is too naive and needs to be far more sophisticated anyway:

+++ b/core/modules/system/system.module
@@ -3060,6 +3061,16 @@ function _system_rebuild_theme_data() {
+    // Inherit the data from the current base theme, and override it with the
+    // specific subtheme settings.
+    $basetheme_info = $themes[$base_theme]->info;
+    // Remove stylesheets-override and stylesheets-remove from the info array,
+    // these settings should not be inherited by subthemes.
+    // @see _drupal_theme_initialize().
+    unset($basetheme_info['stylesheets-override'], $basetheme_info['stylesheets-remove']);
+    $nestedArray = new NestedArray();
+    $subtheme_info = $nestedArray::mergeDeep($basetheme_info, $themes[$key]->info);
+    $themes[$key]->info = $subtheme_info;
fubhy’s picture

Why don't we just do what the original issue title proposed? Merge the theme settings ...

sun’s picture

Title: Automatically inherit theme .info properties from base themes to subthemes » Automatically inherit theme .info settings from base themes to subthemes

Oh, ok. Sure, that's a different thing and probably more appropriate... (but not at all what the patch is doing)

That said, theme settings should actually be moved out of the .info files and be converted into config files in D8. I think we have an issue for that somewhere. Of course, that would mean a dramatically different merge process (and also different spot in the code base, in which merging can be considered).

star-szr’s picture

Closed #1535904: Subtheme inheritance: logo, regions, settings as a duplicate of this issue.

joelpittet’s picture

Version: 8.0.x-dev » 8.1.x-dev
Issue summary: View changes

This likely needs to be done in 8.1.x now.

Version: 8.1.x-dev » 8.2.x-dev

Drupal 8.1.0-beta1 was released on March 2, 2016, which means new developments and disruptive changes should now be targeted against the 8.2.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.2.x-dev » 8.3.x-dev

Drupal 8.2.0-beta1 was released on August 3, 2016, which means new developments and disruptive changes should now be targeted against the 8.3.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.0-alpha1 will be released the week of January 30, 2017, which means new developments and disruptive changes should now be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.0-alpha1 will be released the week of July 31, 2017, which means new developments and disruptive changes should now be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.0-alpha1 will be released the week of January 17, 2018, which means new developments and disruptive changes should now be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.6.x-dev » 8.7.x-dev

Drupal 8.6.0-alpha1 will be released the week of July 16, 2018, which means new developments and disruptive changes should now be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.7.x-dev » 8.8.x-dev

Drupal 8.7.0-alpha1 will be released the week of March 11, 2019, which means new developments and disruptive changes should now be targeted against the 8.8.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.0-alpha1 will be released the week of October 14th, 2019, which means new developments and disruptive changes should now be targeted against the 8.9.x-dev branch. (Any changes to 8.9.x will also be committed to 9.0.x in preparation for Drupal 9’s release, but some changes like significant feature additions will be deferred to 9.1.x.). For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.9.x-dev » 9.1.x-dev

Drupal 8.9.0-beta1 was released on March 20, 2020. 8.9.x is the final, long-term support (LTS) minor release of Drupal 8, which means new developments and disruptive changes should now be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 9.1.x-dev » 9.2.x-dev

Drupal 9.1.0-alpha1 will be released the week of October 19, 2020, which means new developments and disruptive changes should now be targeted for the 9.2.x-dev branch. For more information see the Drupal 9 minor version schedule and the Allowed changes during the Drupal 9 release cycle.

Version: 9.2.x-dev » 9.3.x-dev

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

catch’s picture

Category: Bug report » Task
Issue tags: +Bug Smash Initiative, +Needs issue summary update

This is an API improvement rather than a bug, moving to task. Also could use an issue summary update.

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.5.x-dev » 10.1.x-dev

Drupal 9.5.0-beta2 and Drupal 10.0.0-beta2 were released on September 29, 2022, which means new developments and disruptive changes should now be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 10.1.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch, which currently accepts only minor-version allowed changes. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 11.x-dev » main

Drupal core is now using the main branch as the primary development branch. New developments and disruptive changes should now be targeted to the main branch.

Read more in the announcement.