diff --git a/docs/configuration/collections.mdx b/docs/configuration/collections.mdx index 4d794287c2..2c87d653ed 100644 --- a/docs/configuration/collections.mdx +++ b/docs/configuration/collections.mdx @@ -75,6 +75,7 @@ You can customize the way that the Admin panel behaves on a collection-by-collec | `defaultColumns` | Array of field names that correspond to which columns to show by default in this collection's List view. | | `disableDuplicate ` | Disables the "Duplicate" button while editing documents within this collection. | | `hideAPIURL` | Hides the "API URL" meta field while editing documents within this collection. | +| `enableRichTextLink` | The [Rich Text](/docs/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. | | `enableRichTextRelationship` | The [Rich Text](/docs/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. | | `preview` | Function to generate preview URLS within the Admin panel that can point to your app. [More](#preview). | | `components` | Swap in your own React components to be used within this collection. [More](/docs/admin/components#collections) | diff --git a/docs/fields/rich-text.mdx b/docs/fields/rich-text.mdx index 791d7036b0..258646179f 100644 --- a/docs/fields/rich-text.mdx +++ b/docs/fields/rich-text.mdx @@ -108,7 +108,7 @@ Similar to the `relationship` element, the `upload` element is a user-friendly w Tip:
- Collections are automatically allowed to be selected within the Rich Text relationship and upload elements by default. If you want to disable a collection from being able to be referenced in Rich Text fields, set the collection admin option of enableRichTextRelationship to false. + Collections are automatically allowed to be selected within the Rich Text relationship and upload elements by default. If you want to disable a collection from being able to be referenced in Rich Text fields, set the collection admin options of enableRichTextLink and enableRichTextRelationship to false.
Relationship and Upload elements are populated dynamically into your Rich Text field' content. Within the REST and Local APIs, any present RichText `relationship` or `upload` elements will respect the `depth` option that you pass, and will be populated accordingly. In GraphQL, each `richText` field accepts an argument of `depth` for you to utilize. diff --git a/src/admin/components/forms/field-types/RichText/elements/link/LinkDrawer/baseFields.ts b/src/admin/components/forms/field-types/RichText/elements/link/LinkDrawer/baseFields.ts index bc0e5c7569..7bba95f8f1 100644 --- a/src/admin/components/forms/field-types/RichText/elements/link/LinkDrawer/baseFields.ts +++ b/src/admin/components/forms/field-types/RichText/elements/link/LinkDrawer/baseFields.ts @@ -56,7 +56,7 @@ export const getBaseFields = (config: Config): Field[] => [ label: translations['fields:chooseDocumentToLink'], type: 'relationship', required: true, - relationTo: config.collections.map(({ slug }) => slug), + relationTo: config.collections.filter(({ admin: { enableRichTextLink } }) => enableRichTextLink).map(({ slug }) => slug), admin: { condition: ({ linkType }) => { return linkType === 'internal'; diff --git a/src/collections/config/defaults.ts b/src/collections/config/defaults.ts index da20e64571..fde30c9eca 100644 --- a/src/collections/config/defaults.ts +++ b/src/collections/config/defaults.ts @@ -12,6 +12,7 @@ export const defaults = { admin: { useAsTitle: 'id', components: {}, + enableRichTextLink: true, enableRichTextRelationship: true, pagination: { defaultLimit: 10, diff --git a/src/collections/config/schema.ts b/src/collections/config/schema.ts index 32a2430f87..80332f01df 100644 --- a/src/collections/config/schema.ts +++ b/src/collections/config/schema.ts @@ -56,6 +56,7 @@ const collectionSchema = joi.object().keys({ hooks: joi.object({ beforeDuplicate: joi.func(), }), + enableRichTextLink: joi.boolean(), enableRichTextRelationship: joi.boolean(), components: joi.object({ views: joi.object({ diff --git a/src/collections/config/types.ts b/src/collections/config/types.ts index cd158e1ca6..c02b4d69e2 100644 --- a/src/collections/config/types.ts +++ b/src/collections/config/types.ts @@ -228,6 +228,7 @@ export type CollectionAdminOptions = { defaultLimit?: number limits?: number[] } + enableRichTextLink?: boolean enableRichTextRelationship?: boolean /** * Function to generate custom preview URL diff --git a/test/fields/collections/Array/index.ts b/test/fields/collections/Array/index.ts index 0446dacd9c..4c07b70bfa 100644 --- a/test/fields/collections/Array/index.ts +++ b/test/fields/collections/Array/index.ts @@ -10,6 +10,9 @@ export const arrayFieldsSlug = 'array-fields'; const ArrayFields: CollectionConfig = { slug: arrayFieldsSlug, + admin: { + enableRichTextLink: false, + }, fields: [ { name: 'items', diff --git a/test/fields/e2e.spec.ts b/test/fields/e2e.spec.ts index 03ccda9fac..76f5cc98eb 100644 --- a/test/fields/e2e.spec.ts +++ b/test/fields/e2e.spec.ts @@ -511,6 +511,23 @@ describe('fields', () => { await expect(menu).not.toContainText('Uploads3'); }); + test('should only list RTE enabled collections in link drawer', async () => { + await navigateToRichTextFields(); + + await page.locator('.rich-text__toolbar button:not([disabled]) .link').first().click(); + + const editLinkModal = await page.locator('[id^=drawer_1_rich-text-link-]'); + await expect(editLinkModal).toBeVisible(); + + await editLinkModal.locator('label[for="field-linkType-internal"]').click(); + await editLinkModal.locator('.relationship__wrap .rs__control').click(); + + const menu = page.locator('.relationship__wrap .rs__menu'); + + // array-fields has enableRichTextLink set to false + await expect(menu).not.toContainText('Array Fields'); + }); + test('should only list non-upload collections in relationship drawer', async () => { await navigateToRichTextFields();