Abstract avatar framework

digitalpoint

Well-known member
The code for users to upload/delete/crop avatars is pretty good and really isn't too hard to make work with other content types. It would be super nice if it worked with any content type by default though. You wouldn't even really need to build a handler system, instead you could have entities implement something like an AvatarInterface.

The most problematic part of making avatars/icons (while using the existing avatar functions) for different content types currently is that Templater::fnAvatar() has this:

PHP:
if ($user instanceof User)

What would be way sexier is something along the lines of:

PHP:
if ($entity instanceof AvatarInterface)

Even XenForo could use it themselves and use it for Resource Manager Icons (can't currently crop or generate multiple sizes, so it would be a nice upgrade even not counting what I would use it for).
 
Upvote 6
Probably makes sense to show how it can be used as an example.

Le't say I had a different content type (in this case, studio businesses). Using the avatar template tag on that content entity, and it will generate the random color default icons with the single letter (same function avatars do).

1723240995536.webp

Changing the logo uses the default avatar JavaScript (thankfully none of that needs to be changed) that lets you do things like crop, and also generates various sizes when they are uploaded.

1723240929227.webp

It's not the first time I've used the avatar framework for other things. My Marketplace addon uses it for the icons of products as well (which is a lot better than how the Resource Manager does it imo).

 
Agreed on this suggestion 100%. I was actually just wondering if this was extendable to use for my blog's addons header images so I could force a certain size on them.
 
Back
Top Bottom