XF 2.0 Call methods of extended entity

CMTV

Well-known member
I extended Thread entity and added custom method canSolve().

Then I extended Thread controller with actionSolve(ParameterBug $pb) method:
PHP:
public function actionSolve(ParameterBag $pb)
{
    $thread = $this->assertViewableThread($pb->thread_id);

    /* There is no such a method in XF\Entity\Thread class! */
    $thread->canSolve();
}
How can I call my custom canSolve() method?

I guess I need to somehow cast XF\Entity\Thread object to MyPluginID\XF\Entity\Thread in order to use my method.
Do I need to use getRelationOrDefault(...) here?
 
Have you extended the entity correctly? You should’ve defined the extension in the admin panel.

Liam
 
Have you extended the entity correctly? You should’ve defined the extension in the admin panel.

Liam
My bad.
$thread->canSolve(); is working fine! Rule number one - never trust PhpStorm warnings when working with xF :)
 
My bad.
$thread->canSolve(); is working fine! Rule number one - never trust PhpStorm warnings when working with xF :)

Yeah, obviously the return type is still the original unextended class :)

You can stick your own hint in there though.

Liam
 
Yeah, obviously the return type is still the original unextended class :)

You can stick your own hint in there though.

Liam
If it returning unextended class why can I call my custom method? Magic methods?
 
Top Bottom