Skip to content

Commit 7b1276a

Browse files
docs: add new Page Builder lifecycle events for Block Categories
1 parent afc0d38 commit 7b1276a

File tree

1 file changed

+144
-1
lines changed

1 file changed

+144
-1
lines changed

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

Lines changed: 144 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ new ContextPlugin<PbContext>(async (context) => {
240240
if (category.name.match(/b/) === null) {
241241
return
242242
}
243-
throw new Error(`You are not allowed to delete a category with charcter "b" in its name.`)
243+
throw new Error(`You are not allowed to delete a category with character "b" in its name.`)
244244
})
245245
})
246246
```
@@ -958,6 +958,149 @@ Please, be aware that you can change what ever you want on the object before it
958958

959959
</Alert>
960960

961+
## Block Categories
962+
963+
### OnBeforeBlockCategoryCreateTopicParams
964+
965+
This event is triggered before new block category is stored into the database.
966+
967+
#### Event arguments
968+
969+
| Property | Description |
970+
| ------------- | ------------------------------------------------- |
971+
| blockCategory | Block Category object which is going to be stored |
972+
973+
#### How to subscribe to this event?
974+
975+
```typescript
976+
new ContextPlugin<PbContext>(async (context) => {
977+
context.pageBuilder.onBeforeBlockCategoryCreate.subscribe(async ({ blockCategory }) => {
978+
/**
979+
* For example, all block category names have to start with "BLOCK:" string an be in UPPERCASE.
980+
* You can check name for that condition and add prefix if it is missing.
981+
*/
982+
blockCategory.name = blockCategory.name.toUpperCase()
983+
if (!blockCategory.name.startsWith("BLOCK:")) {
984+
blockCategory.name = "BLOCK:" + blockCategory.name
985+
}
986+
})
987+
})
988+
```
989+
990+
### OnAfterBlockCategoryCreateTopicParams
991+
992+
This event is triggered after new block category is stored into the database.
993+
994+
#### Event arguments
995+
996+
| Property | Description |
997+
| ------------- | -------------------------------------- |
998+
| blockCategory | Block Category object which was stored |
999+
1000+
#### How to subscribe to this event?
1001+
1002+
```typescript
1003+
new ContextPlugin<PbContext>(async (context) => {
1004+
context.pageBuilder.onAfterBlockCategoryCreate.subscribe(async ({ blockCategory }) => {
1005+
await storeBlockCategoryToAnotherSystem({ blockCategory })
1006+
})
1007+
})
1008+
```
1009+
1010+
### OnBeforeBlockCategoryUpdateTopicParams
1011+
1012+
This event is triggered before existing block category is updated and stored.
1013+
1014+
#### Event arguments
1015+
1016+
| Property | Description |
1017+
| ------------- | ---------------------------------------------------------- |
1018+
| original | Block Category object which was received from the database |
1019+
| blockCategory | Block Category object which is going to be stored |
1020+
1021+
#### How to subscribe to this event?
1022+
1023+
```typescript
1024+
new ContextPlugin<PbContext>(async (context) => {
1025+
context.pageBuilder.onBeforeBlockCategoryUpdate.subscribe(async ({ original, blockCategory }) => {
1026+
/**
1027+
* For example, you do not want to allow block category slug changes.
1028+
*/
1029+
if (original.slug === blockCategory.slug) {
1030+
return
1031+
}
1032+
throw new Error(`You are not allowed to change the block category slug.`)
1033+
})
1034+
})
1035+
```
1036+
1037+
### OnAfterBlockCategoryUpdateTopicParams
1038+
1039+
This event is triggered after existing block category is updated and stored.
1040+
1041+
#### Event arguments
1042+
1043+
| Property | Description |
1044+
| ------------- | ---------------------------------------------------------- |
1045+
| original | Block Category object which was received from the database |
1046+
| blockCategory | Block Category object which is going to be stored |
1047+
1048+
#### How to subscribe to this event?
1049+
1050+
```typescript
1051+
new ContextPlugin<PbContext>(async (context) => {
1052+
context.pageBuilder.onAfterBlockCategoryUpdate.subscribe(async ({ original, blockCategory }) => {
1053+
await storeBlockCategoryToAnotherSystem({ original, blockCategory })
1054+
})
1055+
})
1056+
```
1057+
1058+
### OnBeforeBlockCategoryDeleteTopicParams
1059+
1060+
This event is triggered before block category is deleted from the database.
1061+
1062+
#### Event arguments
1063+
1064+
| Property | Description |
1065+
| ------------- | -------------------------------------------------- |
1066+
| blockCategory | Block Category object which is going to be deleted |
1067+
1068+
#### How to subscribe to this event?
1069+
1070+
```typescript
1071+
new ContextPlugin<PbContext>(async (context) => {
1072+
context.pageBuilder.onBeforeBlockCategoryDelete.subscribe(async ({ original, blockCategory }) => {
1073+
/**
1074+
* For example, we do not want to allow certain category with a name "All Advertisement Blocks" to be deleted.
1075+
*/
1076+
if (blockCategory.name !== "All Advertisement Blocks") {
1077+
return
1078+
}
1079+
throw new Error(`You are not allowed to delete a block category with name "All Advertisement Blocks".`)
1080+
})
1081+
})
1082+
```
1083+
1084+
### OnAfterBlockCategoryDeleteTopicParams
1085+
1086+
This event is triggered after block category is deleted from the database.
1087+
1088+
#### Event arguments
1089+
1090+
| Property | Description |
1091+
| ------------- | --------------------------------------- |
1092+
| blockCategory | Block Category object which was deleted |
1093+
1094+
#### How to subscribe to this event?
1095+
1096+
```typescript
1097+
new ContextPlugin<PbContext>(async (context) => {
1098+
context.pageBuilder.onAfterBlockCategoryDelete.subscribe(async ({ original, blockCategory }) => {
1099+
await deleteBlockCategoryFromAnotherSystem({ original, blockCategory })
1100+
})
1101+
})
1102+
```
1103+
9611104
## Registering Lifecycle Event Subscriptions
9621105

9631106
For the subscriptions (your code) to be run, you must register it in the `createHandler` in the `api/code/graphql/src/index.ts` file.

0 commit comments

Comments
 (0)