Theme Clean no editor sheet?

Theme Clean no editor sheet?

by Gareth J Barnard -
Number of replies: 15
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers

Hi all,

In Moodle 2.6.1+ (Build: 20140117), Clean theme 'config.php' has '$THEME->editor_sheets = array();' and yet Bootstrap base has '$THEME->editor_sheets = array('editor');' so surely as Clean's definition overrides Bootstrapbase's then Clean has no editor styles?

Am I right?

Cheers,

Gareth

Average of ratings: -
In reply to Gareth J Barnard

Re: Theme Clean no editor sheet?

by Mary Evans -
Picture of Core developers Picture of Documentation writers Picture of Peer reviewers Picture of Plugin developers Picture of Testers

I thought that was the score but David Scotson said it inherits from Bootstrapbase.

This is not the case in Moodle standard theme as all themes carry their own.

In reply to Mary Evans

Re: Theme Clean no editor sheet?

by Gareth J Barnard -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers

Humm, if it appended, then maybe, but it is an assignment.  But how when you add more layout files to a bespoke theme that you need to copy completely '$THEME->layouts' otherwise if you only define the new ones you lose the old?

Need to test and somehow demonstrate a difference.

In reply to Gareth J Barnard

Re: Theme Clean no editor sheet?

by Mary Evans -
Picture of Core developers Picture of Documentation writers Picture of Peer reviewers Picture of Plugin developers Picture of Testers

If you add say layout/login.php, mydashboard.php and mypublic.php and providing that your other layout files use the same names as bootstrapbase then you only need to define those theme layouts which are different than bootstrapbase.

