General developer forum

Set new block as hidden by default

 
Picture of Hal MacLean
Set new block as hidden by default
 
A bit of a strange one - I am hoping this is an easy thing I've overlooked somewhere!


I have a multi-tenanted moodle system (running v3.1) that has one set of code, but multiple databases - one for each client organisation. On log in we detect the URL and use the appropriate database to show the content for that client. 

However, when we add features and functionality to the system, such as adding a block, it will be installed for ALL organisations as it goes into the blocks directory on the server. Logging in to any of the organisation URLs takes us to the upgrade page and we complete the installation as per normal.

What I want to do is find a way to install a block such that it is not visible by default and then turn it on for each organisation, rather than go through and turn it off one at a time. I don't mind the log in and upgrade the database step - that's all fine - I simply want to find a way to have the block hidden by default once it is installed, so as not to allow it to appear for all, only for those I turn it on for.

As I said - a bit left of field, but any ideas gratefully received!

 
Average of ratings: -
Tim at Lone Pine Koala Sanctuary
Re: Set new block as hidden by default
Core developersDocumentation writersParticularly helpful MoodlersPlugin developers

Is this a block you wrote? If so, put some code in db/install.php to do the necessary config  change on install

$DB->set_field('block', 'visible', 0, ['name' => 'myblockname']);

If this is a third-party block, the you can do something similar in another plugin. (At the OU, we have a plugin tool_ouadmin, which we use for miscellaneous things like this.)

 
Average of ratings: -
Picture of Hal MacLean
Re: Set new block as hidden by default
 

Hi Tim - thanks for that, I'll give it a go.

No, this is a third party block. I'd be interested in seeing how you've developed your OU admin and what it does!

We have a fairly complex set up for around 25 different organisations all using the same code base, so anything we can use to make managing that easier would be good to have! For the most part, we need to turn on and off different blocks and plugins for different clients - each has their own moodle database so it isn't too bad, and things like themes are independent of course, but common code elements, like blocks, are a bit more tricky. 

 
Average of ratings: -
Tim at Lone Pine Koala Sanctuary
Re: Set new block as hidden by default
Core developersDocumentation writersParticularly helpful MoodlersPlugin developers

tool_ouadmin is just a bunch of random scripts that do different things. We just decided to make one Moodle plugin to hold them all.

 
Average of ratings: -