General developer forum

Executing code after saving settings.php

 
Picture of Benedikt Schneider
Executing code after saving settings.php
 

Hello everyone

What I want to do:
After installing my block-plugin, the user can decide if the block is shown on every (invisble) course page. (This can be done and undone by a simple database-entry and automates the steps which are shown here)

What I have tried so far:
- Executing the code in the install.php which works fine but does not give the user a chance to refuse or undo the settings.
- Using the settings.php to store the users' decision (current iteration)

My question:
Is there an event which triggers after the settings have been saved? I couldn't find one in the events2-doc.
Or is there an easier way to do what I want to do?

Best regards,
Benedikt

 
Average of ratings: -
Tim at Lone Pine Koala Sanctuary
Re: Executing code after saving settings.php
Core developersDocumentation writersParticularly helpful MoodlersPlugin developers

One way to do this is to use a custom admin_setting subclass. Then you can override the write_setting method.

admin_setting_enablemobileservice in lib/adminlib.php is an example you could copy.

 
Average of ratings: -
Picture of Benedikt Schneider
Re: Executing code after saving settings.php
 

Thank you very much! This truly helped me.

A thing I still had to do after executing my code was to redirect to the settings-page as Moodle just gave me a blank white page, although the settings were saved and the code executeds successfully.

With best regards,
Benedikt Schneider

 
Average of ratings: -
Tim at Lone Pine Koala Sanctuary
Re: Executing code after saving settings.php
Core developersDocumentation writersParticularly helpful MoodlersPlugin developers

A blank white page is normally the sign of a PHP fatal error.

When you are doing development, you really should have Debugging on, so you see the error message.

 
Average of ratings: -