diff --git a/extensions/mentions/src/Listener/FormatPostMentions.php b/extensions/mentions/src/Listener/FormatPostMentions.php index 990862573..b96b8d7fa 100755 --- a/extensions/mentions/src/Listener/FormatPostMentions.php +++ b/extensions/mentions/src/Listener/FormatPostMentions.php @@ -12,16 +12,32 @@ namespace Flarum\Mentions\Listener; use Flarum\Core\Post\CommentPost; use Flarum\Event\ConfigureFormatter; +use Flarum\Event\ConfigureFormatterRenderer; +use Flarum\Forum\UrlGenerator; use Illuminate\Contracts\Events\Dispatcher; class FormatPostMentions { + /** + * @var UrlGenerator + */ + protected $url; + + /** + * @param UrlGenerator $url + */ + public function __construct(UrlGenerator $url) + { + $this->url = $url; + } + /** * @param Dispatcher $events */ public function subscribe(Dispatcher $events) { $events->listen(ConfigureFormatter::class, [$this, 'configure']); + $events->listen(ConfigureFormatterRenderer::class, [$this, 'render']); } /** @@ -42,7 +58,7 @@ class FormatPostMentions $tag->attributes['number']->required = false; $tag->attributes['discussionid']->required = false; - $tag->template = ''; + $tag->template = ''; $tag->filterChain ->prepend([static::class, 'addId']) @@ -51,6 +67,14 @@ class FormatPostMentions $configurator->Preg->match('/\B@(?[a-z0-9_-]+)#(?\d+)/i', $tagName); } + /** + * @param ConfigureFormatterRenderer $event + */ + public function render(ConfigureFormatterRenderer $event) + { + $event->renderer->setParameter('DISCUSSION_URL', $this->url->toRoute('discussion', ['id' => ''])); + } + /** * @param $tag * @return bool diff --git a/extensions/mentions/src/Listener/FormatUserMentions.php b/extensions/mentions/src/Listener/FormatUserMentions.php index 8241ea417..07d588521 100755 --- a/extensions/mentions/src/Listener/FormatUserMentions.php +++ b/extensions/mentions/src/Listener/FormatUserMentions.php @@ -14,6 +14,7 @@ use Flarum\Core\Repository\UserRepository; use Flarum\Event\ConfigureFormatter; use Flarum\Event\ConfigureFormatterParser; use Flarum\Event\ConfigureFormatterRenderer; +use Flarum\Forum\UrlGenerator; use Illuminate\Contracts\Events\Dispatcher; class FormatUserMentions @@ -24,11 +25,18 @@ class FormatUserMentions protected $users; /** - * @param UserRepository $users + * @var UrlGenerator */ - public function __construct(UserRepository $users) + protected $url; + + /** + * @param UserRepository $users + * @param UrlGenerator $url + */ + public function __construct(UserRepository $users, UrlGenerator $url) { $this->users = $users; + $this->url = $url; } /** @@ -76,8 +84,7 @@ class FormatUserMentions */ public function render(ConfigureFormatterRenderer $event) { - // TODO: use URL generator - $event->renderer->setParameter('PROFILE_URL', '/u/'); + $event->renderer->setParameter('PROFILE_URL', $this->url->toRoute('user', ['username' => ''])); } /**