Skip to content

Commit db6ec30

Browse files
authored
feat(plugin-nested-docs): pass collection config as an arg to generateURL and generateLabel (#14086)
Closes #10378 We now pass `collection` containing the current collection's config into the `generateURL` and `generateLabel` as a third parameter. In the future we should change this into an object so we can more easily insert new params.
1 parent 3cf3f93 commit db6ec30

File tree

3 files changed

+15
-11
lines changed

3 files changed

+15
-11
lines changed

docs/plugins/nested-docs.mdx

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -129,10 +129,11 @@ nestedDocsPlugin({
129129

130130
The function takes two arguments and returns a string:
131131

132-
| Argument | Type | Description |
133-
| -------- | -------- | -------------------------------------------- |
134-
| `docs` | `Array` | An array of the breadcrumbs up to that point |
135-
| `doc` | `Object` | The current document being edited |
132+
| Argument | Type | Description |
133+
| ------------ | -------- | --------------------------------------------- |
134+
| `docs` | `Array` | An array of the breadcrumbs up to that point |
135+
| `doc` | `Object` | The current document being edited |
136+
| `collection` | `Object` | The collection config of the current document |
136137

137138
#### `generateURL`
138139

@@ -148,10 +149,11 @@ nestedDocsPlugin({
148149
})
149150
```
150151

151-
| Argument | Type | Description |
152-
| -------- | -------- | -------------------------------------------- |
153-
| `docs` | `Array` | An array of the breadcrumbs up to that point |
154-
| `doc` | `Object` | The current document being edited |
152+
| Argument | Type | Description |
153+
| ------------ | -------- | --------------------------------------------- |
154+
| `docs` | `Array` | An array of the breadcrumbs up to that point |
155+
| `doc` | `Object` | The current document being edited |
156+
| `collection` | `Object` | The collection config of the current document |
155157

156158
#### `parentFieldSlug`
157159

packages/plugin-nested-docs/src/types.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { CollectionSlug } from 'payload'
1+
import type { CollectionSlug, SanitizedCollectionConfig } from 'payload'
22

33
export type Breadcrumb = {
44
doc: string
@@ -9,11 +9,13 @@ export type Breadcrumb = {
99
export type GenerateURL = (
1010
docs: Array<Record<string, unknown>>,
1111
currentDoc: Record<string, unknown>,
12+
collection: SanitizedCollectionConfig,
1213
) => string
1314

1415
export type GenerateLabel = (
1516
docs: Array<Record<string, unknown>>,
1617
currentDoc: Record<string, unknown>,
18+
collection: SanitizedCollectionConfig,
1719
) => string
1820

1921
export type NestedDocsPluginConfig = {

packages/plugin-nested-docs/src/utilities/formatBreadcrumb.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,11 @@ export const formatBreadcrumb = ({
2727
const lastDoc = docs[docs.length - 1]!
2828

2929
if (typeof generateURL === 'function') {
30-
url = generateURL(docs, lastDoc)
30+
url = generateURL(docs, lastDoc, collection)
3131
}
3232

3333
if (typeof generateLabel === 'function') {
34-
label = generateLabel(docs, lastDoc)
34+
label = generateLabel(docs, lastDoc, collection)
3535
} else {
3636
const title = collection.admin?.useAsTitle ? lastDoc[collection.admin.useAsTitle] : ''
3737

0 commit comments

Comments
 (0)