Skip to content

Commit 0f5c58d

Browse files
feat: add Page Blocks docs, fix typos in Block Category docs
1 parent 7b1276a commit 0f5c58d

File tree

1 file changed

+157
-15
lines changed

1 file changed

+157
-15
lines changed

src/pages/docs/page-builder/references/lifecycle-events.mdx

Lines changed: 157 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -952,15 +952,9 @@ new ContextPlugin<PbContext>(async (context) => {
952952
})
953953
```
954954

955-
<Alert type="danger">
956-
957-
Please, be aware that you can change what ever you want on the object before it is stored into the database, so be careful with changing the data.
958-
959-
</Alert>
960-
961955
## Block Categories
962956

963-
### OnBeforeBlockCategoryCreateTopicParams
957+
### OnBeforeBlockCategoryCreate
964958

965959
This event is triggered before new block category is stored into the database.
966960

@@ -987,7 +981,7 @@ new ContextPlugin<PbContext>(async (context) => {
987981
})
988982
```
989983

990-
### OnAfterBlockCategoryCreateTopicParams
984+
### OnAfterBlockCategoryCreate
991985

992986
This event is triggered after new block category is stored into the database.
993987

@@ -1007,7 +1001,7 @@ new ContextPlugin<PbContext>(async (context) => {
10071001
})
10081002
```
10091003

1010-
### OnBeforeBlockCategoryUpdateTopicParams
1004+
### OnBeforeBlockCategoryUpdate
10111005

10121006
This event is triggered before existing block category is updated and stored.
10131007

@@ -1034,7 +1028,7 @@ new ContextPlugin<PbContext>(async (context) => {
10341028
})
10351029
```
10361030

1037-
### OnAfterBlockCategoryUpdateTopicParams
1031+
### OnAfterBlockCategoryUpdate
10381032

10391033
This event is triggered after existing block category is updated and stored.
10401034

