abstract class FormatMentions (View source)

User mention parsing utilities.

These allow users to be mentioned by their name using the @ prefix.

Constants

TAG_NAME

Methods

static void
configure(Configurator $config)

Formatter configuration callback.

static bool
filterMention(Tag $tag)

Determine whether a mention tag should be kept.

static void
rendering(Renderer $renderer, string $xml, Context|null $context)

Formatter rendering callback.

static array
getMentionedUsers(string $xml)

Get all the user IDs that have been mentioned in a piece of content.

Details

static void configure(Configurator $config)

Formatter configuration callback.

Set up a regular expression to parse plain-text mentions into an XML tag with a name attribute. Also apply a filter to the tag, to look up the username and populate an id attribute on the tag – or remove it if the user doesn't exist.

Parameters

Configurator $config

Return Value

void

static bool filterMention(Tag $tag)

Determine whether a mention tag should be kept.

Parameters

Tag $tag

Return Value

bool

static void rendering(Renderer $renderer, string $xml, Context|null $context)

Formatter rendering callback.

It is possible for a user's name to change after the creation of content that mentions them. So whenever we render content, we go through the mention tags and update the name attribute to the user's current name. This assumes that the mentions relationship is already loaded on the content model – otherwise we would run into an N+1 query problem.

Parameters

Renderer $renderer
string $xml
Context|null $context

Return Value

void

static array getMentionedUsers(string $xml)

Get all the user IDs that have been mentioned in a piece of content.

This is used in the HasBody model trait to populate the mentions relationship so that it can be eager loaded when the content is displayed, and the rendering function above can make use of the data.

Parameters

string $xml

Return Value

array