XF 2.0 Any reason $this->getStyle() would ever be NULL in \XF\Template\Templater?

Jake B.

Well-known member
I'm extending \XF\Template\Templater and have extended the function getDefaultAvatarStyling, and I have a style property for UI.X to use the material color palette instead of generating the random color like XenForo does by default, and for some reason on a couple of installs people are getting an error saying that $this->getStyle() is NULL coming from this chunk:

PHP:
if (!$options->th_materialAvatars_uix && !$this->getStyle()->getProperty('uix_materialAvatars')) {
    return parent::getDefaultAvatarStyling($username);
}

Is there any reason $this->getStyle() would ever be null in a default XenForo install, or is this something that an add-on (ours or otherwise) would be causing somewhere?
 
Well, the default value of the style class property in the templater is null. As far as I can see in all relevant contexts within XF, we always set it, but you can't always rely on it being set.

There's a few contexts where the Templater runs, including CSS, Mail, Public, Admin, Install app (that's actually one context where we don't set it because there's no concept of styles there).

The way to track it down, potentially, is to check whether it is null or not, and bail out from whatever you're doing if it is null. If you suddenly start getting reports of your code not working in certain places then that should make it easier to track down.
 
If you suddenly start getting reports of your code not working in certain places then that should make it easier to track down.

That's the interesting part, it's happening in places I'd fully expect it to work, such as on a thread's page and it's not something that has been reported by many people, just odd one-off reports. I've added a fallback anyways, just in case, but I'm still not sure why it was null in the first place
 
Last edited:
Top Bottom