Commit b822b567 authored by Aaron Wells's avatar Aaron Wells
Browse files

Let a theme specify that it has no parent

Bug 1410638. Currently, a theme that specifies no $theme->parent
in its themeconfig.php is forced to use "raw" as its parent.
With this patch, there are three options:

1. $theme->parent = false; : No parent theme.
2. $theme->parent = "sometheme"; : Sometheme is the parent
3. $theme->parent not defined at all: "raw" is the parent

Change-Id: Ibfeeae246b0f505b5759ee77eeed32467c464cab
parent 21def584
......@@ -898,28 +898,38 @@ class Theme {
* Given a theme name, reads in all config and sets fields on this object
*/
private function init_theme($themename, $themedata) {
$this->basename = $themename;
$themeconfigfile = get_config('docroot') . 'theme/' . $this->basename . '/themeconfig.php';
if (!is_readable($themeconfigfile)) {
// A little anonymous function to retrieve *only* the $theme variable from
// the themeconfig.php file
$getthemeconfig = function($themename) {
$themeconfigfile = get_config('docroot') . 'theme/' . $themename . '/themeconfig.php';
if (is_readable($themeconfigfile)) {
require( get_config('docroot') . 'theme/' . $themename . '/themeconfig.php' );
return $theme;
}
else {
return false;
}
};
$themeconfig = $getthemeconfig($themename);
if (!$themeconfig) {
// We can safely assume that the default theme is installed, users
// should never be able to remove it
$this->basename = 'default';
$themeconfigfile = get_config('docroot') . 'theme/default/themeconfig.php';
$themename ='default';
$themeconfig = $getthemeconfig($themename);
}
require($themeconfigfile);
$this->basename = $themename;
foreach (get_object_vars($theme) as $key => $value) {
foreach (get_object_vars($themeconfig) as $key => $value) {
$this->$key = $value;
}
if (!isset($this->displayname)) {
$this->displayname = $this->basename;
}
if (!isset($theme->parent) || !$theme->parent) {
$theme->parent = 'raw';
}
// Local theme overrides come first
$this->templatedirs[] = get_config('docroot') . 'local/theme/templates/';
......@@ -928,21 +938,37 @@ class Theme {
$this->templatedirs[] = get_config('docroot') . 'theme/' . $this->basename . '/templates/';
$this->inheritance[] = $this->basename;
// 'raw' is the default parent theme
// (If a theme has no parent, it should set $themeconfig->parent = false)
if (!isset($themeconfig->parent)) {
$themeconfig->parent = 'raw';
}
$currentthemename = $this->basename;
while ($themeconfig->parent !== false) {
// Now go through the theme hierarchy assigning variables from the
// parent themes
$parentthemename = $themeconfig->parent;
$parentthemeconfig = $getthemeconfig($parentthemename);
// If the parent theme is missing, short-circuit to the "raw" theme
if (!$parentthemeconfig) {
log_warn("Theme \"{$currentthemename}\" has missing parent theme \"{$parentthemename}\".");
$parentthemename = 'raw';
$parentthemeconfig = $getthemeconfig($parentthemename);
}
$currentthemename = $parentthemename;
$themeconfig = $parentthemeconfig;
// Now go through the theme hierarchy assigning variables from the
// parent themes
$currenttheme = $this->basename;
while ($currenttheme != 'raw') {
$currenttheme = isset($theme->parent) ? $theme->parent : 'raw';
$parentconfigfile = get_config('docroot') . 'theme/' . $currenttheme . '/themeconfig.php';
require($parentconfigfile);
foreach (get_object_vars($theme) as $key => $value) {
foreach (get_object_vars($themeconfig) as $key => $value) {
if (!isset($this->$key) || !$this->$key) {
$this->$key = $value;
}
}
$this->templatedirs[] = get_config('docroot') . 'theme/' . $currenttheme . '/templates/';
$this->inheritance[] = $currenttheme;
$this->templatedirs[] = get_config('docroot') . 'theme/' . $currentthemename . '/templates/';
$this->inheritance[] = $currentthemename;
if (!isset($themeconfig->parent)) {
$themeconfig->parent = 'raw';
}
}
if (!empty($themedata->headerlogo)) {
......
......@@ -8,9 +8,10 @@
* @copyright For copyright information on Mahara, please see the README file distributed with this software.
*/
$theme = new StdClass;
$theme = new stdClass();
$theme->displayname = 'Default';
/* Set parent to boolean FALSE to specify the theme has no parent */
$theme->parent = 'raw';
/**
......
......@@ -8,10 +8,11 @@
* @copyright For copyright information on Mahara, please see the README file distributed with this software.
*/
$theme = new StdClass;
$theme = new stdClass();
$theme->displayname = 'Raw';
$theme->formrenderer = 'table';
$theme->parent = false;
/**
* There are more themeconfig options available. For an explanation of
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment