General developer forum

Call back for saving settings.php?

 
Picture of BAT BAT
Call back for saving settings.php?
 

I need to have a call back or a hook for some code to execute after the admin settings of my block are saved.  (Not while they are being looked at).   

I thought I found the block code "config_save(...)" but overriding that doesn't work.   Again, I don't even  need to change the way the admin settings are saved, I just need a hook to set the chron jobs?   


I am not using "instances" as the plugin I am working with (learning with) would be used for the Moodle site in general and not individual classes.


Any help would be great.


Thanks,
BAT

 
Average of ratings: -
Picture of Justin Hunt
Re: Call back for saving settings.php?
Particularly helpful MoodlersPlugin developers
One way you can do this is to use the set_updatedcallback function. This snippet is from the Generico filter, where it is used to bump an in internal version number.


//template body script
$setting = new admin_setting_configtextarea('filter_generico/templatescript_' . $tindex,
get_string('templatescript', 'filter_generico',$tindex),
get_string('templatescript_desc', 'filter_generico'),
'',PARAM_RAW);
$setting->set_updatedcallback('filter_generico_update_revision');
$settings_page->add($setting);

 
Average of ratings: Useful (1)
Picture of Darko Miletić
Re: Call back for saving settings.php?
Core developersParticularly helpful Moodlers

Every setting item has a method for setting a hook call whenever an update is executed. For example:

    $item = new admin_setting_configempty(
        'local_fooplug/mysetting',
        new lang_string('mysetting', 'local_fooplug'),
        new lang_string('mysetting_desc', 'local_fooplug')
    );

    $item->set_updatedcallback(function () {
        // Place here whatever you need.
    });




 
Average of ratings: Useful (1)
Picture of BAT BAT
Re: Call back for saving settings.php?
 

Thank you both!

I am not capturing the admin_setting object as a variable, I am merely pushing it immediately onto the ... std_object (I am guessing).   I didn't even realize it returned an object.  But that actually makes a lot f sense.  


Thanks again, you guys saved me hours and a really corny work-around.

Cheers,

BAT

 
Average of ratings: -