Jump to content

[SOLVED] Why doesn't ProcessWire recognize my [ProcessModuleName].config.php?


Gadgetto
 Share

Recommended Posts

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:

1988762761_Bildschirmfoto2018-12-12um16_01_22.png.c5eeb3122381f7b7fe2f3543362271cc.png

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

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

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 ?‍? !

  • Like 6
Link to comment
Share on other sites

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.

  • Like 2
Link to comment
Share on other sites

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

It's working for me using the code from your first post.

2018-12-14_152223.png.0a45433daed9cf800aecfda8cfd8ff16.png

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 by Robin S
Updated the module files to use separate info.php file
  • Like 2
Link to comment
Share on other sites

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

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

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:

718225641_Bildschirmfoto2018-12-16um17_17_47.thumb.png.bca3f0a7b045c67ea5d11f674a2f201e.png

 

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

__() 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).

  • Like 1
Link to comment
Share on other sites

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

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

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