Jump to content

Available module functions and variables


benbyf
 Share

Recommended Posts

Hello. Im looking to start making modules and found alot of great resources. I was wondering if there was some i might have missed from the below and whether the was somewhere I could see all the functions and variables available to me as a module dev.

i.e. What other messages can i send?

$this->message("my message");
$this->error("my error message");

etc...?

 

 

Link to comment
Share on other sites

Wire::message()
Wire::warning()
Wire::error()
 

    /**
     * Record an informational or “success” message in the system-wide notices.
     *
     * This method automatically identifies the message as coming from this class.
     *
     * ~~~~~
     * $this->message("This is the notice text");
     * $this->message("This notice is also logged", true);
     * $this->message("This notice is only shown in debug mode", Notice::debug);
     * $this->message("This notice allows <em>markup</em>", Notice::allowMarkup);
     * $this->message("Notice using multiple flags", Notice::debug | Notice::logOnly);
     * ~~~~~
     *
     * #pw-group-notices
     *
     * @param string|array|Wire $text Text to include in the notice
     * @param int|bool $flags Optional flags to alter default behavior:
     *  - `Notice::debug` (constant): Indicates notice should only be shown when debug mode is active.
     *  - `Notice::log` (constant): Indicates notice should also be logged.
     *  - `Notice::logOnly` (constant): Indicates notice should only be logged.
     *  - `Notice::allowMarkup` (constant): Indicates notice should allow the use of HTML markup tags.
     *  - `true` (boolean): Shortcut for the `Notice::log` constant.
     * @return $this
     * @see Wire::messages(), Wire::warning(), Wire::error()
     *
     */

have a look in Wire.php

  • Like 3
Link to comment
Share on other sites

1 hour ago, benbyf said:

i.e. What other messages can i send?


$this->message("my message");
$this->error("my error message");

etc...?

You have the whole API available to you for module development. The examples above are not specific to modules, but are methods of the Wire class.
https://processwire.com/api/ref/wire/message/
https://processwire.com/api/ref/wire/error/

My go-to pages for module-specific info are:
https://processwire.com/api/ref/module/
https://processwire.com/blog/posts/new-module-configuration-options/

  • Like 5
Link to comment
Share on other sites

Hi benbyf ,

 

Very interesting question but I'm not positive I'm following it 100%. This is my non-expert understanding of the topic : By definition a PW module is a PHP class. If you look at 'Module Example' in  http://processwire.com/api/modules/   which is also in your list of links, you'll see  "class Example extends WireData implements Module {". So A Module has immediate access to any variable or method in the parent WireData class. It also has to conform to the Module interface definition it is implementing. But as Robin S pointed out 'You have the whole API available to you', nor are you restricted to the API alone. I'm not trying to be cute or sarcastic here, but if you choose to, you can use whatever code is out there in your Module, be it on Packagist, Pear, GitHub or wherever. I'm not saying you necessarily want to, but you could.

 

Link to comment
Share on other sites

No worries, I'm a frontend guy by trade so mostly functional, not class / object based programming. Hence, modules in PW or coding langauges generally are a new and obscure thing for me.

Having said that, there must be "best practises" and easy ways of intereacting PW admin and site frontend etc using modules, I'm just trying to complie the resources for my own learning and to help others with future tutorials I'm hoping to write. The PW documentation is good, but when it comes to a beginners guide to modules it massively falls down :)

  • Like 1
Link to comment
Share on other sites

6 hours ago, benbyf said:

The PW documentation is good, but when it comes to a beginners guide to modules it massively falls down

You're not the first person to say this so there must be something to it, but that is not my experience. As a PW learner I haven't found working with modules to be a lot more difficult than working with any other aspect of PW / PHP and the docs seem pretty good to me. My experience has been that module development is challenging, but in a good way - you just get stuck in, debug issues as they arise, and ask for help in the forums when you get stuck. :)

6 hours ago, benbyf said:

I'm just trying to complie the resources for my own learning

This makes me wonder if you are holding back from actually starting on your module while you do 'research' - I'm not sure this is the best way to learn module development and my suggestion is just make a start and learn as you go. Like many things in PW, I think you'll find it's a lot simpler and easier than you anticipate when you're on the outside looking in.

Part of the problem with providing detailed documentation for something like module development is that the subject is so broad - a module can be created for any purpose and whoever is writing the docs can't know what you might want to do in your module. By analogy, it's like if you are learning to cook: you won't find much if you are searching for documentation on how to cook in general because the topic is too broad. Instead you have to decide what you want to cook and then look for help with that - how to make a chocolate cake or how to pluck a goose.

Maybe you can say a bit about what you want your module to do?

  • Like 7
Link to comment
Share on other sites

There are various small modules to start from, which include the few basics and everything else is really up to what's needed for your module. There's Helloworld.module in each installation as a plain module (with opt. external config here), ProcessHello as starting point for custom backend modules and FieldtypeEvents for Fieldtype/Inputfield development. If you have those the best followup docs are probably processwire itself. Almost everything beyond the core is a module. You want to have a table rendered in an admin page – Take a look at e.g. ProcessField or ProcessTemplate, which both use such a table. You'll soon notice MarkupAdminDataTable with is another module just for rendering these tables.

7 hours ago, Robin S said:

Part of the problem with providing detailed documentation for something like module development is that the subject is so broad

Basically everything with module infos and a way to tell it own classname is a module. It's described more detailed here: https://processwire.com/api/ref/module/. It can only get more detailed if one is asking for a module doing specific things, e.g. hooks, process modules, textformatters, error messages, table rendering and such.

  • Like 5
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

×
×
  • Create New...