Jump to content

Module select box


Recommended Posts

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

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. :P

(Sorry for beeing not much of help)

Link to comment
Share on other sites

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

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;
}  
  • Like 4
Link to comment
Share on other sites

  • 1 month later...

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...