I guess I should add the following to the extend.php
use FoF\Upload\Contracts\Template;
use FoF\Upload\File;
class MyTemplate implements Template
{
public function tag(): string
{
return 'filenamelink';
}
public function name(): string
{
return 'Filename link';
}
public function description(): string
{
return 'Generates a link with the filename as text';
}
public function preview(File $file): string
{
return '[' . $file->base_name . '](' . $file->url . ')';
}
}
However I don't know how to register that template. According to the wiki, I should register it from a service provider.
I have the following in the extend.php
:
return [
// Register extenders here to customize your forum!
(new FoF\Sitemap\Extend\RemoveResource(FoF\Sitemap\Resources\User::class))
];
Can I extend it like this:
use Flarum\Foundation\AbstractServiceProvider;
use FoF\Upload\Helpers\Util;
class MyServiceProvider extends AbstractServiceProvider
{
public function register()
{
$this->container->make(Util::class)->addRenderTemplate($this->container->make(MyTemplate::class));
}
}
return [
// Register extenders here to customize your forum!
(new FoF\Sitemap\Extend\RemoveResource(FoF\Sitemap\Resources\User::class)),
(new Extend\ServiceProvider())
->register(MyServiceProvider::class),
];
Or ultimately to produce the following extend.php
:
<?php
/*
* This file is part of Flarum.
*
* For detailed copyright and license information, please view the
* LICENSE file that was distributed with this source code.
*/
use Flarum\Extend;
use FoF\Upload\Contracts\Template;
use FoF\Upload\File;
use Flarum\Foundation\AbstractServiceProvider;
use FoF\Upload\Helpers\Util;
class MyTemplate implements Template
{
public function tag(): string
{
return 'filenamelink';
}
public function name(): string
{
return 'Filename link';
}
public function description(): string
{
return 'Generates a link with the filename as text';
}
public function preview(File $file): string
{
return '[' . $file->base_name . '](' . $file->url . ')';
}
}
class MyServiceProvider extends AbstractServiceProvider
{
public function register()
{
$this->container->make(Util::class)->addRenderTemplate($this->container->make(MyTemplate::class));
}
}
return [
// Register extenders here to customize your forum!
(new FoF\Sitemap\Extend\RemoveResource(FoF\Sitemap\Resources\User::class)),
(new Extend\ServiceProvider())
->register(MyServiceProvider::class),
];
Is that the proper code?