Add canonical URL to discussion list (#1814)

This commit is contained in:
David Sevilla Martín 2019-08-07 18:01:25 -04:00 committed by Daniël Klabbers
parent a737b98e7f
commit 54f733ca80

View File

@ -12,6 +12,8 @@ namespace Flarum\Forum\Content;
use Flarum\Api\Client;
use Flarum\Api\Controller\ListDiscussionsController;
use Flarum\Frontend\Document;
use Flarum\Http\UrlGenerator;
use Flarum\Settings\SettingsRepositoryInterface;
use Flarum\User\User;
use Illuminate\Contracts\View\Factory;
use Illuminate\Support\Arr;
@ -29,14 +31,28 @@ class Index
*/
protected $view;
/**
* @var SettingsRepositoryInterface
*/
protected $settings;
/**
* @var UrlGenerator
*/
protected $url;
/**
* @param Client $api
* @param Factory $view
* @param SettingsRepositoryInterface $settings
* @param UrlGenerator $url
*/
public function __construct(Client $api, Factory $view)
public function __construct(Client $api, Factory $view, SettingsRepositoryInterface $settings, UrlGenerator $url)
{
$this->api = $api;
$this->view = $view;
$this->settings = $settings;
$this->url = $url;
}
public function __invoke(Document $document, Request $request)
@ -56,9 +72,11 @@ class Index
];
$apiDocument = $this->getApiDocument($request->getAttribute('actor'), $params);
$defaultRoute = $this->settings->get('default_route');
$document->content = $this->view->make('flarum.forum::frontend.content.index', compact('apiDocument', 'page'));
$document->payload['apiDocument'] = $apiDocument;
$document->canonicalUrl = $defaultRoute === '/all' ? $this->url->to('forum')->base() : $request->getUri()->withQuery('');
return $document;
}