thetuningspoon Posted July 11, 2013 Share Posted July 11, 2013 I am experimenting with building a family of interrelated modules where the base module allows you to select which other modules to load. Ideally, I would like to have a select box in the main module's admin settings screen that lists the available modules that are installed and lets you select one of them. Is this possible? Link to comment Share on other sites More sharing options...
horst Posted July 11, 2013 Share Posted July 11, 2013 I am experimenting with building a family of interrelated modules where the base module allows you to select which other modules to load. Ideally, I would like to have a select box in the main module's admin settings screen that lists the available modules that are installed and lets you select one of them. Is this possible? Without knowing how, I can say yes. Because Somas Modules Manager exists and it knows all of my installed Modules. (Sorry for beeing not much of help) Link to comment Share on other sites More sharing options...
Soma Posted July 11, 2013 Share Posted July 11, 2013 Yeah it's possible. Link to comment Share on other sites More sharing options...
thetuningspoon Posted July 11, 2013 Author Share Posted July 11, 2013 I only briefly looked at the Modules Manager, but doesn't it create a new tab in the admin? I'm thinking of working within the module's basic configuration page. But it sounds like I may be wise to consider adding a tab in the admin for handling the module's various settings. I have some reading up to do on that. Link to comment Share on other sites More sharing options...
thetuningspoon Posted July 11, 2013 Author Share Posted July 11, 2013 Yeah it's possible. Well, good for you How would I build this, considering PW doesn't have a native select box field type, and we're dealing with modules instead of pages (so the pages field type seems like an unlikely fit)? Link to comment Share on other sites More sharing options...
arjen Posted July 11, 2013 Share Posted July 11, 2013 I remember Hani build a selectbox fieldtype while ago. Link to comment Share on other sites More sharing options...
Soma Posted July 11, 2013 Share Posted July 11, 2013 ModulesManager doesn't have tabs. Well I guess you already know you use getModuleConfigInputfields(array $data){ ... } to add configuration inputfields (not fields!) And you need to add the ConfigurableModule to the implements list (implements Module, ConfigurableModule). Now you can create a new InputfieldWrapper and add Inputfields to it. static public function getModuleConfigInputfields(array $data) { // if you have a static $defaults array for defaults you can merge them with saved ones in $data $data = array_merge(self::$defaults, $data); $fields = new InputfieldWrapper(); ... return $fields; } From there it's pretty easy. You can use all inputfield modules for inputs. It's much like creating a front-end form using API. Know my famous thread? Those inputfields are not bound to the fieldtype, like when used in the admin on pages. So the InputfieldSelect is a simple select module you can fill in options as you like. They're also used in FormBuilder. Ryan has even adapted some a little to support pure interactive inputs better. When used on a page (fields) they're actually a mix of the fieldtype and the inputfield and they depend on each other. Fieldtypes are more used to sanitize and save to db, wakup or sleep values etc, while inputfields kinda serve as an plain interface seen by the user, thus having a render() method. Some special Inputfields are more bound to functionality of other modules like "process" modules, but only remember InputfieldPageListSelect. From there it's just generaly PW API coding. So this would look like this to add a multiple ASM select static public function getModuleConfigInputfields(array $data) { $data = array_merge(self::$defaults, $data); $fieldwrapper = new InputfieldWrapper(); $modules = wire("modules"); $field = $modules->get('InputfieldAsmSelect'); $field->attr('name', 'mymodules'); $field->attr('value', $data['mymodules']); $field->label = 'Select modules.'; foreach($modules as $m) { // loop all installed modules if(strpos("$m->name","Process") === 0) $field->addOption("$m", "$m->className"); } $fieldwrapper->append($field); return $fieldwrapper; } 4 Link to comment Share on other sites More sharing options...
thetuningspoon Posted July 11, 2013 Author Share Posted July 11, 2013 Thank you Soma, I got it working! Thanks for the clarification. Link to comment Share on other sites More sharing options...
Martijn Geerts Posted August 29, 2013 Share Posted August 29, 2013 Thank Soma, you saved the evening ! 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