Skip to content

Commit b09ae67

Browse files
authored
feat: slug field (#14007)
Discussion #8859. Requires #14012. Exports a new `slugField`. This is a wrapper around the text field that you can drop into any field schema. A slug is a unique, indexed, URL-friendly string that identifies a particular document, often used to construct the URL of a webpage. Slugs are a fundamental concept for seemingly every project. Traditionally, you'd build this field from scratch, but there are many edge cases and nice-to-haves to makes this difficult to maintain by hand. For example, it needs to automatically generate based on the value of another field, provide UI to lock and re-generate the slug on-demand, etc. Fixes #13938. When autosave is enabled, the slug is only ever generated once after the initial create, leading to single character, or incomplete slugs. For example, it is expected that "My Title" → "my-title, however ends up as "m". This PR overhauls the field to feel a lot more natural. Now, we only generate the slug through: 1. The `create` operation, unless the user has modified the slug manually 2. The `update` operation, if: a. Autosave is _not_ enabled and there is no slug b. Autosave _is_ enabled, the doc is unpublished, and the user has not modified the slug manually The slug should stabilize after all above criteria have been met, because the URL is typically derived from the slug. This is to protect modifying potentially live URLs, breaking links, etc. without explicit intent. This fix, along with all the other features, is now standardized behind the new `slugField`: ```ts import type { CollectionConfig } from 'payload' import { slugField } from 'payload' export const MyCollection: CollectionConfig = { // ... fields: [ // ... slugField() ] } ``` In the future we could also make this field smart enough to auto increment itself when its generated slug is not unique. --- - To see the specific tasks where the Asana app for GitHub is being used, see below: - https://app.asana.com/0/0/1211513433305005
1 parent 444ca0f commit b09ae67

File tree

69 files changed

+636
-999
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

69 files changed

+636
-999
lines changed

docs/fields/collapsible.mdx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,6 @@ The Collapsible Field inherits all of the default admin options from the base [F
6666

6767
## Example
6868

69-
`collections/ExampleCollection.ts`
70-
7169
```ts
7270
import type { CollectionConfig } from 'payload'
7371

docs/fields/date.mdx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,6 @@ When only `pickerAppearance` is set, an equivalent format will be rendered in th
9696

9797
## Example
9898

99-
`collections/ExampleCollection.ts`
100-
10199
```ts
102100
import type { CollectionConfig } from 'payload'
103101

docs/fields/email.mdx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,6 @@ The Email Field inherits all of the default admin options from the base [Field A
7474

7575
## Example
7676

77-
`collections/ExampleCollection.ts`
78-
7977
```ts
8078
import type { CollectionConfig } from 'payload'
8179

docs/fields/group.mdx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,6 @@ The Group Field inherits all of the default admin options from the base [Field A
7777

7878
## Example
7979

80-
`collections/ExampleCollection.ts`
81-
8280
```ts
8381
import type { CollectionConfig } from 'payload'
8482

docs/fields/json.mdx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,6 @@ The JSON Field inherits all of the default admin options from the base [Field Ad
7575

7676
## Example
7777

78-
`collections/ExampleCollection.ts`
79-
8078
```ts
8179
import type { CollectionConfig } from 'payload'
8280

docs/fields/number.mdx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,6 @@ The Number Field inherits all of the default admin options from the base [Field
8080

8181
## Example
8282

83-
`collections/ExampleCollection.ts`
84-
8583
```ts
8684
import type { CollectionConfig } from 'payload'
8785

docs/fields/point.mdx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,6 @@ _\* An asterisk denotes that a property is required._
5555

5656
## Example
5757

58-
`collections/ExampleCollection.ts`
59-
6058
```ts
6159
import type { CollectionConfig } from 'payload'
6260

docs/fields/radio.mdx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,6 @@ The Radio Field inherits all of the default admin options from the base [Field A
9090

9191
## Example
9292

93-
`collections/ExampleCollection.ts`
94-
9593
```ts
9694
import type { CollectionConfig } from 'payload'
9795

docs/fields/row.mdx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,6 @@ _\* An asterisk denotes that a property is required._
4343

4444
## Example
4545

46-
`collections/ExampleCollection.ts`
47-
4846
```ts
4947
import type { CollectionConfig } from 'payload'
5048

docs/fields/select.mdx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,8 +149,6 @@ The Select Field inherits all of the default admin options from the base [Field
149149

150150
## Example
151151

152-
`collections/ExampleCollection.ts`
153-
154152
```ts
155153
import type { CollectionConfig } from 'payload'
156154

0 commit comments

Comments
 (0)