XF 2.0 Improper User Entity Extensions

Snog

Well-known member
I've been getting a lot of reports from people claiming there is a problem with my add-ons when it's not my add-ons causing the problem. I believe it is all from improper user entity extensions and I want to be sure my extensions are correct.

Code:
namespace Snog\MyAddon\XF\Entity;

use XF\Mvc\Entity\Entity;
use XF\Mvc\Entity\Structure;

class User extends XFCP_User
{
   public static function getStructure(Structure $structure)
   {
      $structure = parent::getStructure($structure);

      $structure->columns['my_column'] = ['type' => Entity::STR, 'default' => ''];

      $structure->defaultWith[] = 'Privacy';

      return $structure;
   }
}

Somehow the errors produced will be something like this...
Code:
ErrorException: Template error: Method aDifferentAddonFunction is not callable on the given object (Snog\MyAddon\XF\Entity\User) src/XF/Template/Templater.php:935
....
#2 internal_data/code_cache/navigation_cache.php(491): XF\Template\Templater->method(Object(Snog\MyAddon\XF\Entity\User), 'aDifferentAddonFunction', Array)
....

It's really frustrating because I'm 99.999% certain my add-on extends the entity properly, yet my add-on is mentioned in the errors.
 
Last edited:
Generally the class you see in a stack trace might not be the class that is causing the problem.

Because of the XF class proxy system you’ll generally just see the extension class of the last extension.

It does make debugging faulty extensions difficult but as far as I can tell from your example above, as long as that extension is working on its own, it doesn’t appear to be written in a way that would cause issues to other add-ons.

Based on the error, if I had to hazard a guess, then it could be that the add-on which is calling that method is disabled, but the navigation cache file is still calling it for some reason.
 
Thanks Chris.

The error varies, but your explanation is exactly what I suspected and what I've been telling people. But, to the non-coder it's seems to be something that's hard to understand. ;)

It's also hard for people to understand that installing my add-on simply revealed a problem with a different add-on and isn't the cause of the problem. :(
 
Last edited:
It is because you are (likely) using the default 10 priority and later installed add-ons get added to the back of the list and thus more likely to be seen as the 'first' class.

Lower priority means it will be lower on the built proxy class hierarchy. I tend to make my add-ons have their XFRM id as their priority so I get dependable ordering (since I have a lot of add-ons installed).
 
It is because you are (likely) using the default 10 priority and later installed add-ons get added to the back of the list and thus more likely to be seen as the 'first' class.

Lower priority means it will be lower on the built proxy class hierarchy. I tend to make my add-ons have their XFRM id as their priority so I get dependable ordering (since I have a lot of add-ons installed).
I understand what you're saying, but the explanation from Chris was quite sufficient for the case I was bringing forth.
 
Back
Top Bottom