gebeer Posted January 8, 2019 Share Posted January 8, 2019 Hello all, I am currently developing a process module that will create 2 templates and add pages to the page tree that are then being displayed within the module. I'd like to use existing fields for the templates instead of creating my own where possible and have the code for template and page creation inside the install method. Is there a way to let the user choose module options (in my case fields from a select dropdown) before the module is even installed? Is there a generic PW way to go about this? 1 Link to comment Share on other sites More sharing options...
flydev Posted January 8, 2019 Share Posted January 8, 2019 maybe still a little early to think properly but in this case, instead writing the logic on the __install() method itself, you could present a ProcessModule where in the first instance, the user choose what's needed then he click on the button "Proceed to install". Or another way could be to present a standard template/page with a Hook which install the module on Page::save. I think you get what I mean. 1 Link to comment Share on other sites More sharing options...
gebeer Posted January 8, 2019 Author Share Posted January 8, 2019 7 minutes ago, flydev said: maybe still a little early to think properly but in this case, instead writing the logic on the __install() method itself, you could present a ProcessModule where in the first instance, the user choose what's needed then he click on the button "Proceed to install". This is exactly the scenario I have in mind. My question is how to implement that. Is there a standard method for modules that handles stuff prior to installation, like in my case letting the user choose some fields to use? All the modules I installed so far have a configuration screen after install. I never saw one with configuration options prior to install. Hence my question. Link to comment Share on other sites More sharing options...
flydev Posted January 8, 2019 Share Posted January 8, 2019 To implement that is quite simple, check this small starting point, it should give you the idea : Spoiler <?php namespace ProcessWire; class ProcessGebeer extends Process { public static function getModuleInfo() { return array( // The module's title, typically a little more descriptive than the class name 'title' => 'Process Gebeer', // version number 'version' => '1.0.0', // summary is brief description of what this module is 'summary' => 'An example module used for demonstration purposes.', // Optional URL to more information about the module 'href' => 'https://processwire.com', // Optional font-awesome icon name, minus the 'fa-' part 'icon' => 'smile-o', 'page' => array( 'name' => 'processgebeer', 'parent' => 'setup', 'title' => 'Process Gebeer' ) ); } public function init() { parent::init(); } public function ___execute() { $out = '<h1>ProcessGebeer</h1>'; $fs = $this->modules->get('InputfieldFieldset'); $fs->label = 'First Step'; $form = $this->modules->get('InputfieldForm'); $form->action = './install'; $f = $this->modules->get('InputfieldAsmSelect'); $f->attr('name', 'select-fields'); $f->label = 'Choose fields'; foreach($this->fields as $field) { $f->addOption($field->name, $field->title); } $form->add($f); $f = $this->modules->get('InputfieldSubmit'); $f->attr('name', 'submit'); $f->value = 'Proceed Install'; $form->add($f); $fs->add($form); $out .= $fs->render(); return $out; } public function ___executeInstall() { // check/save previous settings, etc... // create template with fields... // redirect to './installcomplete' when done.. return 'Proceeding to installtion, creating templates with selected fields...'; } public function ___executeInstallComplete() { // install complete return 'Installation complete...'; } } 6 Link to comment Share on other sites More sharing options...
gebeer Posted January 8, 2019 Author Share Posted January 8, 2019 Thanks a lot @flydev So everything goes in the execute method. This will be called after installation which is also fine for me. 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