Jump to content

IC5: Introduction to Listeners

I'm very excited to be posting my first blog entry for IPS, and thrilled that this is what I get to post.

When we started planning the new development tools for v5, we looked at existing resources - from the marketplace, from some contributors, and from our own managed clients - and asked, what is it that developers find themselves doing the most often? Matt’s previous blog entry gave a brief summary of some of those functions. Today’s blog entry is going to focus on one of our powerful new tools, Listeners.

One common reason for a code hook was to execute custom code when a specific action occurs. For example, when a topic is created, or when a new reply is posted. Listeners allow you to execute your code at key points in the workflow, without the worry of finding exactly the right hook location.

Here is an excerpt from the BlogComment listener in our Cloud application:

Could contain: Electronics, Screen, Computer Hardware, Hardware, Monitor, Computer, Pc, Page, TV, Business Card

 

Creating Listeners

Let’s start with the application’s Developer Center.

Could contain: Page, Text

We’ve added a new tab for Listeners. This tab lists all your existing listeners, as well as the class on which it is listening.

You’ll notice that each listener can only observe a single class. While this may seem slightly tedious, the idea here was that as a developer, you should be conscious of what class you are working with. It also eliminates the need to check what type of object is being passed preventing accidents and unintended consequences when missing class checks.

When you add a listener, there are several listener types available. We will discuss each one in detail.

Could contain: Page, Text, Computer, Electronics, Pc, White Board

 

Content Listener

This listener is fired on an Item or Comment (or Review) class. When adding a Content Listener, you must specify the class you are observing. When you hit Save, there is a validation check in place to ensure that the class exists, and that it is a valid class for the selected listener type.

Content Listeners have the following methods available. All methods are included in the default listener file that is generated.

  • onLoad
    Triggered when an object is loaded (in Content::constructFromData)

NOTE: Be careful! This event could be fired at unexpected times. If you’re executing code here, you may want to check the dispatcher instance to verify that your code is running where you expect.

  • onBeforeCreateOrEdit
    Fired when a form is submitted, before it is saved. This is the equivalent of Item::processBeforeCreate and Item::processBeforeEdit. This method includes a parameter to indicate whether this is a create or edit.
  • onCreateOrEdit
    Fired after a form is saved. This is the equivalent of Item::processAfterCreate and Item::processAfterEdit. This method includes a parameter to indicate whether this is a create or edit.
  • onDelete
    Fired after an object is deleted.
  • onStatusChange
    Fired when any moderation action occurs. For example, when an item is pinned/unpinned, locked/unlocked. The moderation action is passed as a parameter so that your code can take that into account.
  • onMerge
    Triggered AFTER an item is merged.
  • onItemView
    Triggered when an item is viewed and the view count is incremented.

 

Invoice Listener

An Invoice listener is fired only on the \IPS\nexus\Invoice class. This listener does not require you to specify a class to extend.

The Invoice listener includes a single method, onStatusChange. This is fired when the invoice is saved and the status changes (pending/paid/expired/canceled).

 

Member Listener

The Member listener will be familiar to many of you. We have taken the MemberSync extension and moved it in its entirety to a listener, as it was a better fit for this structure. All the previous methods that were available are still available here. We have also added the following new methods:

  • onJoinClub
    Fired when a member joins a club. If approval is required, this is fired after they are approved.
  • onLeaveClub
    Fired when a member leaves or is removed from a club.
  • onEventRsvp
    Fired when a member responds to an event. The response is included as a parameter to this method.

 

Commerce Package Listener

The Commerce Package listener is fired on any implementation of \IPS\nexus\Invoice\Item. You must specify the class that you are observing.

The methods are the same as those that are available in an item extension.

  • onCancel
  • onChange
  • onDelete
  • onExpireWarning
  • onExpire
  • onInvoiceCancel
  • onPaid
  • onPurchaseGenerated
  • onReactivate
  • onRenew
  • onTransfer
  • onUnpaid

 

Some Technical Notes

  • All listener files will be generated in a “listeners” directory within your application.
  • Your application’s data directory will include a listeners.json file that defines all your listeners. The json file is automatically generated when you add/remove a listener.
  • All listener methods are optional. The default class that is generated will include all available methods, but they do not have to be present in your file.
  • All listener methods are return type void.
  • If a listener method fails, an exception will be thrown when IN_DEV is enabled. In production, the exception will be logged with a reference to the listener class and the event on which the exception occurred.

 

