Is there a user-customisable theme? If not, how do I create one?

Is there a user-customisable theme? If not, how do I create one?

by Devon R -
Number of replies: 10

Moodle version: 3.5.3 (build 20181112)

Theme name and version: Boost (2018051400)


Description: My aim is to use, or create, an accessible Theme, where users can specify the text and background colours they want to see.

I'm currently working through https://docs.moodle.org/dev/Creating_a_theme_based_on_boost and looking at https://docs.moodle.org/dev/Boost_Presets. I know a bit of HTML / CSS and SCSS, but it looks like PHP is what I really need here.

To avoid reinventing the wheel, I did check if a user-customisable theme was already available, but my brief search was unsuccessful. Did I use the wrong keywords or something? E.g. "theme user color choice" and similar.

If there isn't one, do you have any tips for creating it? Beyond "learn PHP" (I will soon, with codecademy) followed by "learn Moodle's terms for everything".


Screenshot: Something like the below image is what I have in mind for my users; they could choose the colour combinations that work for them. It doesn't have to be that detailed, but clearly it can be done.

I suppose I could get the relevant code from the 'More' theme, but finding it might be difficult. And then I would have to enable some permission/s for users to change it? But it might be tricky to ensure people can only change their own theme and that this preference would be remembered per user.

The alternative is to list multiple combinations as separate Themes (with user-choice enabled). Examples are like 'Dark blue text on light yellow background', 'Dark grey on light grey' or 'Light grey on dark grey' etc. However this seems pretty labour-intensive and difficult to maintain.

Attachment More theme settings.png
Average of ratings: -
In reply to Devon R

Re: Is there a user-customisable theme? If not, how do I create one?

by Jon Bolton -
Picture of Particularly helpful Moodlers Picture of Testers

There are lots of themes that can be customised and users can choose their own predefined theme, but not customise it.

The Accessibility plugin allows accessible overlays, font changes and colour changes which CAN be saved by the user (or at least can be saved as a cookie to their local machine), but is not a theme and is limited in design features.

Jessica Gramp at UCL is working on an accessible theme though - see https://blogs.ucl.ac.uk/digital-education/2017/07/10/accessible-moodle-theme/ for more information. Jessica is an active member of these forums and treasurer of the Moodle User Association.

Average of ratings: Useful (1)
In reply to Jon Bolton

Re: Is there a user-customisable theme? If not, how do I create one?

by Devon R -

(Whoops on my first reply! I didn't refresh the page as I didn't think anyone would have replied yet.)

Ah, fantastic! Thank you, that's exactly what I was after. The latest version is 3.5.3 and the block's latest is for 3.1, but it should be close enough. I'll upload the plug-in after the back-up's done.

Definitely looking forward to a more accessible theme, too! I'll get in touch and ask about how development is going. Thanks.

In reply to Devon R

Re: Is there a user-customisable theme? If not, how do I create one?

by Devon R -

So my question is now: Is there a permission similar to allowuserthemes that would allow presets to be specified? (Like allowuserthemepresets.) It would avoid the need to make and maintain multiple Themes, while users are only allowed a few options e.g. text and background colours.

It doesn't seem to exist, which makes the next part harder. I found the code in the More theme that I need, but my colleague (who knows much more PHP than I do) says they don't know where the function 'admin_setting_configcolourpicker()' would be called or how to display it.

 

I've attached my settings.php file, from the Boost-based theme building guide. At the end of the file, I pasted .php code from this post's GitHub link. I zipped the (mainly identical to 'Photo') theme folder, 'Lalio' and uploaded it as a new plugin. I received the generic error:

"Exception - Argument 1 passed to theme_boost_admin_settingspage_tabs::add_tab() must be an instance of admin_settingpage, instance of admin_setting_configcolourpicker given, called in [dirroot]/theme/boost/classes/admin_settingspage_tabs.php on line 49. More information about this error"

Any help is vastly appreciated, thank you!


In reply to Devon R

Re: Is there a user-customisable theme? If not, how do I create one?

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

There is not anything like 'allowuserthemepresets' and due to the way (very technical to explain) how Moodle generates the theme CSS, then the only current viable simple solution with a limited amount of settings for a per user basis is inline CSS on the web page.  But that's discouraged and not cached.  Or you could implement a theme CSS generation and serving mechanism (as Essential once did for static CSS) that stored each generated preset via the File API then served it with a caching system (such as using eTags).

Average of ratings: Useful (1)
In reply to Gareth J Barnard

Re: Is there a user-customisable theme? If not, how do I create one?

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

Also with the 'admin_setting_configcolourpicker()' issue:

  • Its not a function but a class constructor method.
  • In the context of how Boost settings are written differently to More, then the instantiated settings you copied and pasted need to be added to $page which will allow settings to be added to it, then the $settings which seems to be expecting an instance of 'admin_settingpage' whereby the 'add' method (probably) has a parameter type declaration of 'admin_settingpage' and is itself a method of 'theme_boost_admin_settingspage_tabs' class, as $settings has an instance of it.

And please smile, don't ask me to explain it any simply as I already have within the technical context of the question.

Average of ratings: Useful (1)
In reply to Gareth J Barnard

Re: Is there a user-customisable theme? If not, how do I create one?

by Devon R -

Thanks very much for your time and detailed explanation! I'll bookmark this until I get further along learning PHP and Moodle terms. (I also asked my colleague who knows PHP 6 about it, but they didn't understand because they're new to Moodle.) So I have another question if you have the time and inclination:

Would it be better / faster for me to learn PHP 7 etc, or for a more experienced coder to learn Moodle's terminology?

In reply to Devon R

Re: Is there a user-customisable theme? If not, how do I create one?

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

To learn Moodle's terminology (or at least the PHP element) then you need to understand object orientated (OO) PHP, thus also the concepts of OO.  Therefore, learn the foundation of PHP first.  Speed wise depends on you and your skills / ability.

Did your colleague say they know PHP 6?  If so then it does not exist and they are not telling the truth.

In reply to Gareth J Barnard

Re: Is there a user-customisable theme? If not, how do I create one?

by Devon R -

Ah. Right, I did nooot get on with C++ which I vaguely remember was object-oriented afaik.

And sorry about that, I checked about the numbering: I got it wrong. I just assumed "I don't know 7" meant there was a 6 that they did know.

In reply to Devon R

Re: Is there a user-customisable theme? If not, how do I create one?

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

Have you tried learning other OO languages such as Java or Smalltalk?

In reply to Gareth J Barnard

Re: Is there a user-customisable theme? If not, how do I create one?

by Devon R -

Neither of those, but yes to Python, if it counts. It seemed great until I got to 'for' and 'while' loops. There was one particular exercise on Khan Academy to write a simple factorial calculator: whatever non-working mess I came up with didn't resemble either of the two solutions they explained afterward (iterative and recursive).
IDK if 'R' is object-oriented, but I got on with it really well at uni. I much preferred it to Excel, which apparently surprised the other students.

I just finished most of Codecademy's courses on HTML and CSS, also Sass, so I'm going to start learning PHP in the next few days. Except some of the typos, Codecademy's hand-holding and forums really, really work for me. Really happy I gave it another shot!