XF 2.2 Using the report handler

Lee

Well-known member
I have implemented the report handler for a custom content type.

I have created the content type in the ACP like this:
1641391743889.png

I had a look at how XF handles post reporting and came up with this in my TLS/Thoughts/Report/Thought.php:
PHP:
<?php

namespace TLS\Thoughts\Report;

use XF\Entity\Report;
use XF\Mvc\Entity\Entity;
use XF\Report\AbstractHandler;

class Thought extends AbstractHandler
{

    protected function canViewContent(Report $report)
    {
        return true;
    }

    protected function canActionContent(Report $report)
    {
        return true;
    }


    public function setupReportEntityContent(Report $report, Entity $content)
    {

        $report->content_user_id = $content->user_id;
        $report->content_info = [
            'message' => $content->thought,
            'node_id' => $content->thought_id,
            //'node_name' => $content->Thread->Forum->Node->node_name,
            //'node_title' => $content->Thread->Forum->Node->title,
            'post_id' => $content->thought_id,
            'thread_id' => $content->thought_id,
            //'thread_title' => $threadTitle,
            'user_id' => $content->user_id,
            'username' => $content->username
        ];
    }

    public function getContentTitle(Report $report)
    {
        return \XF::phrase('post_in_thread_x', [
            'title' => \XF::app()->stringFormatter()->censorText($report->content_info['message'])
        ]);
    }

    public function getContentMessage(Report $report)
    {
        return $report->content_info['message'];
    }

    public function getContentLink(Report $report)
    {
        if (!empty($report->content_info['thought_id']))
        {
            $linkData = $report->content_info;
        }
        else
        {
            $linkData = ['thought_id' => $report->content_id];
        }

        return \XF::app()->router('public')->buildLink('thoughts', $linkData);
    }

    //public function getEntityWith()
    //{
    //    return ['Thread', 'Thread.Forum', 'User'];
    //}
}

and my controller:

PHP:
    public function actionReport(ParameterBag $params)
    {
        $thought = $this->assertRecordExists('TLS\Thoughts:Thought', $params->thought_id);
   
        /** @var \XF\ControllerPlugin\Report $reportPlugin */
        $reportPlugin = $this->plugin('XF:Report');
        return $reportPlugin->actionReport(
            'tls_thoughts_thought', $thought,
            $this->buildLink('thoughts/report', $thought),
            $this->buildLink('thought', $thought)
        );
    }


My report is inserting in to the database correctly, but if I try and view it I get the following:

1641392128718.png

What am I doing wrong? Is it something stupid? :ROFLMAO:

Thanks in advance.
 
Not something stupid. but a fairly simple to fix mistake which is a bonus.

The entity content type should be the entity "short name" not an actual class name. So it should be set to TLS\Thoughts:Thought in your case. In that format, it can be used for repositories, finders, creating/finding entities etc.
 
Hi @Chris D - thanks for the reply.

1641392894924.png

Like this? Because that throws a new error and also stops my reactions from working and throws the following error:

1641393004877.png


Am I misunderstanding? :)
 
Not something stupid. but a fairly simple to fix mistake which is a bonus.

The entity content type should be the entity "short name" not an actual class name. So it should be set to TLS\Thoughts:Thought in your case. In that format, it can be used for repositories, finders, creating/finding entities etc.
Did you mean TLS\Thoughts:Thought because that seems to work..? :)
 
Ahhh yes, I did indeed miss the edit. Thanks for the help Chris, much appreciated.
 
Back
Top Bottom