Jump to content

module classes confusion


fruid
 Share

Recommended Posts

I'm trying to understand the basics of module development in PW. I'm quite confused with the structure of it.

what I put figured out so far…

the object class "Process" is going to be applied as a "process" to the admin page and attach to the top menu of the admin panel.
The function __execute is what puts content on this page. 
Here's my first question: How can I add input fields for content to be added to the database?

then you have the module itself that will appear in the modules tab (and page tree under admin but hidden).
There I can add input fields via the class ModuleConfig and the function __construct
am I right?

but also, you can navigate to the modules section, overview of all site and core modules (and uninstalled ones and new ones) where you can see another "settings" button which doesn't appear on the module's detail page. (a bit weird, isn't it?)

anyways, long story short, I'm quite confused about the different classes and which one I should actually use when building a module and how to know.
I might add that I'm not a php expert, though I have built a bunch of websites with some rather complex templates in PW already, I still haven't touched any of this stuff. Maybe it's still some of my lack of understanding of php (also need to learn about the difference of implements and extends for example) but I feel that these PW classes are somewhat arbitrary. So is there a way to get more clarity on that?

  • Like 1
Link to comment
Share on other sites

Some of your questions will be answered by reading through the articles listed at https://processwire.com/docs/modules/, particularly the first three.

Also really helpful are the Hello World example modules described in the blog post https://processwire.com/blog/posts/pw-3.0.181-hello/.

And another excellent post is https://processwire.com/blog/posts/building-custom-admin-pages-with-process-modules/.

These will probably give you enough to start building useful modules. And I'd suggest that building a module or two (especially by following examples) would be the best way to get started, working things out as needed.

  • Like 7
Link to comment
Share on other sites

  • 7 months later...
On 4/17/2022 at 12:39 AM, fruid said:

the object class "Process" is going to be applied as a "process" to the admin page and attach to the top menu of the admin panel.
The function __execute is what puts content on this page. 
Here's my first question: How can I add input fields for content to be added to the database?

Here you are referring to ProcessModules. These provide custom pages in the admin. For an example see https://processwire.com/modules/process-hello/ and I also can strongly recommend the excellent blog post about ProcessModules linked by @BillH 

On 4/17/2022 at 12:39 AM, fruid said:

then you have the module itself that will appear in the modules tab (and page tree under admin but hidden).
There I can add input fields via the class ModuleConfig and the function __construct
am I right?

This is correct. You can read all about module configuration at https://processwire.com/blog/posts/new-module-configuration-options/ with examples both for the "old" and "new" way to implement your custom configuration fields.

On 4/17/2022 at 12:39 AM, fruid said:

but also, you can navigate to the modules section, overview of all site and core modules (and uninstalled ones and new ones) where you can see another "settings" button which doesn't appear on the module's detail page. (a bit weird, isn't it?)

There is no settings button on the module's detail page. Once you have implemented input fields for module configuration, they will appear underneat the module information. All configurable modules are also listed in the admin menu under Modules->Configure

 

On 4/17/2022 at 12:39 AM, fruid said:

anyways, long story short, I'm quite confused about the different classes and which one I should actually use when building a module and how to know.

When you are new to module development, the available classes can be quite confusing. But once you try and build a module yourself everything will get clearer. If you want to build custom pages in the admin, use a process module (https://processwire.com/modules/process-hello/). If you want to add general functionality, use a "normal" module (https://processwire.com/modules/helloworld/).

2 hours ago, gornycreative said:

ConfigurableModules class link from those pages leads nowhere helpful... a dead end.

This is because the API docs are auto-generated from the PW code. Since ConfigurableModule is an interface and not a class, the documentation for it is not being picked up by the script that generates the docs. But you have the path to the file in the core that defines the interface and there you have extensive documentation https://github.com/processwire/processwire/blob/master/wire/core/ConfigurableModule.php

  • Like 3
Link to comment
Share on other sites

16 hours ago, gebeer said:

This is because the API docs are auto-generated from the PW code. Since ConfigurableModule is an interface and not a class, the documentation for it is not being picked up by the script that generates the docs. But you have the path to the file in the core that defines the interface and there you have extensive documentation https://github.com/processwire/processwire/blob/master/wire/core/ConfigurableModule.php

Yup I get that.

Just a suggestion that if a link is going to be included in a tutorial 'Next Steps' a step should actually exist, or perhaps suggesting that a person look at the source code in core for documentation is in order.

The documentation in the source is very helpful - I think that's a feature that gets buried often and isn't brought up to new users. It was awhile before I realized how much extra information was in there for devs.

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