Gadgetto Posted December 12, 2018 Share Posted December 12, 2018 Hello, here is my next question while starting module development in ProcessWire: I have created a new process module skeleton which installs fine. My process module directory looks like this: The problem is, that the .config.php file doesn't seem to be recognized by the installer. The config fields aren't displayed. Here is the code of the ProcessGoodNews.config.php file: class ProcessGoodNewsConfig extends ModuleConfig { public function __construct() { $this->add(array( array( 'name' => 'test', // name of field 'type' => 'text', // type of field (any Inputfield module name) 'label' => $this->_('Test'), // field label 'description' => $this->_('My test description'), 'required' => true, 'value' => $this->_('abc'), // default value ), )); } } I exactly followed the ProcessHello module sample which works as expected. Could it be that the name of my module is the problem? GoodNews (camel case). The .module.php class starts like this: class ProcessGoodNews extends Process { ... .. } Thanks in advance, Martin Link to comment Share on other sites More sharing options...
BitPoet Posted December 12, 2018 Share Posted December 12, 2018 Your ProcessGoodNews module needs to tell PW that it is configurable by having "implements ConfigurableModule" in the class declaration. 4 Link to comment Share on other sites More sharing options...
adrian Posted December 12, 2018 Share Posted December 12, 2018 Also, if you're going to use a separate config.php file, I think it's worth considering the $config = array() approach seen here: https://github.com/ryancramerdesign/Helloworld/blob/master/Helloworld.config.php 4 Link to comment Share on other sites More sharing options...
Gadgetto Posted December 12, 2018 Author Share Posted December 12, 2018 5 hours ago, BitPoet said: Your ProcessGoodNews module needs to tell PW that it is configurable by having "implements ConfigurableModule" in the class declaration. Thank you @BitPoet, but why does the ProcessHello module sample work without “implements ConfigurableModule”? This is confusing. Link to comment Share on other sites More sharing options...
Gadgetto Posted December 12, 2018 Author Share Posted December 12, 2018 4 hours ago, adrian said: Also, if you're going to use a separate config.php file, I think it's worth considering the $config = array() approach seen here: https://github.com/ryancramerdesign/Helloworld/blob/master/Helloworld.config.php Yes, this is definitely more strait forwards, thanks for the hint! Link to comment Share on other sites More sharing options...
flydev Posted December 13, 2018 Share Posted December 13, 2018 12 hours ago, Gadgetto said: Thank you @BitPoet, but why does the ProcessHello module sample work without “implements ConfigurableModule”? This is confusing. BitPoet is right but there is a subtlety. Actually you do not need to implement ConfigurableModule because when you use a MyModuleConfig.php along the module file, this new class extend the ModuleConfig class and thus you don't need to implements the ConfigurableModule or other configuration-specific code ! Your module IS configurable at that point. So regarding your fields configuration, it should work and if is not loading, I bet that a uninstall of the module and a Modules > Refresh and/or removing File Compiled/cache then re-installing the module will do the trick. Enjoy ?? ! 6 Link to comment Share on other sites More sharing options...
BitPoet Posted December 13, 2018 Share Posted December 13, 2018 7 hours ago, flydev said: Actually you do not need to implement ConfigurableModule because when you use a MyModuleConfig.php along the module file, this new class extend the ModuleConfig class and thus you don't need to implements the ConfigurableModule or other configuration-specific code ! Your module IS configurable at that point. That's right, and it's something that slipped past me somehow (looking into modules.php, both a MyModuleConfig.php and a MyModule.config.php should automagically make the module configurable). Thus, my bet is on a caching issue too, and it makes sense that adding an external module config without changing the original module file goes unnoticed by PW's module cache. Incrementing the version of MyModule and refreshing the modules should work too in that case. 2 Link to comment Share on other sites More sharing options...
Gadgetto Posted December 13, 2018 Author Share Posted December 13, 2018 OK, I'm still hanging on to this problem (which should not be a problem anymore because of your tips). - I uninstalled my module. - cleared the cache (/site/assets/cache/FileCompiler) - Increases the version number The .config is still not working. Any other idea? Link to comment Share on other sites More sharing options...
Robin S Posted December 14, 2018 Share Posted December 14, 2018 (edited) It's working for me using the code from your first post. ProcessGoodNews.zip If this module you're working on is going to be freely shared with community when finished then maybe it would be good to put your code into a public GitHub repo now so people can see the code and help you with problems that come up as you are developing it. Edited December 14, 2018 by Robin S Updated the module files to use separate info.php file 2 Link to comment Share on other sites More sharing options...
flydev Posted December 14, 2018 Share Posted December 14, 2018 On 12/12/2018 at 4:10 PM, Gadgetto said: Could it be that the name of my module is the problem? GoodNews (camel case). 14 hours ago, Gadgetto said: Any other idea? What say the line FILE in the module's information ? If it say nothing then rename the folder `GoodNews` to `ProcessGoodNews` and click on `Submit` on your module page, if still nothing, take a look at your database if there is any trace, on table `modules` and remove the corresponding entry of the module. Link to comment Share on other sites More sharing options...
Gadgetto Posted December 16, 2018 Author Share Posted December 16, 2018 On 12/12/2018 at 5:30 PM, adrian said: Also, if you're going to use a separate config.php file, I think it's worth considering the $config = array() approach seen here: https://github.com/ryancramerdesign/Helloworld/blob/master/Helloworld.config.php I changed the .config.php file to uses the $config = array() approach and now it works. This is very strange. Thanks, @adrian Link to comment Share on other sites More sharing options...
Gadgetto Posted December 16, 2018 Author Share Posted December 16, 2018 The problems go on: The module can now be installed and the config options are available, but if I go to the GoodNews page or try to uninstall the module, an error message is displayed: I took the code directly from Ryans GitHub repo: https://github.com/ryancramerdesign/Helloworld/blob/master/Helloworld.config.php and the documentation says: In order to make a string translatable in your template or module code, you just have to wrap the original string in a $this->_() or __() function call: $out = $this->_("Live long and prosper"); // syntax within a class $out = __("Live long and prosper!"); // syntax outside of a class If I change the translatable strings to _( it works. Using $config = array() in .config.php we are outside of a class or not? Is there a difference in using the $config = array() approach in process-modules? Link to comment Share on other sites More sharing options...
adrian Posted December 16, 2018 Share Posted December 16, 2018 __() works for me in a config.php file here: https://github.com/adrianbj/CookieManagementBanner/blob/master/CookieManagementBanner.config.php I know that's not very helpful though ? Perhaps it's a namespace issue - are you declaring the ProcessWire namespace, or have you turned off the file compiler (which is needed if you don't declare it). 1 Link to comment Share on other sites More sharing options...
Gadgetto Posted December 16, 2018 Author Share Posted December 16, 2018 28 minutes ago, adrian said: __() works for me in a config.php file here: https://github.com/adrianbj/CookieManagementBanner/blob/master/CookieManagementBanner.config.php I know that's not very helpful though ? Perhaps it's a namespace issue - are you declaring the ProcessWire namespace, or have you turned off the file compiler (which is needed if you don't declare it). CookieManagementBanner is not a process module (which my module is). And yes, I namespaced the module file. Here is the complete package, maybe somebody could have a look and tell me what's wrong? ProcessGoodNews.zip Link to comment Share on other sites More sharing options...
LostKobrakai Posted December 16, 2018 Share Posted December 16, 2018 You namespaced the file containing the module, but not the two other files. Namespaces are always per file, therefore each one needs the namespace declaration. 2 Link to comment Share on other sites More sharing options...
Gadgetto Posted December 16, 2018 Author Share Posted December 16, 2018 5 minutes ago, LostKobrakai said: You namespaced the file containing the module, but not the two other files. Namespaces are always per file, therefore each one needs the namespace declaration. OK --- this is new. ? Can't remember I saw other files than .module.php namespaced in other modules... Link to comment Share on other sites More sharing options...
LostKobrakai Posted December 16, 2018 Share Posted December 16, 2018 The crux here is that the file compiler usually takes care of older modules, which are not namespaced. Maybe those additional files are expected to be namespaced by the file compiler if your main module is namespaced. 1 Link to comment Share on other sites More sharing options...
Gadgetto Posted December 16, 2018 Author Share Posted December 16, 2018 This was the problem! It now works as expected. So each file (.module.php, .info.php and .config.php) need to be namespaced. Thanks all for your help! 4 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