XF 2.2 Extend instead replace of method in classes?

Robert9

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

PHP:
<?php

namespace Robert9\ThreadFieldsHeader\XF\Entity;

use XF\Mvc\Entity\Structure;

class ThreadField extends XFCP_ThreadField
{
    public static function getStructure(Structure $structure)
    {
        self::setupDefaultStructure(
            $structure,
            'xf_thread_field',
            'XF:ThreadField',
            [
                //'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.

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

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

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

Code:
    public static function getStructure(Structure $structure)
    {
        $structure = parent::getStructure($structure);   
        $structure->columns['display_group']['allowedValues'][]='thread_header';
        return $structure;
    }
 
Back
Top Bottom