Fixed Avatar forcetype throws error

Snog

Well-known member
Affected version
2.0 Beta 6
I was hoping to trick xf:avatar into allowing an array instead of an entity when I ran across this error:
Code:
Fatal error:  Method XF\Widget\WidgetRenderer::__toString() must not throw an exception, caught Error: Call to a member function getAvatarUrl() on array in /var/www/clients/client0/web1/web/src/XF/Template/Templater.php on line 0
I was using this template code:
Code:
<xf:avatar user="$user" size="xs" forcetype="custom" />
 
If $user is an array (or some other falsey value), rather than a User entity then this will happen.

So it's not supposed to work. That said, we should probably be making that more clear or bailing out sooner with a nicer message (or just falling back to the default avatar regardless).
 
Yeah, that was kind of my point. I really didn't expect the array to work (although it would be nice). But I didn't expect the error either.
 
Fixed now. I think the $forceType switch in use when $user is not an entity is a leftover from some previous assumptions.
 
Back
Top Bottom