@@ -762,7 +762,7 @@ admin: {
762762
763763### onInit Pattern
764764
765- Always call existing ` onInit ` before your initialization. See [ onInit Hook] ( #onit -hook ) pattern for full example.
765+ Always call existing ` onInit ` before your initialization. See [ onInit Hook] ( #oninit -hook ) pattern for full example.
766766
767767## Advanced Patterns
768768
@@ -1242,71 +1242,8 @@ collection.endpoints = [
12421242]
12431243```
12441244
1245- #### Error Boundary Customization
1246-
1247- Add custom error handling to admin UI:
1248-
1249- ``` ts
1250- // From plugin-sentry
1251- config .admin = {
1252- ... config .admin ,
1253- components: {
1254- ... config .admin ?.components ,
1255- errorBoundary: ' /components/SentryErrorBoundary#SentryErrorBoundary' ,
1256- },
1257- }
1258- ```
1259-
12601245### Field & Collection Modifications
12611246
1262- #### Deep Merge Pattern
1263-
1264- Recursively merge plugin fields with existing fields:
1265-
1266- ``` ts
1267- // From plugin-seo
1268- import { deepMerge } from ' payload'
1269-
1270- function addFieldsToCollection(
1271- collection : CollectionConfig ,
1272- fieldsToAdd : Field [],
1273- ): CollectionConfig {
1274- return {
1275- ... collection ,
1276- fields: deepMerge (collection .fields , fieldsToAdd ),
1277- }
1278- }
1279- ```
1280-
1281- #### Field Recursion for Nested Structures
1282-
1283- Process fields recursively to handle blocks, arrays, groups:
1284-
1285- ``` ts
1286- // From plugin-cloud-storage
1287- function traverseFields(fields : Field [], callback : (field : Field ) => Field ): Field [] {
1288- return fields .map ((field ) => {
1289- const modified = callback (field )
1290-
1291- if (' fields' in modified && Array .isArray (modified .fields )) {
1292- return { ... modified , fields: traverseFields (modified .fields , callback ) }
1293- }
1294-
1295- if (modified .type === ' blocks' && modified .blocks ) {
1296- return {
1297- ... modified ,
1298- blocks: modified .blocks .map ((block ) => ({
1299- ... block ,
1300- fields: traverseFields (block .fields , callback ),
1301- })),
1302- }
1303- }
1304-
1305- return modified
1306- })
1307- }
1308- ```
1309-
13101247#### Admin Folders Override
13111248
13121249Control admin UI organization:
@@ -1321,73 +1258,6 @@ collection.admin = {
13211258}
13221259```
13231260
1324- ### Upload & Storage
1325-
1326- #### Upload Collection Modification
1327-
1328- Modify upload collections for custom storage:
1329-
1330- ``` ts
1331- // From plugin-cloud-storage
1332- config .collections = (config .collections || []).map ((collection ) => {
1333- if (! collection .upload ) return collection
1334-
1335- return {
1336- ... collection ,
1337- upload: {
1338- ... collection .upload ,
1339- handlers: [
1340- ... (collection .upload .handlers || []),
1341- async ({ file , req }) => {
1342- // Upload to cloud storage
1343- const url = await cloudStorage .upload (file )
1344- return { ... file , url }
1345- },
1346- ],
1347- },
1348- }
1349- })
1350- ```
1351-
1352- #### Adapter Pattern for Pluggable Backends
1353-
1354- Abstract storage implementation:
1355-
1356- ``` ts
1357- // From plugin-cloud-storage
1358- interface StorageAdapter {
1359- handleUpload: (args : { file: File ; req: PayloadRequest }) => Promise <File >
1360- handleDelete: (args : { doc: any ; req: PayloadRequest }) => Promise <void >
1361- generateURL: (args : { filename: string }) => string
1362- }
1363-
1364- export const cloudStoragePlugin =
1365- (adapter : StorageAdapter ) =>
1366- (config : Config ): Config => ({
1367- ... config ,
1368- collections: config .collections ?.map ((collection ) =>
1369- collection .upload
1370- ? {
1371- ... collection ,
1372- hooks: {
1373- ... collection .hooks ,
1374- beforeChange: [
1375- ... (collection .hooks ?.beforeChange || []),
1376- async ({ req , data }) => {
1377- if (req .file ) {
1378- const uploaded = await adapter .handleUpload ({ file: req .file , req })
1379- data .url = adapter .generateURL ({ filename: uploaded .filename })
1380- }
1381- return data
1382- },
1383- ],
1384- },
1385- }
1386- : collection ,
1387- ),
1388- })
1389- ```
1390-
13911261### Background Jobs & Async Operations
13921262
13931263#### Jobs Registration
0 commit comments