mirror of
https://github.com/flarum/core.git
synced 2025-07-30 13:10:24 +02:00
Use URL generator for mention href
This commit is contained in:
@@ -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 = '<a href="/d/{@discussionid}/{@number}" class="PostMention" data-id="{@id}"><xsl:value-of select="@username"/></a>';
|
||||
$tag->template = '<a href="{$DISCUSSION_URL}{@discussionid}/{@number}" class="PostMention" data-id="{@id}"><xsl:value-of select="@username"/></a>';
|
||||
|
||||
$tag->filterChain
|
||||
->prepend([static::class, 'addId'])
|
||||
@@ -51,6 +67,14 @@ class FormatPostMentions
|
||||
$configurator->Preg->match('/\B@(?<username>[a-z0-9_-]+)#(?<id>\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
|
||||
|
@@ -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' => '']));
|
||||
}
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user