AndyB
Well-known member
I would like to extend the src/XF/Entity/Thread/php structure relation.
My add-on works correctly if I hack the code by adding the following:
to this section:
but of course I need to extend properly.
I tried to extend using the XFCP system like this:
then defining the class extensions like this:
but I get the following error when trying to view the forum_list:
My add-on works correctly if I hack the code by adding the following:
PHP:
'History' => [
'entity' => 'Andy\History:History',
'type' => self::TO_ONE,
'conditions' => 'thread_id',
'primary' => true
]
to this section:
PHP:
$structure->relations = [
'Forum' => [
'entity' => 'XF:Forum',
'type' => self::TO_ONE,
'conditions' => 'node_id',
'primary' => true,
'with' => 'Node'
],
'User' => [
'entity' => 'XF:User',
'type' => self::TO_ONE,
'conditions' => 'user_id',
'primary' => true
],
'FirstPost' => [
'entity' => 'XF:post',
'type' => self::TO_ONE,
'conditions' => [['post_id', '=', '$first_post_id']],
'primary' => true
],
'LastPost' => [
'entity' => 'XF:post',
'type' => self::TO_ONE,
'conditions' => [['post_id', '=', '$last_post_id']],
'primary' => true
],
'LastPoster' => [
'entity' => 'XF:User',
'type' => self::TO_ONE,
'conditions' => [['user_id', '=', '$last_post_user_id']],
'primary' => true
],
'Prefix' => [
'entity' => 'XF:ThreadPrefix',
'type' => self::TO_ONE,
'conditions' => 'prefix_id',
'primary' => true
],
'Read' => [
'entity' => 'XF:ThreadRead',
'type' => self::TO_MANY,
'conditions' => 'thread_id',
'key' => 'user_id'
],
'Watch' => [
'entity' => 'XF:ThreadWatch',
'type' => self::TO_MANY,
'conditions' => 'thread_id',
'key' => 'user_id'
],
'UserPosts' => [
'entity' => 'XF:ThreadUserPost',
'type' => self::TO_MANY,
'conditions' => 'thread_id',
'key' => 'user_id'
],
'DeletionLog' => [
'entity' => 'XF:DeletionLog',
'type' => self::TO_ONE,
'conditions' => [
['content_type', '=', 'thread'],
['content_id', '=', '$thread_id']
],
'primary' => true
],
'DraftReplies' => [
'entity' => 'XF:Draft',
'type' => self::TO_MANY,
'conditions' => [
['draft_key', '=', 'thread-', '$thread_id']
],
'key' => 'user_id'
],
'ApprovalQueue' => [
'entity' => 'XF:ApprovalQueue',
'type' => self::TO_ONE,
'conditions' => [
['content_type', '=', 'thread'],
['content_id', '=', '$thread_id']
],
'primary' => true
],
'Redirect' => [
'entity' => 'XF:ThreadRedirect',
'type' => self::TO_ONE,
'conditions' => 'thread_id',
'primary' => true
],
'ReplyBans' => [
'entity' => 'XF:ThreadReplyBan',
'type' => self::TO_MANY,
'conditions' => 'thread_id',
'key' => 'user_id'
],
'Poll' => [
'entity' => 'XF:poll',
'type' => self::TO_ONE,
'conditions' => [
['content_type', '=', 'thread'],
['content_id', '=', '$thread_id']
]
],
'CustomFields' => [
'entity' => 'XF:ThreadFieldValue',
'type' => self::TO_MANY,
'conditions' => 'thread_id',
'key' => 'field_id'
],
'History' => [
'entity' => 'Andy\History:History',
'type' => self::TO_ONE,
'conditions' => 'thread_id',
'primary' => true
]
];
but of course I need to extend properly.
I tried to extend using the XFCP system like this:
PHP:
<?php
namespace Andy\History\XF\Entity;
use XF\Mvc\Entity\Structure;
class Thread extends XFCP_Thread
{
public static function getStructure(Structure $structure)
{
$structure = parent::getStructure($structure);
$structure->relations = [
'History' => [
'entity' => 'Andy\History:History',
'type' => self::TO_ONE,
'conditions' => 'thread_id',
'primary' => true
]
];
return $structure;
}
}
then defining the class extensions like this:
but I get the following error when trying to view the forum_list: