Articles

Tribe Support

Tribe Support's Articles

Nick Swinford

Nick Swinford

March 21 2016

Extending Person Entity

So I'm trying to extend the person entity and based on Rastin's suggestion, it'd be best to do this by injecting a behavior. I've created the following plugin to inject a behavior:

Loading ...
#file-ranks-php

And then created the following behavior:

Loading ...
#file-rankable-php

I've tested that the behavior does get injected into the entity correctly, but after I added the resource and attribute, I get an error "Property seniorMember is mapped to an invalid column for entity com://site/people.domain.entity.person".

The only thing that I can think that's causing this is that the behavior isn't getting injected before the repository is instantiated, but idk. Any ideas would be appreciated.

Rastin Mehr
Rastin Mehr
March 21 2016 Permalink
In what component and view do you get that error?
Rastin Mehr
Rastin Mehr
March 21 2016 Permalink
Also a new flag is added to the actors called verified. You can use that to identify senior members.
I get it on every page cause it's all happening right after initialization.

Senior members is just the start. Eventually, I'll be add more ranks. I like the verified feature. I'll be using the for groups, for sure.
Rastin Mehr
Rastin Mehr
March 21 2016 Permalink
An alternative approach would be overriding the person entity entirely and just add the new field to it. Mixins can be tricky sometimes. I'm not sure what's causing this.
What do you mean by override? Do you mean by mapping it to another class like below?

KFactory::map('site::com.actor.template.helper','plg.system.example.actorhelper');
Rastin Mehr
Rastin Mehr
March 21 2016 Permalink
yes, that way Anahita will pick your actor entity class instead of her own.
Should I override the actor or person entity? I'd rather not add fields to groups, as well.
Rastin Mehr
Rastin Mehr
March 22 2016 Permalink
person entity
Rastin Mehr
Rastin Mehr
March 22 2016 Permalink
We can focus on fixing this issues in 4.3 and 4.4. There is no reason that your approach shouldn't work, except we never had the chance to try out all these scenarios yet. Thanks to you, we can do that now. Maybe you can look into it further and see what's causing it.
I just realized I created this accidentally as an article and not a topic! I thought it was weird it had an excerpt! Sorry about that.
Rastin Mehr
Rastin Mehr
March 23 2016 Permalink
It's ok, I sometimes wonder what would happen if we could combine notes,articles, and topics as one app. Different topic for later, but worth the time.
Okay, I'm trying to override the person entity and it's not working.

Loading ...


Currently, in the person.php file I've just copied the person entity and simply changed the class name to PlgSystemRanksPerson. It looks like Anahita is finding the file and including it, but then I get the following error:

PHP Fatal error: Uncaught Exception 'KServiceException' with message 'Cannot instantiate object from identifier : plg://site/system.domain.repository.person'

Why it's overriding the repository, as well, I have no idea. Any thoughts?
Rastin Mehr
Rastin Mehr
March 24 2016 Permalink
try swapping the parameters. I think they are in the wrong order.
Nope, that's the right order.
That doesn't make sense. I put error_log('this is from plugin') in the initialize function from my overridden and error_log('this is from com_people') in the initialize function in the actual person entity.

If I put alias first, then identifier, I get 'this is from com_people in the error log. If I reverse it, and put identifier first, then alias, I get 'this is from plugin' in the error log, and the error.

Plus, I'm currently using this (https://github.com/NicholasJohn16/plg-username/blob/master/src/plugins/system/username.php) on a test site (http://beta.stonewallgaming.net/) and it does work.
Rastin Mehr
Rastin Mehr
March 24 2016 Permalink
I need to play with the code myself. It is important for us to be able to override classes
Rastin Mehr
Rastin Mehr
April 03 2016 Permalink
I need to convert this node to a topic in one of our migrations
I've been working on this a bit more over the last couple days and I think I've come to a realization. You can't add resources with behaviors. After looking over behavoirs (https://github.com/anahitasocial/anahita/blob/master/src/libraries/anahita/domain/behavior/abstract.php) there's no place that handles the resources attribute on the config option. I'm not sure if this is intentional or accidental.

Relationships are processed though so I'll be looking into using that to add additional fields onto the person entity.
Rastin Mehr liked this
Rastin Mehr
Rastin Mehr
March 13 2017 Permalink
It would've been nice if we could. I don't think the current code was intentional. It was simply the code written at the time and it can always be improved.

Additional Information

Powered by Anahita