Alter Moodle Administrator

Alter Moodle Administrator

by Surya Pratap -
Number of replies: 12

Hi all,

I am a new comer in Moodle development. I have an unique requirement regarding Moodle Administrator. I need to provide change theme permission to custom role i.e, this custom role can change the theme just like Moodle admin did. Is there any possibility? Please guide me.  

Is this possible? 

If yes, then anyone please suggest me how can I achieve this?

If no, then what is the reason behind that? 

Is Moodle provide any settings for the same or I need to create a custom plugin in order to achieve the requirement? 

Any help would be appreciated. 


Thanks in advanced

Surya Pratap

Moodle Developer


Average of ratings: -
In reply to Surya Pratap

Re: Alter Moodle Administrator

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

I’m fairly sure that there is no capability that specifically controls themes; it’s tied to the permission for "Change site configuration", which will allow much more than just selecting a theme.

But if you allow category and/or user themes in Site Administration > Themes > Theme settings, then the teacher role can choose the theme for their course from the list of installed themes, and any role that is allowed to edit the category settings can choose a theme for that category.

Themes are "inherited" from a higher context, so if you set a category theme, it will be used by all courses in that category unless overridden in a course.

You might also be interested in this plugin: https://moodle.org/plugins/block_theme_selector - it uses the setting for "Allow theme changes in the URL" which can also be found in Site Administration > Themes > Theme settings and allows any user to change the theme for a particular session, but only for their own view.

See https://docs.moodle.org/36/en/Theme_settings for more info.

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

Re: Re: Alter Moodle Administrator

by Surya Pratap -
Hi Jon, thanks for the reply.

Can we create a plugin for the same? Just like this plugin provides the functionality to change the theme.
For Example, I have created a role named `Theme change` now I want to write some code snippet in my custom plugin to provide the theme changing permission to this role like override `load_administration_settings` method. Is it possible what I am thinking?

Thanks in advanced.
In reply to Surya Pratap

Re: Alter Moodle Administrator

by Joost Elshoff -
Picture of Particularly helpful Moodlers Picture of Testers
Hi Surya,
There is a clear distinction between a site administrator and a user with a site level assigned role 'manager'. The first has access to all things site administration, including configuration, the latter only has access to users and courses, and some features that don't necessarily fall under 'configuration'.

Theme changes are considered config changes. This means a user needs to have site administrator permission to change themes, if this applies to the entire site. If the theme changes only apply to a certain category, enabling category themes (Site admin > Appearance > Theme settings) would allow a user with a 'manager' role assigned at category level to change themes for a specific category.

Kind regards,

Joost
In reply to Joost Elshoff

Re: Re: Alter Moodle Administrator

by Surya Pratap -
Hi Joost, thanks for the instant reply.
My requirement is to create a new role in Moodle and provide the only theme changing permission for this role. Is it possible in Moodle?
If this functionality required a custom plugin then suggest the process.
If this is not possible then let me know the reason. Any help would be appreciated.

Thanks and regards
Surya Pratap
In reply to Surya Pratap

Re: Alter Moodle Administrator

by S. kavita -
Picture of Testers
Hi Surya,
The capability is not there specific to theme which you can add to a role. There is a ticket in Moodle Tracker, you can also ask help there https://tracker.moodle.org/browse/MDL-50377
Average of ratings: Useful (1)
In reply to S. kavita

Re: Re: Alter Moodle Administrator

by Surya Pratap -
Hi Kavita,
Thanks for the reply. Can we override the Moodle core code in order to achieve this requirement?
In reply to Surya Pratap

Re: Re: Re: Alter Moodle Administrator

by Joost Elshoff -
Picture of Particularly helpful Moodlers Picture of Testers
Hi Surya,
Please think twice about changing Moodle core code: it's not recommended to do so and makes updating to future versions a really problematic challenge.

Why would you want a specific user to only have access to changing the site's theme (and no access to other config components)?
Currently, access to themes and theme settings is managed under the permission 'moodle/site:config', and I don't see an easy way of working around that, other than what John and S. Kavita said.
In reply to Joost Elshoff

Re: Re: Re: Re: Alter Moodle Administrator

by Surya Pratap -
Hi Joost,
According to the requirement I need to provide a specific setting in Moodle who can provide the functionality to change the only theme.
is there any way or solution?
For core override, I have created a custom plugin for the same and used the core Moodle classes and trying to alter override method `load_administration_settings` but not able to do that.
Is this the correct way in order to achieve the requirement?
John and S. Kavita's suggestion is appreciated but my client is stick to the requirement. I need to provide him a solution or a genuine reason for the same.

Thanks for the contribute
In reply to Surya Pratap

Re: Re: Re: Re: Re: Alter Moodle Administrator

by Howard Miller -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers
If I had to do this... I would create a local plugin that added a new entry in the Administration settings that duplicates the theme selection. This could then define its own capability.

Do not modify core Moodle code.
Average of ratings: Useful (2)
In reply to Howard Miller

Re: Re: Re: Re: Re: Re: Alter Moodle Administrator

by Surya Pratap -
Hi Howard,

Thanks for the reply this would be a very useful one. Will trying to implement this. If you have any code snippet then, please provide or suggest.

Thanks in advanced.
In reply to Surya Pratap

Re: Re: Re: Re: Re: Re: Re: Alter Moodle Administrator

by Gemma Lesterhuis -
Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers
Hi Surya,
I would go with Howards approach, but a small question on my end - just for curiosity: Why do you need a seperated role to change the theme on site level?

Gemma
Average of ratings: Useful (1)
In reply to Howard Miller

Re: Re: Re: Re: Re: Re: Alter Moodle Administrator

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

I would go with Howard’s approach, but like Gemma, I’m curious about the requirement. A site wide theme affects all users, so really does not need to be changed frequently at all. As I explained earlier, teachers and others can already choose their own themes for their own courses from a list of already installed themes, and can change it whenever they want.

It seems that you’re going to have a LOT of work to get a setting just to be able to change something on a fairly irregular basis.

Average of ratings: Useful (1)