Jump to content
benbyf

Available module functions and variables

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

 

 

Share this post


Link to post
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

Share this post


Link to post
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

Share this post


Link to post
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.

 

Share this post


Link to post
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

Share this post


Link to post
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

Share this post


Link to post
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

Share this post


Link to post
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

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By Lmwt
      Hi there,
      I am new to PW but already very convinced. I need to build a dropdown button to browse in a collection of authors by country and language. The dropdown should be editable in the BACK and displayed on the same as the authors collection. I tried my luck with "PageField Creator" but I don't know how to display the dropdown, I simply used: 
      "$content .=$page->Land;" (the name of the select field)
      but nothing is displayed...
      I see there is a 2nd module out there to achieve this : "Select Options Fieldtype". I am not sure what is the difference, anyone has a tip?
      And a clear tutorial with the necessary steps to build this? I am a bit confused which should be the parent template or page, if it should have a file or not...
      Thanks a lot in advance!
    • By Noel Boss
      👋 PW Pros…
      I have some hooks that I need to bind at the init phase (or even __construct) and I was wondering, and I couldn't find a good and simple way to determine if I'm in the admin. Would be nice if there is a reliable short option to do so, but I can't seem to find one… Is there a coherent way to tell this no matter where I am?
      Right now, I use the following method inside one of my modules:
      public function isAdmin($page = null) { if ( strpos($this->input->url, $this->urls->admin) !== false || $this->process instanceof ProcessPageList || $this->process instanceof ProcessPageEdit || ($page instanceof Page && $page->rootParent->id == $this->config->adminRootPageID) ) { return true; } return false; } @ryan wouldn't it be nice to have something like wire()->isAdmin(); like wire()->user->isLoggedin(); to tell if we are in admin – very early on (probably even in __construct() phase of modules?
    • By benbyf
      Hi!
      Been doing some basic Twilio implementation for a client to enable them to automatically send text messages to registered users on page publish. As an upshot, I thought I would strip out the site specific work and stick up on github here: https://github.com/benbyford/TwilioChannels
      This modules pulls in the Twilio APi and enables you to send SMS messages from your front or backend.
      Send SMS message Truncate message to single message character limit Auto-select number from range of numbers depending on $To number country of origin–this enables you to send messages with a local number to that user if one added to the config. Templates usage:
      $twilio = $modules->get("TwilioChannels"); $twilio->sendSMS($toNumber, $message);  
    • By J_Szwarga
      What is the best practice for having a form (only accessible to a logged in user) save the user's progress between sections of the form? Fieldsets? Multiple forms?
      Use case: I have a very long application form that would take 30 minutes for the applicant to fill out and I would hate for all progress to be lost due to user error. The progress needs to be logged into the user's page.
      Thanks!
×
×
  • Create New...