edit_form.php and settings.php

edit_form.php and settings.php

Gerald Henzinger írta időpontban
Válaszok szám: 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. mosoly

Gerald

Értékelések átlaga: -
Válasz erre: Gerald Henzinger

Re: edit_form.php and settings.php

Tim Hunt írta időpontban
Kép Kép Kép Kép Kép

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

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

Válasz erre: Tim Hunt

Re: edit_form.php and settings.php

Gerald Henzinger írta időpontban

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

Válasz erre: Gerald Henzinger

Re: edit_form.php and settings.php

Tim Hunt írta időpontban
Kép Kép Kép Kép Kép

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

Válasz erre: Tim Hunt

Re: edit_form.php and settings.php

Gerald Henzinger írta időpontban

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

 

Válasz erre: Gerald Henzinger

Re: edit_form.php and settings.php

Tim Hunt írta időpontban
Kép Kép Kép Kép Kép

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

Válasz erre: Tim Hunt

Re: edit_form.php and settings.php

Greg J Preece írta időpontban

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. mosoly Thanks!

Válasz erre: Greg J Preece

Re: edit_form.php and settings.php

Tim Hunt írta időpontban
Kép Kép Kép Kép Kép

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.

Értékelések átlaga:Useful (1)
Válasz erre: Tim Hunt

Re: edit_form.php and settings.php

Greg J Preece írta időpontban

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.

Válasz erre: Tim Hunt

Re: edit_form.php and settings.php

Greg J Preece írta időpontban

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.