XF 2.2 Extend instead replace of method in classes?


Well-known member
I need a another place for my custom_fields;
I replace XF/Entity/Threadfield with


namespace Robert9\ThreadFieldsHeader\XF\Entity;

use XF\Mvc\Entity\Structure;

class ThreadField extends XFCP_ThreadField
    public static function getStructure(Structure $structure)
                //'groups' => ['before', 'after', 'thread_status'],
                'groups' => ['before', 'after', 'thread_status', 'thread_header'],
                'has_user_group_editable' => true,
                'has_wrapper_template' => true,

        $structure->relations['ForumFields'] = [
            'entity' => 'XF:ForumField',
            'type' => self::TO_MANY,
            'conditions' => 'field_id'

        return $structure;

May someone show me, please, how to do this in a dynamic way like:

fetch the value from 'groups' => ['before', 'after', 'thread_status'],
add 'thread_header' and extend that array to be used by XF.

I have to do the same with XF/Repository/ThreadField

should i extend both classes or do this in a listener?
Call the parent and manipulate the returned structure object as you would using ordinary PHP. You can look at \XF\Entity\AbstractField::setupDefaultStructure, or just dump and inspect the structure object to see how it's set up.

$structure = parent::getStructure($structure);

$structure->columns['someColumn']['someSubArray'][] = 'appended_value';

return $structure;
Thank you. Meanwhile, I have solved it with:

    public static function getStructure(Structure $structure)
        $structure = parent::getStructure($structure);   
        return $structure;
Top Bottom