• This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.

Event listener hints - how do I know what is what?

CrispinP

Well-known member
#1
Hi folks,

I'm writing my first add-on for XF and have run into a dead end.

How do I know what event hints are available and which I should look for?
I've read a number of long threads (lawrence's one is very detailed) but fail to see anything on how to know which hint to listen to. If I don't then I get redeclaration errors.

I want to intercept a resource post so I can inspect the file they have added and then do stuff with it (not alter it)

Many thanks
Crispin
 

James

Well-known member
#2
Am I not right in saying that your event hint should be on the class you're extending? Been a long time since I looked into them.
 

wang

Well-known member
#4
@James is correct. Let us say that you are extanding the thread controller, the listener hint in this case is: XenForo_ControllerPublic_Thread. And so on for the rest.
 

CrispinP

Well-known member
#5
Thanks for that -

I (think) I found what I am after - XenResource_DataWriter_Update I did though find this by trawling all the plugins until I found something that looked similar and checked the code.

How though would I have found this another way? Is it documented anywhere or just a case of looking at what is available and trying?
 

Lawrence

Well-known member
#6
Hi folks,
How do I know what event hints are available and which I should look for?
I've read a number of long threads (lawrence's one is very detailed) but fail to see anything on how to know which hint to listen to. If I don't then I get redeclaration errors.
Crispin
Hi Crispin, when I wrote the tutorial event hints were not part of listeners at the time. What we had to do is use an if statement or better a switch statement to test what class was being called, and then append an appropriate class to the referenced extend array, like so:

Code:
class YourAddOnsDirectory_YourSpecificAddon_Listener_LoadClassController
{
    public static function loadClassListener($class, &$extend)
    {
        switch ($class)
        {
            case 'XenForo_ControllerPublic_Thread':
                $extend[] = 'YourAddOnsDirectory_YourSpecificAddon_ControllerPublic_Thread';
            break;
            case 'XenForo_ControllerAdmin_Tools':
                XenForo_CacheRebuilder_Abstract::$builders['yourAddonCache'] = 'YourAddOnsDirectory_YourSpecificAddon_CacheRebuilder_yourMethod';
            break;
        }
    }
}
With hints now you can be more specific on when your class should be executed, so the hint, if applicable would be what you are looking for in $class:
XenForo_ControllerPublic_Thread

Note that listeners that do have a hint, and no hint is put in the field, those listeners will be executed before those that have provided a hint.
 

CrispinP

Well-known member
#7
Thanks @Lawrence . I gathered that the hint thing was added after the tutorial was written. I'll have a root around this evening when the pay-your-bills work is finished.

It's all a fun learning game :)