Different Attachment File Types Metadata

Rasmus Vind

Well-known member
I am looking into extending the attachment system with more file types. My site has to do with lots of obscure formats. I would like to add thumbnails for those filetypes. This is something I am already able to do, but where do I put it in xenForo? I would rather not edit the original files, nor overwrite original methods with huge chunks of the existing code. Can't I attach something to the end of a function?
I have been looking into code event listeners which allows me to overwrite methods of instantiated objects. I am not so happy with that as I want the existing functionality to stay, but add more to it. I could copy paste the existing code into my own event listener, but that's ugly. I guess I could make a transparent class that overloads __get() and __call() but has an instance variable being the object passed to me. Then the transparent class can have a method I make. After calling it, it could call the original method.
Any better ideas?
 
Code Event Listeners do not overwrite existing methods.

You can overwrite, or you can extend them.

After setting up your event listener to listen to the appropriate events, you specify which class you want to extend, and your new class will declare an existing method.

If you start that method with:

$parent = parent::existingMethodName();

And end it with:

return $parent;

Anything in between can be your own code. It means the existing method still executes. Therefore you are extending, rather than overwriting.

That being said, if for whatever reason you cannot extend, it might not be a major problem. Overwriting existing methods is only bad news if you're releasing it publicly which may cause clashes with people's existing add-ons or if you plan to install existing add-ons that may be attempting to overwrite or extend those same methods. It may also need to be reviewed when there is a core XenForo update... but in most cases, extending it as I described above will work and should be pretty worry free for the future.
 
Oh, that's brilliant. I guess I should have known from the explanation in the code event listener editor page. Thanks none the less for the good explanation. It makes a lot of sense. I am starting to understand how truly powerful this is.
 
Back
Top Bottom