General developer forum

Access Config/Settings in AMD?

 
Picture of Benedikt Schneider
Access Config/Settings in AMD?
 

Hello all,

I am currently trying to access the mdl-config through AMD to initialize a table depending on the users' settings. I tried the core module core/config, but it only returns

admin: "admin"​
contextid: 1​
developerdebug: true​
iconsystemmodule: "core/icon_system_fontawesome"​
jsrev: -1​
sesskey: "7d95Hrz1Vu"​
slasharguments: 1​
svgicons: true​
theme: "boost_campus_tu"​
themerev: "1541437620"​
usertimezone: "Europa/Berlin"

How can I access the database / the full config with AMD?

Best regards,
Benedikt

Edit: I found this post which explains that I have to make a web service, which is easy to do - and apparently this is needed because there is no core web service which does this function, correct?

 
Average of ratings: -
Davo
Re: Access Config/Settings in AMD?
Core developersParticularly helpful MoodlersPlugin developers

Normally you would choose the specific config fields that are needed by the AMD module and pass them in as params when calling $PAGE->requires->js_call_amd('amd_module_name', 'init_function', $array_of_params);

Creating an AJAX webservice to retrieve arbitrary site config settings sounds like a potential security risk to me ...

 
Average of ratings: -
Picture of Benedikt Schneider
Re: Access Config/Settings in AMD?
 

Thank you for your response - I am only a part timer so my answer is late.

I tried using your approach wich worked, but it gave me an indexed array instead of an associative array, which gets confusing when using a few variables. In my case, this means 8 variables/settings and counting.

As of now, the webservice version is working as I already use webservices in my plugin. The settings I want to retrieve here are for my plugin only which means that there should be no security risk in returning unwanted/unauthorized config-settings.

Best regards
Benedikt

 
Average of ratings: -
Picture of Joby Harding
Re: Access Config/Settings in AMD?
Core developers

+1 for Davo's answer, use PHP to prepare the data you need and pass to your module in the initialisation call. It doesn't sound like your use case needs the complexity of a web service.

 
Average of ratings: -