You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
:description: TinyMCE User Lookup provides an API to identify the current user and retrieve user details via integration-defined methods.
3
-
:keywords: userLookup, fetchUsers, userId, avatar, user metadata
4
+
:keywords: userLookup, fetchUsers, user_id, user management, collaborative editing
4
5
5
6
The {productname} User Lookup API enables integrations to retrieve and cache user details (such as names and avatars) and identify the current user within the editor.
6
7
7
-
This is useful when building features that rely on user context, such as commenting, or displaying a list of elements container user information, and lets you manage user data efficiently with built-in caching.
8
+
This is useful when building features that rely on user context, such as commenting, collaborative editing, or displaying user-specific information. The API provides built-in caching for efficient user data management.
8
9
9
-
== Using the User Lookup API
10
+
== How it works
10
11
11
-
Follow the steps below to configure and use the `userLookup` API.
12
+
The User Lookup API provides two main functions:
12
13
13
-
[[step-1-set-the-current-user]]
14
-
=== 1. Set the current user_id
14
+
[cols="2,4",options="header"]
15
+
|===
16
+
|Method|Description
15
17
16
-
The first step is to tell the editor which user is currently active. This is done using the `+user_id+` initialization option.
18
+
|`editor.userLookup.userId`|Returns the current user's ID, set via the `user_id` configuration option.
19
+
|`editor.userLookup.fetchUsers(userIds)`|Fetches and caches user information. Returns a Promise-based lookup object.
For a basic setup, you only need to configure the `user_id` option:
25
+
26
+
[source,js]
27
+
----
28
+
tinymce.init({
29
+
selector: '#editor',
30
+
user_id: 'current-user-id'
31
+
});
32
+
----
33
+
34
+
For more advanced user data fetching, see the <<options,Options>> section below.
35
+
36
+
== Understanding user lookup
37
+
38
+
The User Lookup API handles three main scenarios:
39
+
40
+
1. **Basic identification**: Setting a current user ID for editor context
41
+
2. **Dynamic fetching**: Retrieving user details from backend systems
42
+
3. **Fallback behavior**: Auto-generating user data when no fetch function is provided
43
+
44
+
== Data structure
45
+
46
+
=== User
47
+
48
+
The user is an `Object` that contains the following fields:
49
+
50
+
[cols="1,1,1,3",options="header"]
51
+
|===
52
+
| Field | Type | Required? | Description
53
+
| `id` | `string` | required | The unique string ID of the user.
54
+
| `name` | `string` | optional | The display name of the user. If not provided, defaults to the `id`.
55
+
| `avatar` | `string` | optional | The URL of the user's avatar image or data URI. If not provided, an auto-generated SVG using the user's initials will be used.
56
+
| `custom` | `Object` | optional | Additional metadata for the user.
57
+
|===
58
+
59
+
.Example user object:
60
+
[source,js]
61
+
----
62
+
{
63
+
id: 'user-1', // Required: User identifier
64
+
name: 'Jane Doe', // Optional: Display name (defaults to id)
65
+
avatar: 'https://...', // Optional: Avatar URL or data URI
66
+
custom: { // Optional: Additional metadata
67
+
role: 'admin',
68
+
department: 'engineering'
69
+
}
70
+
}
71
+
----
72
+
73
+
== Options
74
+
75
+
The following configuration options affect the behavior of the User Lookup API.
This example shows how to set up a complete user lookup system with a simulated backend:
35
115
36
116
.Example
37
117
[source,js]
@@ -68,51 +148,18 @@ tinymce.init({
68
148
});
69
149
----
70
150
71
-
This example demonstrates how to simulate user lookup in-browser. In a production environment, this function could be swapped out for a network request.
151
+
This example demonstrates how to simulate user lookup in-browser. In a production environment, the `fetch_users` function would typically make network requests to your backend API.
72
152
73
-
The returned array should include objects with:
153
+
[[fallback-behavior]]
154
+
=== Fallback Behavior
74
155
75
-
* `id` (string) - Required
76
-
* `name` (string) - Optional (defaults to `id`)
77
-
* `avatar` (string, URL or data URI) - Optional (auto-generated SVG fallback if missing)
78
-
* `custom` (object) - Optional metadata
156
+
If no `fetch_users` function is configured, {productname} will return fallback users with auto-generated data:
79
157
80
-
[[step-3-fetch-user-information]]
81
-
=== 3. Fetch user information
158
+
* `name` defaults to the user ID
159
+
* `avatar` is an auto-generated SVG using the first letter of the name
82
160
83
-
Once the editor is initialized, use the API to look up multiple users:
The User Lookup API provides the following methods:
166
213
167
-
[cols="2,4",options="header"]
214
+
[cols="3,4,2",options="header"]
168
215
|===
169
-
|Function|Description
216
+
|Method|Description|Return Type
170
217
171
-
|`editor.userLookup.userId`|Returns the current user’s ID, set via the `user_id` option.
172
-
|`editor.userLookup.fetchUsers(userIds)`|Fetches and caches user information from a backend.
218
+
|`editor.userLookup.userId`|Gets the current user's ID, set via the `user_id` configuration option.|`string`
219
+
|`editor.userLookup.fetchUsers(userIds)`|Fetches and caches user information for the specified user IDs. Returns an object where each key is a user ID and each value is a Promise that resolves to the user object.|`Object<string, Promise<UserObject>>`
173
220
|===
174
-
175
-
== Example User Object
176
-
177
-
Each returned user object from `fetchUsers()` has the following structure:
Copy file name to clipboardExpand all lines: modules/ROOT/partials/configuration/fetch_users.adoc
+3-5Lines changed: 3 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,7 +1,7 @@
1
1
[[fetch_users]]
2
2
== `fetch_users`
3
3
4
-
A **required callback function** that fetches user data. This function is called with an array of user IDs and should return a `Promise` that resolves to an array of user objects. The callback is used by the xref:userlookup.adoc[`UserLookup`] API. If the returned array does not include all requested user IDs, promises for the missing users will be rejected with a "User {id} not found" error.
4
+
A **required callback function** that fetches user data. This function is called with an array of user IDs and should return a `Promise` that resolves to an array of user objects. The callback is used by the xref:userlookup.adoc[`UserLookup`] API. If the returned array does not include all requested user IDs, promises for the missing users will be rejected with a "User \{id} not found" error.
5
5
6
6
*Type:* `Function`
7
7
@@ -11,8 +11,7 @@ A **required callback function** that fetches user data. This function is called
11
11
*Returns:*
12
12
- `Promise<Array<Object>>`: A promise that resolves to an array of user objects.
0 commit comments