Files
payload/test/fields/collections/Blocks/shared.ts
Alessio Gravili e6fea1d132 fix: localized fields within block references were not handled properly if any parent is localized (#11207)
The `localized` properly was not stripped out of referenced block fields, if any parent was localized. For normal fields, this is done in sanitizeConfig. As the same referenced block config can be used in both a localized and non-localized config, we are not able to strip it out inside sanitizeConfig by modifying the block config.

Instead, this PR had to bring back tedious logic to handle it everywhere the `field.localized` property is accessed. For backwards-compatibility, we need to keep the existing sanitizeConfig logic. In 4.0, we should remove it to benefit from better test coverage of runtime field.localized handling - for now, this is done for our test suite using the `PAYLOAD_DO_NOT_SANITIZE_LOCALIZED_PROPERTY` flag.
2025-02-17 19:50:32 +00:00

63 lines
1.3 KiB
TypeScript

import type { BlockField } from '../../payload-types.js'
export const getBlocksFieldSeedData = (prefix?: string): any => [
{
blockName: 'First block',
blockType: prefix ? `${prefix}Content` : 'content',
text: 'first block',
richText: [
{
children: [{ text: '' }],
},
],
},
{
blockName: 'Second block',
blockType: prefix ? `${prefix}Number` : 'number',
number: 342,
},
{
blockName: 'Sub-block demonstration',
blockType: prefix ? `${prefix}SubBlocks` : 'subBlocks',
subBlocks: [
{
blockName: 'First sub block',
blockType: 'number',
number: 123,
},
{
blockName: 'Second sub block',
blockType: 'textRequired',
text: 'second sub block',
},
],
},
]
export const blocksDoc: Partial<BlockField> = {
blocks: getBlocksFieldSeedData(),
localizedBlocks: getBlocksFieldSeedData('localized'),
blocksWithMinRows: [
{
blockTitle: 'first row',
blockType: 'blockWithMinRows',
},
{
blockTitle: 'second row',
blockType: 'blockWithMinRows',
},
],
localizedReferencesLocalizedBlock: [
{
blockType: 'localizedTextReference',
text: 'localized text',
},
],
localizedReferences: [
{
blockType: 'localizedTextReference2',
text: 'localized text',
},
],
}