edit_form.php and settings.php

edit_form.php and settings.php

por Gerald Henzinger -
Number of replies: 9

Dear Everyone,

I am a little confused about the correct implementation of moodle blocks and a configuration page.

There is edit_form.php an settings.php?
What is the difference?

Many thanks. sorrisa

Gerald

Average of ratings: -
In reply to Gerald Henzinger

Re: edit_form.php and settings.php

por Tim Hunt -
Imaxe de Core developers Imaxe de Documentation writers Imaxe de Particularly helpful Moodlers Imaxe de Peer reviewers Imaxe de Plugin developers

settings.php is for global, site-wide settings.

edit_form.php is for settings that relate to one instance of the block.

In reply to Tim Hunt

Re: edit_form.php and settings.php

por Gerald Henzinger -

Thank you for this answer!

I am using the settings.php and I wanted to override the config_save() procedure in the block_XXXX.php. Since Version 2.0, this is not working anymore.

How can I add some functionality to the saving process of "settings.php"?

Many Thanks

Gerald

In reply to Gerald Henzinger

Re: edit_form.php and settings.php

por Tim Hunt -
Imaxe de Core developers Imaxe de Documentation writers Imaxe de Particularly helpful Moodlers Imaxe de Peer reviewers Imaxe de Plugin developers

You can't. settings.php files don't work like that.

The settings.php files are the same for all plugins. To understand how they work, see http://docs.moodle.org/dev/Admin_settings

In reply to Tim Hunt

Re: edit_form.php and settings.php

por Gerald Henzinger -

Maybe I should explain what i did with Mdl1.9

I created a now block with a configuration site, the config_global.html.

One parameter had influence so some other DB tables. So I overrided the function config_save() of the block class and it worked fine.

This was in 1.9, currently I want the same within Mdl2.0.

I learnt, that Mdl2.0 isn´t supporting config_save() anymore.

Is there any possibility for adding some functionality when saving the global configuration of a block?

Many Thanks

G

 

In reply to Gerald Henzinger

Re: edit_form.php and settings.php

por Tim Hunt -
Imaxe de Core developers Imaxe de Documentation writers Imaxe de Particularly helpful Moodlers Imaxe de Peer reviewers Imaxe de Plugin developers

Yes, it is possible. You need to understand how settings.php files work. See the link I gave you above.

In reply to Tim Hunt

Re: edit_form.php and settings.php

por Greg J Preece -

Hi Tim,

I've been trying to figure out how to do this myself, in order to encrypt passwords in my settings form before saving them. I've had settings.php in place for some time, and I've got a couple of external admin pages also working for some other settings, but I've read through the docs and some of the code, and I can't seem to find any solid info on overriding how a particular setting in settings.php is written to the database. Any hints on where to look in the code, or working examples, would be very helpful. I know from the linked post that I can do this for instance forms, so I imagine there's a way to do it in admin forms.

http://moodle.org/mod/forum/discuss.php?d=195453


Just to clarify, I'm building a block rather than a standard module. sorrisa Thanks!

In reply to Greg J Preece

Re: edit_form.php and settings.php

por Tim Hunt -
Imaxe de Core developers Imaxe de Documentation writers Imaxe de Particularly helpful Moodlers Imaxe de Peer reviewers Imaxe de Plugin developers

You define the settings by creating instances of classes like

new admin_setting_configtext(...)

Those classes are defined in lib/adminlib.php.

If you create a new class

class admin_setting_configtext_encrypted extends admin_setting_configtext {

}

then you can control how the setting is loaded and saved from the DB.

Average of ratings:Useful (1)
In reply to Tim Hunt

Re: edit_form.php and settings.php

por Greg J Preece -

Bingo, it was that last part I needed. Thanks Tim. I'll have a nose through the code of the existing classes and figure out how to extend one as you suggested.

In reply to Tim Hunt

Re: edit_form.php and settings.php

por Greg J Preece -

Just a quick follow-up on this. I extended the admin_setting_configpasswordunmask class as directed, overrode the necessary methods (get_setting and write_settings), and got it working just dandy. Passwords are encrypted to the database and retrieved properly. The one very minor issue that I have is that these two settings are displayed on every upgrade or installation of the block as being new settings, even if they already existed. Do you know what criteria Moodle uses to decide whether a setting is new? I only overrode those two methods, so I can't see what would be causing it in my code.

Thanks again for your help on this. Turned out to be really easy once I found the right classes.