33namespace Backpack \CRUD \app \Http \Controllers ;
44
55use Backpack \CRUD \app \Library \Attributes \DeprecatedIgnoreOnRuntime ;
6+ use Backpack \CRUD \app \Library \CrudPanel \Hooks \Facades \LifecycleHook ;
67use Illuminate \Foundation \Bus \DispatchesJobs ;
78use Illuminate \Foundation \Validation \ValidatesRequests ;
89use Illuminate \Routing \Controller ;
@@ -19,6 +20,7 @@ class CrudController extends Controller
1920 use DispatchesJobs, ValidatesRequests;
2021
2122 public $ crud ;
23+
2224 public $ data = [];
2325
2426 public function __construct ()
@@ -40,8 +42,14 @@ public function __construct()
4042
4143 $ this ->crud ->setRequest ($ request );
4244
45+ LifecycleHook::trigger ('crud:before_setup_defaults ' , [$ this ]);
4346 $ this ->setupDefaults ();
47+ LifecycleHook::trigger ('crud:after_setup_defaults ' , [$ this ]);
48+
49+ LifecycleHook::trigger ('crud:before_setup ' , [$ this ]);
4450 $ this ->setup ();
51+ LifecycleHook::trigger ('crud:after_setup ' , [$ this ]);
52+
4553 $ this ->setupConfigurationForCurrentOperation ();
4654
4755 return $ next ($ request );
@@ -109,13 +117,15 @@ protected function setupConfigurationForCurrentOperation()
109117 /*
110118 * FIRST, run all Operation Closures for this operation.
111119 *
112- * It's preferred for this to closures first, because
120+ * It's preferred for this to run closures first, because
113121 * (1) setup() is usually higher in a controller than any other method, so it's more intuitive,
114122 * since the first thing you write is the first thing that is being run;
115123 * (2) operations use operation closures themselves, inside their setupXxxDefaults(), and
116124 * you'd like the defaults to be applied before anything you write. That way, anything you
117125 * write is done after the default, so you can remove default settings, etc;
118126 */
127+ LifecycleHook::trigger ($ operationName .':before_setup ' , [$ this ]);
128+
119129 $ this ->crud ->applyConfigurationFromSettings ($ operationName );
120130
121131 /*
@@ -124,5 +134,7 @@ protected function setupConfigurationForCurrentOperation()
124134 if (method_exists ($ this , $ setupClassName )) {
125135 $ this ->{$ setupClassName }();
126136 }
137+
138+ LifecycleHook::trigger ($ operationName .':after_setup ' , [$ this ]);
127139 }
128140}
0 commit comments