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:
I had a look at how XF handles post reporting and came up with this in my TLS/Thoughts/Report/Thought.php:
and my controller:
My report is inserting in to the database correctly, but if I try and view it I get the following:
What am I doing wrong? Is it something stupid?
Thanks in advance.
I have created the content type in the ACP like this:
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:
What am I doing wrong? Is it something stupid?
Thanks in advance.