You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: 7.x-dev/crud-operations.md
+18-13Lines changed: 18 additions & 13 deletions
Original file line number
Diff line number
Diff line change
@@ -226,25 +226,31 @@ Understanding these moments and their order, is important in order to place your
226
226
<aname="lifecycle-hooks"></a>
227
227
### Lifecycle Hooks
228
228
229
-
At important points in the CRUD Lifecycle, Backpack triggers what we call "lifecycle events". You can hook into those events - by registering custom code that will run when that lifecycle event happens. This allows you to customize the process, without having to override any of the core files for CRUD or an Operation.
229
+
At important points in the CRUD Lifecycle, Backpack triggers what we call "_lifecycle events_". You can hook into those events - by registering custom code that will run when that lifecycle event happens. This allows you to customize the process, without having to override any of the core files for that CRUD or Operation.
230
230
231
-
For example, in a Backpack CRUD all routes are setup on the **CrudController** using methods like `setupModerateOperationRoutes()`. Before those methods are called, Backpack calls `LifecycleEvent::trigger('crud:before_all_route_setup')`. If you want to add your own code that runs there, you can do:
231
+
For example, in a Backpack CRUD all routes are setup on the **CrudController** using methods like `setupModerateOperationRoutes()`. Before those methods are called, Backpack triggers an event called `crud:before_all_route_setup`. If you want to add your own code that runs there, you can do:
232
232
233
233
```php
234
+
use Backpack\CRUD\app\Library\CrudPanel\Hooks\Facades\LifecycleHook;
Here are all the general Lifecycle Events we currently have:
240
+
<aname="general-lifecycle-events"></a>
241
+
#### General Lifecycle Events
242
+
243
+
Here are all the general lifecycle events Backpack triggers:
240
244
241
-
`crud:before_setup_routes` - before any operation routes are registered
242
-
`crud:after_setup_routes` - after all operation routes have been registered
243
-
`crud:before_setup_defaults` - before all defaults are setup
244
-
`crud:after_setup_defaults` - after all defaults have been setup
245
-
`crud:before_setup` - before any operation is set up
246
-
`crud:after_setup` - after that operation has been set up
245
+
-`crud:before_setup_routes` - before any operation routes are registered
246
+
-`crud:after_setup_routes` - after all operation routes have been registered
247
+
-`crud:before_setup_defaults` - before all defaults are setup
248
+
-`crud:after_setup_defaults` - after all defaults have been setup
249
+
-`crud:before_setup` - before any operation is set up
250
+
-`crud:after_setup` - after that operation has been set up
247
251
252
+
<aname="operation-lifecycle-events"></a>
253
+
#### Operation Lifecycle Events
248
254
249
255
In addition to the general Lifecycle events above, each operation can trigger its own lifecycle events. For example, here are the lifecycle events triggered by the Create operation:
As a developer you may have had the need to create custom operations, and while creating a "one time use" operation may not require/demand the usage of lifecycle events, creating a reusable operation that you may want to share with the community, or use in multiple projects, may benefit from the usage of lifecycle events to allow other developers to hook into your operation and customize its behavior.
273
-
274
-
You can add your own lifecycle events to your custom operations by calling the `LifecycleEvent::trigger()` method at the appropriate points in your operation. For example, if you have a custom operation that need to do something after some action happen in te operation, you can trigger a lifecycle event like this:
279
+
You can add your own lifecycle events to your custom operations by calling the `LifecycleEvent::trigger()` method at the appropriate points in your operation. For example, if you have a custom operation that need to do something after some action happens in the operation, you can trigger a lifecycle event like this:
Copy file name to clipboardExpand all lines: 7.x-dev/release-notes.md
+1-1Lines changed: 1 addition & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -22,7 +22,7 @@ Together, our team has put in an incredible amount of work to make v7 what it is
22
22
23
23
### CRUD Lifecycle Hooks
24
24
25
-
// TODO
25
+
Previously when working with Operations, developers found themselves needing to _override_ an entire operation method, in order to do things before/after the routes/defaults/operation is set up. This created a lot of duplicate code, and made it hard to maintain. Now, you can use CRUD Lifecycle Hooks to add your own code before/after each operation method. This is a much cleaner way to add your own code, without having to override the entire method. [Read more](/docs/{{version}}/crud-operations#lifecycle-hooks).
0 commit comments