XF 2.0 Adding custom importers

Jake B.

Well-known member
Digging through the code trying to figure out how to add in custom importers I came across // TODO: event to add importers which makes me wonder if there is a "correct" way to do it currently or if I should just hack it into working by extending \XF\Container\Import
 
Currently using this, and it seems to work for now at least

Code:
public function initialize()
{
    $initialize = parent::initialize();

    $importers = $this->container('importers');

    $this->container['importers'] = function() use ($importers) {
        $importers[] = 'ThemeHouse\Reactions:DarkPostRatings';
        return $importers;
    };

    return $initialize;
}
 
There's a slightly better way.

You can just use the app_setup event:
PHP:
public static function appSetup(\XF\App $app)
{
    $container = $app->container();

    $container->extend('importers', function(array $importers)
    {
        $importers[] = 'ThemeHouse\Reactions:DarkPostRatings';
        return $importers;
    });
}
 
Do whatever hack you want now, though the extend is a good way to do it. At some point during the beta there will be a code event triggered instead so you can remove the hack.
 
There's a slightly better way.

You can just use the app_setup event:
PHP:
public static function appSetup(\XF\App $app)
{
    $container = $app->container();

    $container->extend('importers', function(array $importers)
    {
        $importers[] = 'ThemeHouse\Reactions:DarkPostRatings';
        return $importers;
    });
}

Forgot to reply here, doing it this way requires the $container->extend() to be wrapped in a try/catch because the 'imporers' container only exists when the importer subcontainer has loaded, reverted it back to my original method for now since it's a temporary solution anyways.

Edit: Just gave it another try with the try and catch and it doesn't register the importers, I'm guessing app_setup runs before that SubContainer is loaded
 
That's a good point. app_complete might work but, honestly, if what you were already doing works, stick with that. There will be an actual code event before you know it and it will be a moot point.
 
Back
Top Bottom