Rudy Posted February 22, 2019 Share Posted February 22, 2019 Hi, I am writing a custom module that requires storing array of settings in the module config/settings. Is there a built-in fieldtype that allows me to store settings in an array (sort of like Repeater)? I tried using InputfieldAceExtended and InputfieldTextarea to store JSON array. Both times, my data was stored in the module settings (in the database) but upon reload, that information was not retrieved. Thanks Rudy Link to comment Share on other sites More sharing options...
flydev Posted February 23, 2019 Share Posted February 23, 2019 Hi Rudy, Storing a JSON array in a TextArea should works as expected without doing anything than saving the field in a standard fashion. protected static function getDefaultData() { return array( 'json_config' => '' ); } public static function getModuleConfigInputfields(array $data) { $data = array_merge(self::getDefaultData(), $data); $modules = wire('modules'); $fields = new InputfieldWrapper(); $field = $modules->get("InputfieldTextarea"); $field->label = __('JSON Config'); $field->attr('name+id', 'json_config'); $field->attr('value', $data['json_config']); $fields->append($field); return $fields; } 3 Link to comment Share on other sites More sharing options...
psy Posted February 23, 2019 Share Posted February 23, 2019 13 hours ago, Rudy said: Both times, my data was stored in the module settings (in the database) but upon reload, that information was not retrieved. The fact that the data is being stored in the database as json is good. On retrieval you need to explicitly tell PW what/where to put the data. For example, a textarea field only has one 'value'. In your config screen there a several fields which should be populated with bits of the json data. I think you're one step away. Retrieve the json then assign the individual bits to your module config inputfields 1 Link to comment Share on other sites More sharing options...
Rudy Posted February 23, 2019 Author Share Posted February 23, 2019 @flydev Thanks! I was missing this bit $field->attr('value', $data['json_config']); Cheers! 1 Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now