Executing code after saving settings.php

Executing code after saving settings.php

oa73neve Königstein發表於
Number of replies: 3

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

評比平均分數: -
In reply to oa73neve Königstein

Re: Executing code after saving settings.php

Tim Hunt發表於
Core developers的相片 Documentation writers的相片 Particularly helpful Moodlers的相片 Peer reviewers的相片 Plugin 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.

In reply to Tim Hunt

Re: Executing code after saving settings.php

oa73neve Königstein發表於

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

In reply to oa73neve Königstein

Re: Executing code after saving settings.php

Tim Hunt發表於
Core developers的相片 Documentation writers的相片 Particularly helpful Moodlers的相片 Peer reviewers的相片 Plugin 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.