Firing Events

Your code can fire any existing event using the Event::fire method.

Example:

Event::fire( 'onBeforeCreateOrEdit', $comment, array( $values ) );

The Event::fire method is called statically and accepts an event name, the object on which the event will be fired, and an array of additional parameters (varies according to the event that you are triggering).

This concludes our introduction to Listeners. We do intend to implement additional listener types and events based on your feedback and as the need arises.

Comments

Recommended Comments



CheersnGears

Posted

3 hours ago, Matt said:

The third party developers are very important to us, but most customers choose to not use add-ons or modifications. Based on statistics we collect, the most popular plug-in on the marketplace has less than 250 current installations, and the most popular application has less than 600 installations.

Is that a cause or effect?

 The number of offerings in the marketplace has dwindled significantly during V4's lifetime.

SeNioR-

Posted

4 minutes ago, CheersnGears said:

The third party developers are very important to us, but most customers choose to not use add-ons or modifications. Based on statistics we collect, the most popular plug-in on the marketplace has less than 250 current installations, and the most popular application has less than 600 installations.

Not every person has applications/plugins associated with the Marketplace. Many people downloaded the resource in xml/tar format and just installed it.

There are definitely more installations. IMHO.

  • Management
Matt

Posted

I agree. It wasn’t to suggest mods aren’t popular just that statistically more people choose to run “vanilla” installations. 
 

There has been a shift downwards in new applications for sure. I think that is just a byproduct of the forum market maturing and changing. 

Adriano Faria

Posted

15 minutes ago, Matt said:

There has been a shift downwards in new applications for sure. I think that is just a byproduct of the forum market maturing and changing. 

Probably... and due to that, the devs get tired of releasing new stuff and it gets a couple of purchases. There is certainly more to it than that.

marklcfc

Posted

10 hours ago, Matt said:

I agree. It wasn’t to suggest mods aren’t popular just that statistically more people choose to run “vanilla” installations. 
 

There has been a shift downwards in new applications for sure. I think that is just a byproduct of the forum market maturing and changing. 

4/6 of mine I paid someone on here to make, as they were specific requests. My forum wouldn’t be all what it is without a few of them at least as it adds something different

Daniel F

Posted

The capability to change how most stuff in IPS works and enhance it with own features/apps isn't going away.

What changed is how things have to be done. Some changes will be much easier, others will be probably annoying as hell for people who are used to how the hooks worked in v4, some will think that it is a huge step backward, but as Matt said, it had to be done, to provide a much more stable and faster-improving code base for v5, because we'll be able to alter or even deprecate methods, method parameters and even deprecate complete (internal) classes much faster, which also 3rd parties and clients will benefit from.

With v5 I'm really expecting fewer "A new community release with some huge under-the-hood BC breaking changes is here, all my apps are now broken and need to be updated ASAP" scenarios.

 

Code listeners are a quite common pattern used in modern applications, most php framework use this approach today. It's the perfect balance between none capability to change the core behavior via 3rd party code and the too-powerful proxy autoloader which we had in 4.x, which as powerful as it was, had also way too many problems.

I've read about concerns about missing event locations which were common in v3 and that it took ages to have new hooks implemented => Keep in mind that we have now a monthly release cycle, so I'm quite sure it's not going to take now that long to ship improvements as long as they make sense and fit into the general vision of the product.

RevengeFNF

Posted (edited)

14 hours ago, Matt said:

I’m unsure what the question is there. 🙂 

I was just curious to know if most people just use the base IPS with the official apps and don't care about using third party apps/plugins.

1 hour ago, Daniel F said:

With v5 I'm really expecting fewer "A new community release with some huge under-the-hook BC breaking changes is here, all my apps are now broken and need to be updated ASAP" scenarios.

That is indeed an advantage. And third party developers will also save some trouble because there is less risk of new IPS version breaking their apps.

If it's something that needed to be done, i guess we will all survive like it happened in the past with other major changes.

Edited by RevengeFNF
  • Management
Matt

Posted

I'm not really sure what is driving customer habits beyond what we're seeing as trends in the industry. The community market has become more professional and hobbyist communities which used to keep the marketplace alive by spending $5 to $50 on something they felt they needed for their members are being consumed by social media or other hosted apps like Discord.

