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
feat: adds admin.formatDocURL function to control list view linking (#13773)
### What?
Adds a new `formatDocURL` function to collection admin configuration
that allows users to control the linkable state and URLs of first column
fields in list views.
### Why?
To provide a way to disable automatic link creation from the first
column or provide custom URLs based on document data, user permissions,
view context, and document state.
### How?
- Added `formatDocURL` function type to `CollectionAdminOptions` that
receives document data, default URL, request context, collection slug,
and view type
- Modified `renderCell` to call the function when available and handle
three return types:
- `null`: disables linking entirely
- `string`: uses custom URL
- other: falls back to no linking for safety
- Added function to server-only properties to prevent React Server
Components serialization issues
- Updated `DefaultCell` component to support custom `linkURL` prop
---
- To see the specific tasks where the Asana app for GitHub is being
used, see below:
- https://app.asana.com/0/0/1211211792037945
Copy file name to clipboardExpand all lines: docs/configuration/collections.mdx
+71Lines changed: 71 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -136,6 +136,7 @@ The following options are available:
136
136
|`enableRichTextLink`| The [Rich Text](../fields/rich-text) field features a `Link` element which allows for users to automatically reference related documents within their rich text. Set to `true` by default. |
137
137
|`enableRichTextRelationship`| The [Rich Text](../fields/rich-text) field features a `Relationship` element which allows for users to automatically reference related documents within their rich text. Set to `true` by default. |
138
138
|`folders`| A boolean to enable folders for a given collection. Defaults to `false`. [More details](../folders/overview). |
139
+
|`formatDocURL`| Function to customize document links in the List View. Return `null` to disable linking, or a string for custom URLs. [More details](#format-document-urls). |
139
140
|`meta`| Page metadata overrides to apply to this Collection within the Admin Panel. [More details](../admin/metadata). |
140
141
|`preview`| Function to generate preview URLs within the Admin Panel that can point to your app. [More details](../admin/preview). |
141
142
|`livePreview`| Enable real-time editing for instant visual feedback of your front-end application. [More details](../live-preview/overview). |
The `formatDocURL` function allows you to customize how document links are generated in the List View. This is useful for disabling links for certain documents, redirecting to custom destinations, or modifying URLs based on user context or document state.
340
+
341
+
To define a custom document URL formatter, use the `admin.formatDocURL` property in your Collection Config:
|`defaultURL`| The default URL that Payload would normally generate for this document. You can return this as-is, modify it, or replace it entirely. |
378
+
|`req`| The full [PayloadRequest](../types/payload-request) object, providing access to user context, payload instance, and other request data |
379
+
|`collectionSlug`| The slug of the current collection |
380
+
|`viewType`| The current view context (`'list'`, `'trash'`, etc.) where the link is being generated |
381
+
382
+
The function should return:
383
+
384
+
-`null` to disable the link entirely (no link will be rendered)
385
+
- A `string` containing the custom URL to use for the link
386
+
- The `defaultURL` parameter to use Payload's default linking behavior
387
+
388
+
<Bannertype="success">
389
+
**Tip:** The `defaultURL` parameter saves you from having to reconstruct URLs
390
+
manually. You can modify it by appending query parameters or use it as a
391
+
fallback for your custom logic.
392
+
</Banner>
393
+
394
+
#### Examples
395
+
396
+
**Disable linking for certain users:**
397
+
398
+
```ts
399
+
formatDocURL: ({ defaultURL, req }) => {
400
+
if (req.user?.role==='editor') {
401
+
returnnull// No link rendered
402
+
}
403
+
returndefaultURL
404
+
}
405
+
```
406
+
336
407
## GraphQL
337
408
338
409
You can completely disable GraphQL for this collection by passing `graphQL: false` to your collection config. This will completely disable all queries, mutations, and types from appearing in your GraphQL schema.
0 commit comments