Mention

Mention users by their user name in page content.

0 stars out of 5

0 0 0 0 0
  • Author Taufik Nurrohman
  • Maintainer 1
  • Member
  • Version 1.0.0

Type an @ character in the page content followed by a user name to automatically turn it into a user link. The link text can be set based on the key value in the .\lot\x\mention\state.php file:

KeyResult
authorLink text will be the author property of the User class instance. When you hover over it, the user key (the user property) appears in the tooltip.
userLink text will be the user property of the User class instance. When you hover over it, the display name (the author property) appears in the tooltip.
*Where * is any string, link text will be the * property of the User class instance.

If the key value is a callable function name or an anonymous function, the value returned by that function is used to replace the mention pattern:

<?php

return [
    'key' => function (string $text): string {
        // In this context, `$this` refers to the instance of the `User` class
        return '<a href="' . ($this->link ?: $this->url) . '">' . $text . '</a>';
    }
];

If you want to set its value as a function name, make sure that it cannot possibly exist as a property name of a User class instance, to prevent it from triggering a property call. You can do this in a number of ways, such as creating a long and unique function name, or creating a function name under a namespace. As long as a function name contains a \ character, there is very little chance that it will be detected as a property name:

function name(string $text): string {
    return '<mark>' . $text . '</mark>';
}

// This will most likely return the `$user->name` value, not the return value of the `name()` function
return ['key' => 'name'];

Any mention pattern found in the HTML tag (as a tag name, attribute name or value) will be ignored. Any mention pattern found in the HTML content of <code>, <kbd>, <pre>, <script>, <style>, and <textarea> will also be ignored.

0 Comments

No comments yet.