$THEME->layouts = array(
    'mydashboard' => array(
        'file' => 'mydashboard.php',
        'regions' => array('side-blocks',
        'defaultregion' => 'side-blocks',
        'options' => array('langmenu'=>true),
    ),
    'mypublic' => array(
        'file' => 'mypublic.php',
        'regions' => array('side-humpty', 'side-dumpty'),
        'defaultregion' => 'side-humpty',
    ),
    'login' => array(
        'file' => 'login.php',
        'regions' => array(),
        'options' => array('langmenu'=>true),
    ),

);

You only need the full layout if you are making changes to your block regions. But if your new layouts are the only places the layout sill be in then you only need to add those.

Average of ratings: Useful (1)
In reply to Mary Evans

Re: Theme Clean no editor sheet?

by Gareth J Barnard -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers

Thank you Mary, it does make sense.  But at the same time seems to break the general rules of assignment operators on global variables!  Or indeed any assignment operator when applied to the attribute of an object.

In reply to Gareth J Barnard

Re: Theme Clean no editor sheet?

by Gareth J Barnard -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers

Out of curiosity to see if $THEME was an instance of a specialised class like $OUTPUT is, I added the following to the end of the theme's 'config.php':

error_log(get_class($THEME));

Then in the error log:

[24-Jan-2014 23:12:35 UTC] stdClass
[24-Jan-2014 23:12:45 UTC] stdClass
[24-Jan-2014 23:12:45 UTC] stdClass
[24-Jan-2014 23:12:46 UTC] stdClass
[24-Jan-2014 23:12:46 UTC] stdClass
[24-Jan-2014 23:12:46 UTC] stdClass
[24-Jan-2014 23:12:47 UTC] stdClass
[24-Jan-2014 23:12:47 UTC] stdClass
[24-Jan-2014 23:12:47 UTC] stdClass
[24-Jan-2014 23:12:48 UTC] stdClass
[24-Jan-2014 23:12:48 UTC] stdClass
[24-Jan-2014 23:12:48 UTC] stdClass
[24-Jan-2014 23:12:48 UTC] stdClass
[24-Jan-2014 23:12:48 UTC] stdClass
[24-Jan-2014 23:12:49 UTC] stdClass
[24-Jan-2014 23:12:49 UTC] stdClass
[24-Jan-2014 23:12:49 UTC] stdClass
[24-Jan-2014 23:12:49 UTC] stdClass
[24-Jan-2014 23:12:49 UTC] stdClass
[24-Jan-2014 23:12:49 UTC] stdClass
[24-Jan-2014 23:12:50 UTC] stdClass
[24-Jan-2014 23:12:50 UTC] stdClass
[24-Jan-2014 23:12:50 UTC] stdClass
[24-Jan-2014 23:12:52 UTC] stdClass
[24-Jan-2014 23:12:52 UTC] stdClass
[24-Jan-2014 23:12:52 UTC] stdClass
[24-Jan-2014 23:12:52 UTC] stdClass
[24-Jan-2014 23:12:52 UTC] stdClass
[24-Jan-2014 23:12:52 UTC] stdClass
[24-Jan-2014 23:12:53 UTC] stdClass
[24-Jan-2014 23:12:53 UTC] stdClass
[24-Jan-2014 23:12:53 UTC] stdClass

After performing one page load with 'Theme designer mode' off.  Each line represents the parsing and processing of the file.  Is this a tad bonkers or what!

Gareth

In reply to Gareth J Barnard

Re: Theme Clean no editor sheet?

by Mary Evans -
Picture of Core developers Picture of Documentation writers Picture of Peer reviewers Picture of Plugin developers Picture of Testers

Are we talking about you or Moodle ? LOL

Only kidding!!!

To answer your question I am not sure as this is beyond me. I'm not really getting what it is that worries you.

Is it similar to the use of default block region, when you can actually change the order without declaring the default region?

Or like the Fake Blocks etc...

$OUTPUT or $THEMES which to use?  -> This caused problems with Logo in Clean theme because it had the incorrect setting $OUTPUT when it should have been $THEME.

Average of ratings: Useful (1)
In reply to Mary Evans

Re: Theme Clean no editor sheet?

by Gareth J Barnard -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers

Hi Mary,

RE: Are we talking about you or Moodle = ROFL! smile

To be honest, I'm not quite sure.  I think perhaps it is using $THEME as it should but perhaps interleaving on page load between different values for $THEME which have to be instantiated every time on a random alternating process.  Very inefficient.  When an auto loaded class hierarchy would be much better.  Just like 'theme_bootstrapbase_core_renderer' extends 'core_renderer' extends etc.... Then use methods to set the values in the constructor, but always call the parent first so that the settings in the bottom most child are applied last.  Perhaps something for a Moodle 3.0 re-write.

Cheers,

Gareth

In reply to Gareth J Barnard

Re: Theme Clean no editor sheet?

by Mary Evans -
Picture of Core developers Picture of Documentation writers Picture of Peer reviewers Picture of Plugin developers Picture of Testers

I thought parent CSS was applied first and child last. If it isn't then it should!

In reply to Mary Evans

Re: Theme Clean no editor sheet?

by Gareth J Barnard -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers

I'm not sure about the CSS, only the oddities with 'config.php' loading in the child and parent themes are well, umm, odd.

In reply to Gareth J Barnard

Re: Theme Clean no editor sheet?

by Gareth J Barnard -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers

Ok, if you add the following code:

error_log(print_r($THEME, true));

To the bottom of the Clean and Bootstrapbase config.php files, then you get the attached on a non-logged in front page load.  My first example was loading the editor page of the Book module.

Seems to be over the top.

In reply to Gareth J Barnard

Re: Theme Clean no editor sheet?

by Richard Oelmann -
Picture of Core developers Picture of Plugin developers Picture of Testers

Clean definitely inherits the editor style sheet from bootstrapbase

Very simple test - I added p {font-size:3em;color:red;} into the bootstrapbase editor.css file and then visited an editor using clean theme. The text is then large and red, so inherited from bootstrapbase.

As for the rest of the discussion about appending/assigning, layout files etc. I'm not sure I'm following what the problem is, but for the initial question, the Clean theme does inherit its editor.css from BootstrapBase.

R

Average of ratings: Useful (1)
In reply to Richard Oelmann

Re: Theme Clean no editor sheet?

by Gareth J Barnard -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers

Thanks all,

It seems that $THEME is not the same thing all the same time.  Ok, with the following at the bottom of the Clean, Bootstrapbase and Base theme config.php files:

error_log(print_r(debug_backtrace(), true));

It produces the attached log when using the URL to set the theme and loading the front page.  It appears that:

setup.php checks the theme is valid in the URL by loading it to the point of creating a theme_config object by using  'theme_config::load($themename)' in 'outputlib.php'.  This is then placed in $SESSION->theme.  But then is not used by pagelib.php 'initialise_theme_and_output()' when it repeats the entire process with the call to 'theme_config::load($themename)' in 'outputlib.php'.  setup.php is called from config.php which is called from index.php.  This appears to be inefficient.

'theme_config::load($themename)' in 'outputlib.php' has in it two lines:

if ($config = theme_config::find_theme_config($themename, $settings)) {
return new theme_config($config);

The first one just calls 'find_theme_config' but that method also loads the parents to check they are ok, but then ditches the parent theme data loaded:

        // verify the theme configuration is OK
        if (!is_array($THEME->parents)) {
            // parents option is mandatory now
            return null;
        } else {
            // We use $parentscheck to only check the direct parents (avoid infinite loop).
            if ($parentscheck) {
                // Find all parent theme configs.
                foreach ($THEME->parents as $parent) {
                    $parentconfig = theme_config::find_theme_config($parent, $settings, false);
                    if (empty($parentconfig)) {
                        return null;
                    }
                }
            }
        }

 As $parentconfig is lost.  The second line 'return new theme_config($config);' calls '__construct($config)' in 'outputlib.php' which calls 'find_theme_config' in 'outputlib.php' again for the parent themes and performs a second valid parent check:

 
        // verify all parents and load configs and renderers
        foreach ($this->parents as $parent) {
            if ($parent == 'base') {
                $parent_config = $baseconfig;
            } else if (!$parent_config = theme_config::find_theme_config($parent, $this->settings)) {
                // this is not good - better exclude faulty parents
                continue;
            }

 But this time decides to keep $parent_config if it is valid.  Now the parent in a parent check would be fine in 'find_theme_config' if we had grandparent - parent - child themes, but the code in '__construct($config)' appears to only go as far as processing the parents of the theme selected and no further.  So therefore the parent in a parent check in the line:

} else if (!$parent_config = theme_config::find_theme_config($parent, $this->settings))

is faulty because the third parameter is not 'false' which tells the method not to check parents.

The upshot of all of this is that I believe there is credible evidence for performance improvements that reduce file loads and memory allocate / deallocate of data which has been carefully processed and then lost.  Also I believe it demonstrates that we cannot have grandparent - parent - child themes or at least if that is the intent, then the data stored in 'config.php' of the theme is not processed correctly.  It also demonstrates that the Clean theme which uses Bootstrapbase as a parent also relies on the contents of the Base theme's config.php:

        if ($this->name != 'base') {
            $baseconfig = theme_config::find_theme_config('base', $this->settings);
        } else {
            $baseconfig = $config;
        }
 

....

        // cascade all layouts properly
        foreach ($baseconfig->layouts as $layout=>$value) {
            if (!isset($this->layouts[$layout])) {
                foreach ($this->parent_configs as $parent_config) {
                    if (isset($parent_config->layouts[$layout])) {
                        $this->layouts[$layout] = $parent_config->layouts[$layout];
                        continue 2;
                    }
                }
                $this->layouts[$layout] = $value;
            }
        }

 When perhaps it should only rely on the '$THEME->layouts' of Bootstrapbase being the primary parent theme.  Therefore conceptually, Base's config.php 'layouts' MUST be accurate for the Bootstrapbase -> Clean pair to work properly.

Ok, this is all complicated, but I think I have it described fairly accurately.  I welcome comments, testing suggestions and indeed possible solutions that would demonstrate a performance gain by optimising the code in a tracker improvement.  I know it may only shave a fraction of a second off the page load time, but what if you were to multiply that by the number of Moodle page loads across all the installations on the planet?  Could we actually save a bit of carbon footprint?

Cheers,

Gareth

P.S. The stack trace line numbers in the log file refer to files in Moodle version 2013111801.01 - release 2.6.1+ (Build: 20140117) if you wish to cross correlate them.

In reply to Gareth J Barnard

Re: Theme Clean no editor sheet?

by Gareth J Barnard -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers

P.P.S.

It looks like I've made a coding fault with my Shoelace and Mutant Banjo themes needing a '$THEME->editor_sheets = array('editor');' because they define their own and exclude the parent sheet and hence setting.  Will fix!  But Clean is fine.

You learn something new every day smile

In reply to Gareth J Barnard

Re: Theme Clean no editor sheet?

by Mary Evans -
Picture of Core developers Picture of Documentation writers Picture of Peer reviewers Picture of Plugin developers Picture of Testers

Taking notes...

Is that it?

In reply to Mary Evans

Re: Theme Clean no editor sheet?

by Gareth J Barnard -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers

I think so!  The constructor for theme_config being '__construct($config)' in 'outputlib.php' makes interesting reading.