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

Discussion in 'XenForo Development Discussions' started by CrispinP, May 8, 2016.

  1. CrispinP

    CrispinP Well-Known Member

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

    James Well-Known Member

    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 likes this.
  3. CrispinP

    CrispinP Well-Known Member

    thanks for the nudge - I will dig a bit more that that.
  4. wang

    wang Well-Known Member

    @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 likes this.
  5. CrispinP

    CrispinP Well-Known Member

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

    Lawrence Well-Known Member

    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:

    class YourAddOnsDirectory_YourSpecificAddon_Listener_LoadClassController
        public static function loadClassListener($class, &$extend)
            switch ($class)
                case 'XenForo_ControllerPublic_Thread':
                    $extend[] = 'YourAddOnsDirectory_YourSpecificAddon_ControllerPublic_Thread';
                case 'XenForo_ControllerAdmin_Tools':
                    XenForo_CacheRebuilder_Abstract::$builders['yourAddonCache'] = 'YourAddOnsDirectory_YourSpecificAddon_CacheRebuilder_yourMethod';
    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:

    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 likes this.
  7. CrispinP

    CrispinP Well-Known Member

    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 :)

Share This Page