My hope is that after market developers focus on few projects but more impactful ones. Wordpress has WooCommerce and Yoast which are incredibly popular and generate a lot of revenue.

Proxy classes/code-hooks just couldn't continue. Our code base was years overdue a clean up but it would have caused massive support overhead and massive after market development headaches were most of the marketplace needed updating.

2 hours ago, marklcfc said:

4/6 of mine I paid someone on here to make, as they were specific requests. My forum wouldn’t be all what it is without a few of them at least as it adds something different

What modifications do you have?

DawPi

Posted

6 minutes ago, Matt said:

Our code base was years overdue a clean up but it would have caused massive support overhead and massive after market development headaches were most of the marketplace needed updating.

Sooo maybeeee you could add BIG RED TRIGGER to enable hooks with all the risk and consequences ceded to the owner of the forum?

It would be an excellent compromise.

marklcfc

Posted

5 minutes ago, Matt said:

What modifications do you have?

This is the main one https://www.foxestalk.co.uk/matchratings/season/5-202223/ which I've used for 5 years.
A ratings application, where a poll is posted after each match to rate players 1-10. Results are calculated and displayed per match and overall season ratings too.

I also have an adblock checker which is more to my suiting, not the ones offered in the marketplace here and online indictator which I had rewrote from an old hook that no longer worked.

  • Management
Matt

Posted

Great modification, and that will still be possible in v5.

marklcfc

Posted

and I assume {insert="stats/browse.php"} will still work in content pages, which I use for the History section to pull in self written files and database (the main reason why I can't use the cloud hosting as I'd lose this). I'd rather that be an App too but no point getting that ready for this version of the forum now.

annadaa

Posted

can you translate a bit for non-developers?

because if I understand the plugins will no longer be available as is but the applications yes

do all applications in v. 4 can be updated to v. 5?

some plugins no and others yes by becoming applications if I understand? but no real answer yet because it is under development

if I understand the advantage of this update is an ease of compatibility of applications with future updates, even large ones and months of interference between IPS and certain plugins which brought certain malfunctions


why do you underestimate the value of the market? while you do not know the future of IPS, what will be its future potential customers?

nor the number of customers developing in-house third-party applications

also see your direct competitor how being the word press community using bbPress, woo commerce, learn dash (LMS) and others, and not just professionals

you can greatly outperform them if you don't underestimate the market here

your admin panel is better and incomparable, you can manage members and groups better here, there are a lot of bugs here and third party application problems due to updates and it will be even better in the future as I understand

it is possible to do much better here and cleaner than the equivalent of the applications available at word press

the applications here are much better in options than their wordpress equivalent

you want to create an LMS then at least leave the possibility to the developers to improve it and make it better than learn dash from word press

Adriano Faria

Posted

44 minutes ago, annadaa said:

because if I understand the plugins will no longer be available as is but the applications yes

I’ll try.

Plugins don’t. Applications will. Everything you could do with a plugin, you always could with an application because both used hooks; it was powerful and you could do basically everything. Hooks are removed in V5. It won’t be possible anymore and it’s been replaced by a hook-points system (a.k.a. Listeners) and a UIExtension, which we don’t know as they didn’t blog about it yet. It will be more limited/restricted, no doubt.  Matt said, you can do a lot, but you can’t do everything you could before. The doubt now is how much limited it is compared to hooks.

Translating to marketplace resources: my guess is that a few (compared to the totality) applications/plugins will be fully upgraded to V5. Some will be upgraded but will lost some functionalities (due to hooks it may have today) but vast majority don’t, at least in first moment; improvements will be necessary along the way.

I guess we’ll have to wait and see. Get your popcorn and have a seat. Only time will tell.

47 minutes ago, annadaa said:

you want to create an LMS then at least leave the possibility to the developers to improve it and make it better than learn dash from word press

Marketplace rules will change for V5. 3rd-party devs probably will be allowed to create similar resources. 

SeNioR-

Posted

@annadaa I recommend to follow: Deprecation Tracker.

Quote

We are removing support for plugins and instead you should use the applications system. Applications are more flexible than plugins and easier to manage.

Any existing plugins can easily be ported to applications and we encourage third-parties to start the process as soon as possible.

Adriano Faria

Posted

