Macrura Posted December 29, 2015 Share Posted December 29, 2015 Hi - i have a module i'm trying to improve so i added a page list select to the getModuleConfigInputfields function like this: $fieldDocsRoot = wire('modules')->get('InputfieldPageListSelect'); $fieldDocsRoot->attr('name+id', 'docsRoot'); $fieldDocsRoot->label = __('Docs Root', __FILE__); $fieldDocsRoot->description = __('Select the root page of your docs. (Allows the module to know where to create new docs.', __FILE__); $fieldDocsRoot->attr('title', __('Docs root', __FILE__)); $wrapper->add($fieldDocsRoot); i also tried to init the docRoot var up in __construct, but i can't figure out how to get it to save the page on that inputfield.. TIA Link to comment Share on other sites More sharing options...
kongondo Posted December 29, 2015 Share Posted December 29, 2015 (edited) This works for me //create the config screen $form = new InputfieldWrapper(); $p = 'selected'; $parentId = wire('pages')->get('/')->id; //pagelistselects $parentAdd = wire('modules')->get('InputfieldPageListSelect'); $parentAdd->label = __('Parent Page'); $parentAdd->attr('name+id', $p); $parentAdd->set('parent_id', $parentId); $parentAdd->set('startLabel', __('Parent Page')); $form->add($parentAdd); Edited December 29, 2015 by kongondo Link to comment Share on other sites More sharing options...
Macrura Posted December 29, 2015 Author Share Posted December 29, 2015 many thanks - but i can't seem to get the module to save the selected page; it shows the field but it reverts to unselection after you hit submit.. Link to comment Share on other sites More sharing options...
kongondo Posted December 29, 2015 Share Posted December 29, 2015 (edited) Are you sure its not saving? Un-selection is different from not saved ....Can you confirm by looking into the module's data field in the database? As for selection of saved data, I think there is a property for setting that but I can't find it now. You have to tell the module what is selected (saved) I believe. Let me see if I can find the property... Edited December 29, 2015 by kongondo Link to comment Share on other sites More sharing options...
kongondo Posted December 29, 2015 Share Posted December 29, 2015 Hmm...I can't find such a property. Not sure if the select label is coming from JS... Link to comment Share on other sites More sharing options...
Macrura Posted December 29, 2015 Author Share Posted December 29, 2015 right, i will check the database shortly... i've spent some hours looking at other modules including the menu builder, to try and figure out how to get a page list select to work for module setting... Link to comment Share on other sites More sharing options...
kongondo Posted December 29, 2015 Share Posted December 29, 2015 (edited) I tested with Blog module settings and it works (the saving bit) but couldn't figure out how to tell it to show the label of what's saved...I had a look at how this is done in page fields but the rabbit hole was too deep so turned back Edited December 29, 2015 by kongondo Link to comment Share on other sites More sharing options...
Macrura Posted December 29, 2015 Author Share Posted December 29, 2015 ok thanks - i will research again tonight and try and venture forth; in the meantime I might change it to an integer input ("please enter the page ID of the root for docs..") Link to comment Share on other sites More sharing options...
kongondo Posted December 29, 2015 Share Posted December 29, 2015 (edited) Sorted! Just add a value attribute $myModuleConfigs = wire('modules')->getModuleConfigData('YourModuleClassName'); $savedPageID= (int) $myModuleConfigs['selected'];// name of our input above (see my previous code => $p) $parentAdd->attr('value', $savedPageID);// (int) Saved paged ID #$parentAdd->value = $savedPageID;// alternative way to set For completeness, here's the full working code $form = new InputfieldWrapper(); $parentId = wire('pages')->get('/')->id; // pagelistselects $parentAdd = wire('modules')->get('InputfieldPageListSelect'); $parentAdd->label = __('Parent Page'); $parentAdd->attr('name+id', 'selected'); $parentAdd->set('parent_id', $parentId); $parentAdd->set('startLabel', __('Parent Page')); $data = wire('modules')->getModuleConfigData('YourModuleClassName'); $savedPageID = (int) $data['selected'];// name of our input above $parentAdd->attr('value', $savedPageID);// (int) Saved paged ID #$parentAdd->value = $savedPageID;// alternative way to set $form->add($parentAdd); Edited December 29, 2015 by kongondo Added full working code for completeness 4 Link to comment Share on other sites More sharing options...
Macrura Posted December 29, 2015 Author Share Posted December 29, 2015 whoa - sweet - super amplified thanks for this... just tested and totally works... ! Link to comment Share on other sites More sharing options...
Macrura Posted December 29, 2015 Author Share Posted December 29, 2015 In terms of building this module (PageDocsTab), i wonder how to deal with it needing to work with a 3rd party fieldtype, namely FieldtypeTemplates, because the way i have it working is that you specify on the doc which templates to show that particular doc on, so that field needs to be added to the template that is being used for "Docs'. I guess it could be in the instructions and also could be made a requirement that the fieldtype is installed before installing this one... and then once this module is installed it could create the required field, e.g. 'template_select'... Another question - i've looked through a bunch of modules and i was under the impression that if you had css or js named the same as the module that it would load them, and in some modules i don't see any code to load css or js, even though there are css and js files in the module folder; on the URL checker module, this code is used to get the css to load: $this->config->styles->add($this->config->urls->siteModules . __CLASS__ . '/' . __CLASS__ . '.css?v=' . time()); so is this the recommended/correct way? Link to comment Share on other sites More sharing options...
LostKobrakai Posted December 30, 2015 Share Posted December 30, 2015 The resource files with the same name as the module should be loaded automatically and even be cachebusted. But there might be rare edgecases, where you'd need to include them manually because processwire might load them to late or something. I'd only do that if the need arises. 1 Link to comment Share on other sites More sharing options...
Macrura Posted December 30, 2015 Author Share Posted December 30, 2015 this module definitely wasn't loading the .css file, but i have no idea why - could it be the name of the module? For now i'm able to get it to load using the code above, but would be curious as to why... Link to comment Share on other sites More sharing options...
kongondo Posted December 30, 2015 Share Posted December 30, 2015 (edited) It will only auto-load if in your module's init method you call parent::init(); then your code after that. The other conditions have to be true as well, i.e. the resources have to be in the same directory as the module and they have to be named as: MyModuleName.module MyModuleName.js MyModuleName.css What class is your module extending? I don't think the above works with all module types Edited December 30, 2015 by kongondo 1 Link to comment Share on other sites More sharing options...
Macrura Posted December 30, 2015 Author Share Posted December 30, 2015 great - thanks for the clarification - i think in my case i should only load the assets if the hook is run (which hooks into the page edit and adds a tab), because those assets are not needed unless those conditions are met.. Link to comment Share on other sites More sharing options...
Macrura Posted December 30, 2015 Author Share Posted December 30, 2015 What class is your module extending? I don't think the above works with all module types I'm extending WireData; this hooks into ProcessPageEdit::buildForm and adds a tab for the found documentation based on the template; but i realized that it shouldn't load the css/js by default, only when the hook runs, and i wasn't doing parent::init; i may need to rename the css if i need that parent init for some other reason. but that brings up another question - i also want to have a process module bundled in with this to render the global documentation page; right now i'm hacking it together by using admin custom pages and then calling this module's (render) method on that; i will look at some other modules that have submodules, so i guess it would install the 2nd module as a child and then i could still get the confiig data somehow (need it to find the root page to render, in the process module).. Link to comment Share on other sites More sharing options...
kongondo Posted December 30, 2015 Share Posted December 30, 2015 (edited) I doubt auto loading of resources will work with extending WireData Many modules (including Blog, Padloper, etc) are actually several modules bundled together, each fulfilling their specific role. So, that's OK, if you want to go that route. The important thing is to indicate which module requires which one and which one installs which one (if you wish, i.e., otherwise user installs each on its own). There's is no magic in respect of getting any module's config other than using what PW already provides: $anyModuleConfigs = wire('modules')->getModuleConfigData('AnyModuleClassName'); You can call that from anywhere, including in template files. It returns an array. It will be empty if there is no config data. https://processwire.com/talk/topic/648-storing-module-config-using-api/?p=5241 https://processwire.com/talk/topic/3343-how-can-i-setget-module-data-from-db-when-not-implementing-configurablemodule/?p=33087 Edited December 30, 2015 by kongondo Link to comment Share on other sites More sharing options...
Macrura Posted December 30, 2015 Author Share Posted December 30, 2015 I will carry on researching this (will check out blog module), this is/will be my first real module of any consequence... lot of stuff to learn, thanks for the help! Module Under Construction: https://processwire.com/talk/topic/11803-admindocstab/ 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