mirror of
https://github.com/flarum/core.git
synced 2025-07-28 20:20:34 +02:00
Make mention formatter work in live preview 🎉
This commit is contained in:
@@ -19,11 +19,16 @@ class AddPostMentionsFormatter
|
||||
$tagName = 'POSTMENTION';
|
||||
|
||||
$tag = $configurator->tags->add($tagName);
|
||||
|
||||
$tag->attributes->add('username');
|
||||
$tag->attributes->add('number');
|
||||
$tag->attributes->add('id')->filterChain->append('#uint');
|
||||
$tag->attributes['id']->required = false;
|
||||
|
||||
$tag->template = '<a href="{$DISCUSSION_URL}{@number}" class="PostMention" data-number="{@number}"><xsl:value-of select="@username"/></a>';
|
||||
$tag->filterChain->prepend([static::class, 'addId'])->addParameterByName('post');
|
||||
$tag->filterChain->prepend([static::class, 'addId'])
|
||||
->addParameterByName('post')
|
||||
->setJS('function() { return true; }');
|
||||
|
||||
$configurator->Preg->match('/\B@(?<username>[a-z0-9_-]+)#(?<number>\d+)/i', $tagName);
|
||||
}
|
||||
@@ -40,8 +45,10 @@ class AddPostMentionsFormatter
|
||||
->where('number', $tag->getAttribute('number'))
|
||||
->pluck('id');
|
||||
|
||||
$tag->setAttribute('id', $id);
|
||||
if ($id) {
|
||||
$tag->setAttribute('id', $id);
|
||||
|
||||
return true;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -30,8 +30,12 @@ class AddUserMentionsFormatter
|
||||
$tag = $configurator->tags->add($tagName);
|
||||
$tag->attributes->add('username');
|
||||
$tag->attributes->add('id')->filterChain->append('#uint');
|
||||
$tag->attributes['id']->required = false;
|
||||
|
||||
$tag->template = '<a href="{$PROFILE_URL}{@username}" class="UserMention">@<xsl:value-of select="@username"/></a>';
|
||||
$tag->filterChain->prepend([static::class, 'addId'])->addParameterByName('userRepository');
|
||||
$tag->filterChain->prepend([static::class, 'addId'])
|
||||
->addParameterByName('userRepository')
|
||||
->setJS('function() { return true; }');
|
||||
|
||||
$configurator->Preg->match('/\B@(?<username>[a-z0-9_-]+)(?!#)/i', $tagName);
|
||||
}
|
||||
@@ -49,8 +53,10 @@ class AddUserMentionsFormatter
|
||||
|
||||
public static function addId($tag, UserRepository $users)
|
||||
{
|
||||
$tag->setAttribute('id', $users->getIdForUsername($tag->getAttribute('username')));
|
||||
if ($id = $users->getIdForUsername($tag->getAttribute('username'))) {
|
||||
$tag->setAttribute('id', $id);
|
||||
|
||||
return true;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user