XF 2.1 Extending XFMG class?

stan1226

Member
I am trying to extend a function of the XFMG.

I uploaded an addon for this, with the file stan1226\XFMGOrderByTitle\OrderByTitle\NewAbstractList.php which should replace the getAvailableSorts() function of XFMG\ControllerPlugin\AbstractPlugin.php

I added a class extension in developer admin panel:
XFMG\ControllerPlugin\AbstractPlugin
->
stan1226\XFMGOrderByTitle\OrderByTitle\NewAbstractList
designated to my addon

I included a vardump to test if it is actually called, here's my code
PHP:
<?php

namespace stan1226\XFMGOrderByTitle\OrderByTitle;

abstract class NewAbstractList extends XFCP_AbstractPlugin
{
    public function getAvailableSorts()
    {
        \XF::dump('test');
        // maps [name of sort] => field in/relative to MediaItem entity
        return [
            'comment_count' => 'comment_count',
            'rating_weighted' => 'rating_weighted',
            'reaction_score' => 'reaction_score',
            'view_count' => 'view_count',
            'title' => 'title'
        ];
    }
}

So far nothing I try actually calls my function (removing XFCP_, try to extend the XF\ControllerPlugin\AbstractPlugin that the XFMG is extending, etc). Anybody got an idea what is missing here? I really appreciate any help.
 
You cannot extend an abstract class. You need to extend AlbumList and/or MediaList and the XFCP extension class would be XFCP_AlbumList and/or XFCP_MediaList.
Thank you so much, that worked fine.

One additional question: How can I add the class extensions I have to make in dev adminpanel to install itself when installing the addon?
 
They should be written out to your add-on files, like this:

1589292503070.webp

Once you have finished development there is a xf-addon:build-release CLI command which exports everything into the correct format Zip archive that can be installed in XF.
 
Top Bottom