Page History
...
The core of mentions is implemented using content processors in totara_core\content namespace
which allows adding any kind of other content processing in a centralised and controllable manner.
Class | Purpose |
---|---|
totara_core\content\content | Represents content to process. |
totara_core\content\content_handler | The main class that searches for processors and handles content through them. |
totara_core\content\processor | Abstract class which all content processors must implement. |
totara_core\content\processor\mention_processor | Implementation of content processor that searches mentions in the content and sends notifications. |
totara_core\task\user_mention_notify_task | An adhoc task that sends notifications to the users. |
totara_core\output\mention_message | Class for the template used to generate message. It represents Mustache template located at server/totara/core/templates/mention_message.mustache . |
How to add @mentions support
...
You can use different areas for adding support of different mentions within one component.
The mechanism of finding users to @mention
By default when using @mention, the system will try to find all the users within the system, limited to the user's tenant if multitenancy is enabled. The user will only be able to @mention the users that they can see.
For example, user one in tenant A will not be able to search for user two in tenant B. Additionally, user one will not be able to search for system-level users, but only the users that are in the same tenant (tenant A) and all the participants of that tenant.
This works for several places, however, we have enabled hooks to allow plugins to override the logic of searching users within @mention. The hook will only run when there are necessary data provided such as: 'component', 'context' and 'area' where the @mention is being used. With the hook, plugins are free to provide the list of users that can be used for @mention.
Hook class name: "editor_weka\hook\search_users_by_pattern"
Example of using the hook within watcher:
Code Block | ||
---|---|---|
| ||
function on_search_users(editor_weka\hook\search_users_by_pattern $hook): void {
if ($hook->is_db_run()) {
// Hook has been run with injected user records. We should skip it.
return;
}
$component = $hook->get_component();
if ('your_system_component_name' !== $component) {
// @mention is not used in the plugin place.
return;
}
// This is where to actually search for users and inject result to the hook.
$users = \your_system_component_name\some_class::search_for_users($hook->get_pattern());
$hook->add_users($users);
// Marking DB run is quite important, because with this flag, once the hook is executed,
// the query will return the list of injected users straight away. Hence with out this flag,
// the query will fallback to the default logics of searching users.
$hook->mark_db_run();
} |