XF 2.1 $this->service('XF:Post\Editor', $post) return unexpected result

TheSkullKid

Active member
I tried to extend the XF\Pub\Controller\Post and XF\Service\Post\Editor, in the second extended class I add a function called checkContent, but when I run the code the content $editor is not the expected one:

PHP:
<?php

namespace TSK\newTest\XF\Pub\Controller;
use XF\Mvc\ParameterBag;

class Post extends XFCP_Post
{
    protected function setupPostEdit(\XF\Entity\Post $post)
    {
        $editor = parent::setupPostEdit($post);
        $editor->checkContent($this->filter('tsk_search', 'str'));
        return $editor;
    }
}

From the main / parent class this code line

PHP:
        $editor = $this->service('XF:Post\Editor', $post);

returns
1612691011600.png
and I got the following error message:
Error: Call to undefined method DBTech\Credits\XF\Service\Post\Editor::checkContent() in src\addons\TSK\newTest\XF\Pub\Controller\Post.php at line 11

Why do I get back this and not XF\Service\Post\Editor?
What kind of stuff will be used in a wrong format?
 
Why do I get back this and not XF\Service\Post\Editor?
That's normal because the DBTech\Credits add-on is extending the $editor service object. XenForo class proxy system loads all extensions and makes the extension chain transparently. That's why you see the extended object in the debugger.

then again,
XF\Service\Post\Editor
you said you're also trying to extend this post $editor service, right? I feel like that class extension is not working properly.

could you increase the execution order of your class extension?
And create a conditional breakpoint on src/XF/Extension.php line 109
($class = ltrim($class, '\\');)
the condition has to be: $class == "TSK\newTest\XF\Service\Post\Editor"

Then refresh the page and see if it's hitting the breakpoint.
If it's not hitting, it means your class extension isn't working. you should check if the extension is working correctly.
 
could you increase the execution order of your class extension?
And create a conditional breakpoint on src/XF/Extension.php line 109
($class = ltrim($class, '\\');)
the condition has to be: $class == "TSK\newTest\XF\Service\Post\Editor"
This was a great tip & hint, what kind of ******** happened on my system, one of the class extension I created has been deleted. Could not believe it.

Thx a lot.
 
Top Bottom