FriendsOfFlarum / upload

The file upload extension with insane intelligence for your Flarum forum.
https://discuss.flarum.org/d/4154
MIT License
176 stars 95 forks source link

Custom Templates are not showing up in the admin interface #260

Closed ghost closed 3 years ago

ghost commented 3 years ago

I have tried following the Wiki page guideline to create a custom template, but have noticed that it is currently outdated and the example provided does not generate a working template (mostly due to the lack of the Settings class, which has been renamed to Utils, but the change doesn't seem to have been updated in the Wiki). After using the correct class (Utils) to add the template and registering the corresponding ServiceProvider to the forum, it still doesn't seem to be working, or at least not showing up in the admin panel. I have tried to reconstruct the process of creating the default templates as far as I could, but I am still not able to find the correct solution. I have also tried using the internal AbstractTemplate to create my own custom template, but there doesn't seem to be much of a difference.

This is the code of extend.php that I have used in my project:

<?php

namespace Dev\TemplateExtension;

use Flarum\Extend;
use Flarum\Foundation\AbstractServiceProvider;
use Flarum\Foundation\Application;
use Flarum\Settings\Event\Deserializing;

//use FoF\Upload\Contracts\Template;
use FoF\Upload\File;
use FoF\Upload\Templates\AbstractTemplate;
use FoF\Upload\Helpers\Util;

class AudioTemplate extends AbstractTemplate
{
    protected $tag = 'upl-audio';

    public function name(): string
    {
        return 'Audio Template';
    }

    public function description(): string
    {
        return 'A small audio player';
    }

    public function preview(File $file): string
    {
        return $file->url;
    }
}

class AudioTemplateServiceProvider extends AbstractServiceProvider
{
    public function register()
    {
        $util = $this->app->make(Util::class);

        $util->addRenderTemplate($this->app->make(AudioTemplate::class));
    }
}
return [
    (new Extend\ServiceProvider())
        ->register(AudioTemplateServiceProvider::class),

    (new Extend\Frontend('forum'))
        ->js(__DIR__.'/js/dist/forum.js'),

    (new Extend\Frontend('admin'))
        ->js(__DIR__.'/js/dist/admin.js'),

    new Extend\Locales(__DIR__ . '/resources/locale'),
];

The extension is active and working well otherwise, but I cannot get this piece of code to work, or show up in the admin panel. One guess that I have is that the AddAvailableTemplatesToAdmin event isn't called properly? Haven't tested it, but maybe the function is executed before my extension is loaded? After examining the Flarum database, I have also found that the settings table does not contain an entry for the availableTemplates that seems to be read when loading the available Templates in the admin panel.

I hope this could help in finding the bug, or maybe I have overseen something very obvious. Kind regards