@@ -952,15 +952,9 @@ new ContextPlugin<PbContext>(async (context) => {
952
952
})
953
953
```
954
954
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
-
961
955
## Block Categories
962
956
963
- ### OnBeforeBlockCategoryCreateTopicParams
957
+ ### OnBeforeBlockCategoryCreate
964
958
965
959
This event is triggered before new block category is stored into the database.
966
960
@@ -987,7 +981,7 @@ new ContextPlugin<PbContext>(async (context) => {
987
981
})
988
982
```
989
983
990
- ### OnAfterBlockCategoryCreateTopicParams
984
+ ### OnAfterBlockCategoryCreate
991
985
992
986
This event is triggered after new block category is stored into the database.
993
987
@@ -1007,7 +1001,7 @@ new ContextPlugin<PbContext>(async (context) => {
1007
1001
})
1008
1002
```
1009
1003
1010
- ### OnBeforeBlockCategoryUpdateTopicParams
1004
+ ### OnBeforeBlockCategoryUpdate
1011
1005
1012
1006
This event is triggered before existing block category is updated and stored.
1013
1007
@@ -1034,7 +1028,7 @@ new ContextPlugin<PbContext>(async (context) => {
1034
1028
})
1035
1029
```
1036
1030
1037
- ### OnAfterBlockCategoryUpdateTopicParams
1031
+ ### OnAfterBlockCategoryUpdate
1038
1032
1039
1033
This event is triggered after existing block category is updated and stored.
1040
1034
@@ -1055,7 +1049,7 @@ new ContextPlugin<PbContext>(async (context) => {
1055
1049
})
1056
1050
```
1057
1051
1058
- ### OnBeforeBlockCategoryDeleteTopicParams
1052
+ ### OnBeforeBlockCategoryDelete
1059
1053
1060
1054
This event is triggered before block category is deleted from the database.
1061
1055
@@ -1069,7 +1063,7 @@ This event is triggered before block category is deleted from the database.
1069
1063
1070
1064
``` typescript
1071
1065
new ContextPlugin <PbContext >(async (context ) => {
1072
- context .pageBuilder .onBeforeBlockCategoryDelete .subscribe (async ({ original , blockCategory }) => {
1066
+ context .pageBuilder .onBeforeBlockCategoryDelete .subscribe (async ({ blockCategory }) => {
1073
1067
/**
1074
1068
* For example, we do not want to allow certain category with a name "All Advertisement Blocks" to be deleted.
1075
1069
*/
@@ -1081,7 +1075,7 @@ new ContextPlugin<PbContext>(async (context) => {
1081
1075
})
1082
1076
```
1083
1077
1084
- ### OnAfterBlockCategoryDeleteTopicParams
1078
+ ### OnAfterBlockCategoryDelete
1085
1079
1086
1080
This event is triggered after block category is deleted from the database.
1087
1081
@@ -1095,14 +1089,162 @@ This event is triggered after block category is deleted from the database.
1095
1089
1096
1090
``` typescript
1097
1091
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 })
1100
1236
})
1101
1237
})
1102
1238
```
1103
1239
1104
1240
## Registering Lifecycle Event Subscriptions
1105
1241
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
+
1106
1248
For the subscriptions (your code) to be run, you must register it in the ` createHandler ` in the ` api/code/graphql/src/index.ts ` file.
1107
1249
1108
1250
``` typescript api/code/graphql/src/index.ts
0 commit comments