Access Config/Settings in AMD?

Access Config/Settings in AMD?

by oa73neve Königstein -
Number of replies: 3

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: -
In reply to oa73neve Königstein

Re: Access Config/Settings in AMD?

by Davo Smith -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin 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 ...

In reply to Davo Smith

Re: Access Config/Settings in AMD?

by oa73neve Königstein -

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

In reply to oa73neve Königstein

Re: Access Config/Settings in AMD?

by Joby Harding -

+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.