The Definitive Guide to Drupal 7

Inheritance and How it Works

You already know that Drupal provides a lot of markup in its modules, and that this markup comes in the form of templates, theme functions, or the Render API. In Drupal themes you have the opportunity to override and take over this behavior. So, technically, you are inheriting it in the first place. Using subthemes allows you to add one more step to the process. When using a parent theme, all of the assets—including template files, CSS files, JavaScript files, theme functions, and pretty much everything in template.php—are inherited.

CSS, JavaScript, template files, and theme functions defined in a base theme will automatically be available for the subtheme. The subtheme doesn’t have to do anything for this to happen. It just works. Preprocess and process functions will run for both the base and the subtheme, so they can be used in both themes simultaneously without issue. Of course, the subtheme can override anything the base theme has done.

Some things don’t work this well. Regions are not inherited, and neither are features or theme settings. In order for these to work properly, you’ll have to copy the information from the base theme into the subtheme’s .info file. Table 16–4 shows which assets are automatically inherited and which ones are not.

Table 16–4. Inheritance of assets from base theme to subthemes
Asset Automatically Inherited?
CSS files Yes
JavaScript files Yes
Template files Yes
Theme Screenshot Yes
Regions No
Theme Settings No

You are reading content from two chapters on Theme Development from The Definitive Guide to Drupal 7, written by Jacine Luisi and published by Apress on July 19, 2011. All rights reserved.