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(plugin-seo)!: support overriding default fields via a function instead and fixes bugs regarding localized labels (#8958)
## The SEO plugin now takes in a function to override or add in new
fields
- `fieldOverrides` has been removed
- `fields` is now a function that takes in `defaultFields` and expects
an array of fields in return
This makes it a lot easier for end users to override and extend existing
fields and add new ones. This change also brings this plugin inline with
the pattern that we use in our other plugins.
```ts
// before
seoPlugin({
fieldOverrides: {
title: {
required: true,
},
},
fields: [
{
name: 'customField',
type: 'text',
}
]
})
// after
seoPlugin({
fields: ({ defaultFields }) => {
const modifiedFields = defaultFields.map((field) => {
// Override existing fields
if ('name' in field && field.name === 'title') {
return {
...field,
required: true,
}
}
return field
})
return [
...modifiedFields,
// Add a new field
{
name: 'ogTitle',
type: 'text',
label: 'og:title',
},
]
},
})
```
## Also fixes
- Localization labels not showing up on default fields
- The inability to add before and after inputs to default fields
#8893
Copy file name to clipboardExpand all lines: docs/plugins/seo.mdx
+16-24Lines changed: 16 additions & 24 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -89,12 +89,23 @@ An array of global slugs to enable SEO. Enabled globals receive a `meta` field w
89
89
90
90
##### `fields`
91
91
92
-
An array of fields that allows you to inject your own custom fields onto the `meta` field group. The following fields are provided by default:
92
+
A function that takes in the default fields via an object and expects an array of fields in return. You can use this to modify existing fields or add new ones.
93
93
94
-
-`title`: text
95
-
-`description`: textarea
96
-
-`image`: upload (if an `uploadsCollection` is provided)
97
-
-`preview`: ui
94
+
```ts
95
+
// payload.config.ts
96
+
{
97
+
// ...
98
+
seoPlugin({
99
+
fields: ({ defaultFields }) => [
100
+
...defaultFields,
101
+
{
102
+
name: 'customField',
103
+
type: 'text',
104
+
}
105
+
]
106
+
})
107
+
}
108
+
```
98
109
99
110
##### `uploadsCollection`
100
111
@@ -209,25 +220,6 @@ Rename the meta group interface name that is generated for TypeScript and GraphQ
209
220
}
210
221
```
211
222
212
-
#### `fieldOverrides`
213
-
214
-
Pass any valid field props to the base fields: Title, Description or Image.
215
-
216
-
```ts
217
-
// payload.config.ts
218
-
seoPlugin({
219
-
// ...
220
-
fieldOverrides: {
221
-
title: {
222
-
required: true,
223
-
},
224
-
description: {
225
-
localized: true,
226
-
},
227
-
},
228
-
})
229
-
```
230
-
231
223
## Direct use of fields
232
224
233
225
There is the option to directly import any of the fields from the plugin so that you can include them anywhere as needed.
0 commit comments