@@ -1055,7 +1049,7 @@ new ContextPlugin<PbContext>(async (context) => {
10551049
})
10561050
```
10571051

1058-
### OnBeforeBlockCategoryDeleteTopicParams
1052+
### OnBeforeBlockCategoryDelete
10591053

10601054
This event is triggered before block category is deleted from the database.
10611055

@@ -1069,7 +1063,7 @@ This event is triggered before block category is deleted from the database.
10691063

10701064
```typescript
10711065
new ContextPlugin<PbContext>(async (context) => {
1072-
context.pageBuilder.onBeforeBlockCategoryDelete.subscribe(async ({ original, blockCategory }) => {
1066+
context.pageBuilder.onBeforeBlockCategoryDelete.subscribe(async ({ blockCategory }) => {
10731067
/**
10741068
* For example, we do not want to allow certain category with a name "All Advertisement Blocks" to be deleted.
10751069
*/
@@ -1081,7 +1075,7 @@ new ContextPlugin<PbContext>(async (context) => {
10811075
})
10821076
```
10831077

1084-
### OnAfterBlockCategoryDeleteTopicParams
1078+
### OnAfterBlockCategoryDelete
10851079

10861080
This event is triggered after block category is deleted from the database.
10871081

@@ -1095,14 +1089,162 @@ This event is triggered after block category is deleted from the database.
10951089

10961090
```typescript
10971091
new ContextPlugin<PbContext>(async (context) => {
1098-
context.pageBuilder.onAfterBlockCategoryDelete.subscribe(async ({ original, blockCategory }) => {
1099-
await deleteBlockCategoryFromAnotherSystem({ original, blockCategory })
1092+
context.pageBuilder.onAfterBlockCategoryDelete.subscribe(async ({ blockCategory }) => {
1093+
await deleteBlockCategoryFromAnotherSystem({ blockCategory })
1094+
})
1095+
})
1096+
```
1097+
1098+
## Page Blocks
1099+
1100+
### onBeforePageBlockCreate
1101+
1102+
This event is triggered before new page block is stored into the database.
1103+
1104+
#### Event arguments
1105+
1106+
| Property | Description |
1107+
| --------- | ---------------------------------------------- |
1108+
| pageBlock | Page Block object which is going to be stored |
1109+
1110+
#### How to subscribe to this event?
1111+
1112+
```typescript
1113+
new ContextPlugin<PbContext>(async (context) => {
1114+
context.pageBuilder.onBeforePageBlockCreate.subscribe(async ({ pageBlock }) => {
1115+
/**
1116+
* For example, all page block names have to be in UPPERCASE.
1117+
* You can check name and convert it if needed.
1118+
*/
1119+
if (pageBlock.name !== pageBlock.name.toUpperCase()) {
1120+
pageBlock.name = pageBlock.name.toUpperCase()
1121+
}
1122+
})
1123+
})
1124+
```
1125+
1126+
### onAfterPageBlockCreate
1127+
1128+
This event is triggered after new page block is stored into the database.
1129+
1130+
#### Event arguments
1131+
1132+
| Property | Description |
1133+
| --------- | ------------------------------------------- |
1134+
| pageBlock | Page Block object which was stored |
1135+
1136+
#### How to subscribe to this event?
1137+
1138+
```typescript
1139+
new ContextPlugin<PbContext>(async (context) => {
1140+
context.pageBuilder.onAfterPageBlockCreate.subscribe(async ({ pageBlock }) => {
1141+
await storePageBlockToAnotherSystem({ pageBlock })
1142+
})
1143+
})
1144+
```
1145+
1146+
### onBeforePageBlockUpdate
1147+
1148+
This event is triggered before existing page block is updated and stored.
1149+
1150+
#### Event arguments
1151+
1152+
| Property | Description |
1153+
| --------- | ------------------------------------------------------ |
1154+
| original | Page Block object which was received from the database |
1155+
| pageBlock | Page Block object which is going to be stored |
1156+
1157+
#### How to subscribe to this event?
1158+
1159+
```typescript
1160+
new ContextPlugin<PbContext>(async (context) => {
1161+
context.pageBuilder.onBeforePageBlockUpdate.subscribe(async ({ original, pageBlock }) => {
1162+
/**
1163+
* For example, you do not want to allow block category changes.
1164+
*/
1165+
if (original.blockCategory === pageBlock.blockCategory) {
1166+
return
1167+
}
1168+
throw new Error(`You are not allowed to change the page block category.`)
1169+
})
1170+
})
1171+
```
1172+
1173+
### onAfterPageBlockUpdate
1174+
1175+
This event is triggered after existing page block is updated and stored.
1176+
1177+
#### Event arguments
1178+
1179+
| Property | Description |
1180+
| --------- | ------------------------------------------------------ |
1181+
| original | Page Block object which was received from the database |
1182+
| pageBlock | Page Block object which is going to be stored |
1183+
1184+
#### How to subscribe to this event?
1185+
1186+
```typescript
1187+
new ContextPlugin<PbContext>(async (context) => {
1188+
context.pageBuilder.onAfterPageBlockUpdate.subscribe(async ({ original, pageBlock }) => {
1189+
await storePageBlockToAnotherSystem({ original, pageBlock })
1190+
})
1191+
})
1192+
```
1193+
1194+
### onBeforePageBlockDelete
1195+
1196+
This event is triggered before page block is deleted from the database.
1197+
1198+
#### Event arguments
1199+
1200+
| Property | Description |
1201+
| --------- | ---------------------------------------------- |
1202+
| pageBlock | Page Block object which is going to be deleted |
1203+
1204+
#### How to subscribe to this event?
1205+
1206+
```typescript
1207+
new ContextPlugin<PbContext>(async (context) => {
1208+
context.pageBuilder.onBeforePageBlockDelete.subscribe(async ({ pageBlock }) => {
1209+
/**
1210+
* For example, we do not want to allow certain block with a name "Heading" to be deleted.
1211+
*/
1212+
if (pageBlock.name !== "Heading") {
1213+
return
1214+
}
1215+
throw new Error(`You are not allowed to delete a page block with name "Heading".`)
1216+
})
1217+
})
1218+
```
1219+
1220+
### onAfterPageBlockDelete
1221+
1222+
This event is triggered after page block is deleted from the database.
1223+
1224+
#### Event arguments
1225+
1226+
| Property | Description |
1227+
| --------- | ----------------------------------- |
1228+
| pageBlock | Page Block object which was deleted |
1229+
1230+
#### How to subscribe to this event?
1231+
1232+
```typescript
1233+
new ContextPlugin<PbContext>(async (context) => {
1234+
context.pageBuilder.onAfterPageBlockDelete.subscribe(async ({ pageBlock }) => {
1235+
await deletePageBlockFromAnotherSystem({ pageBlock })
11001236
})
11011237
})
11021238
```
11031239

11041240
## Registering Lifecycle Event Subscriptions
11051241

1242+
<Alert type="danger">
1243+
1244+
Please, be aware that you can change what ever you want on the object before it is stored into the database, so be careful with changing the data.
1245+
1246+
</Alert>
1247+
11061248
For the subscriptions (your code) to be run, you must register it in the `createHandler` in the `api/code/graphql/src/index.ts` file.
11071249

11081250
```typescript api/code/graphql/src/index.ts

0 commit comments

Comments
 (0)