Just now, SeNioR- said:

v5? WTF 😄 

Could contain: File, Webpage, Page, Text

Wow. This definitely a guy ahead of his time. 

annadaa

Posted

I really don't know what to say except I hope that all these modifications are full of good intentions towards customers and developers as well, which allow many of us to stay in this community rather than seeing other similar products.

I think that you can't have everything without anything, and that you have to have to give up accepting many things, even difficult for a better future product.

for the developers it will surely be a lot of work to update but I hope that afterwards there will be less work to update their applications for future versions which will then give them more time to improve them

I can understand that you close your system as much as possible in order to have a bug-free product, but I hope that you do it for the purpose of improvement and not of exclusivity

there are plenty of paid products better than yours but limited and sold by number of users. and your very strong point of the cloud it must be said is that you do not limit the number of users and views etc.

the developers can help us to have products similar to others for a very competitive price and where the cloud could then be interesting to be taken if we can have what we need without limit.

do what you have to do but be careful that the choices are not only about money because I don't think that makes a community, social product successful... we could see it a little with twitter.. .

annadaa

Posted

On 7/29/2023 at 12:23 PM, Adriano Faria said:

Marketplace rules will change for V5. 3rd-party devs probably will be allowed to create similar resources. 

 

I do hope that will change. that developers can create an application that improves upon what may already exist, or a better equivalent.

and this is to everyone's advantage, customers and IPS alike.

I don't think that IPS has refrained until today from creating similar applications that may or already exist in the marketplace.

moreover, IPS is satisfied with the bare minimum in its applications, surely for lack of time, but which then does not make you really want to be used and rather to go and see (blog, sales page, LMS, ...), despite the fact that we can count on a certain stability of the products it must be said.

there really is no advantage to living in an environment closed to everything, without "competition" moreover where it is the customers who are the first to suffer, see even IPS

the marketplace can only be an advantage in the sense that it serves to improve the product and things where the IPS team does not have time to focus on it.

as we were able to receive the number of installations of a popular application, I would like to know the number of customers who have decided to switch to the cloud in order to be able to use races, or improved gallery, video encoding...

otherwise, I don't question the cloud, but when my project is running, when it brings me income, of course I prefer to go to the cloud. especially since I believe that there may no longer be any bugs with third-party applications when updates are made and this is a great inconvenience of the cloud, I hope it deletes.

and certainly from a certain number of users it is certainly more profitable to go to the cloud, and this allows IPS to continue to live, which is also an advantage for customers.

Randy Calvert

Posted

7 hours ago, annadaa said:

I don't think that IPS has refrained until today from creating similar applications that may or already exist in the marketplace.

That policy has existed a LOOOOOONG time.  In fact, it looks to have been in the very first marketplace guidelines released back in 2020.  The Wayback Machine has it in the cache on August 6th and the first blog talking about Marketplace coming soon was on June 12, 2020.   

https://invisioncommunity.com/developers/submission-guidelines/

 

AlexJ

Posted (edited)

On 7/27/2023 at 11:54 AM, Matt said:

Based on statistics we collect,

Again this bogus statistics gameplay. Jeez .....u had used same logic for removing support desk/ticket which everyone said, it's working fine. 

Anything that you want to remove, use the stats card. Without plugins, I wouldn't use IPS because IPS Nexus/Commerce can't even do basic donation tracking which every community needs. 

We love IPS and many are here since V2,V3 or even before versions... but with V5, it feels you want to go pro-cloud, make it standard for all and remove features which you think are not required without having 2nd thought for what your customer needs. 

Why you need to push us to XF man..... I am not touching vB for sure.. so only choice XF for me. 

Edited by AlexJ
  • Management
Matt

Posted

9 minutes ago, AlexJ said:

I wouldn't use IPS because IPS Nexus/Commerce can't even do basic donation tracking

Already in v5.

9 minutes ago, AlexJ said:

Why you need to push us to XF man..... I am not touching vB for sure.. so only choice XF for me. 

I think the sensible thing to do is wait for all the news of v5 to come out and then make an informed decision on your future. Trying to extrapolate v5 from a few dev blogs may lead to rash decisions.

I'd love to keep you as a customer, but if you do wish to move to xF then on the plus side you won't need to worry about new versions and there being significant changes in your future. 😄



×
×
  • Create New...