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/base-components.md
+31Lines changed: 31 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -100,6 +100,8 @@ This component helps you show a form _anywhere you want_, so the admin can easil
100
100
-`operation='create'` - by default, the datatable component will pick up everything that controller sets up for the Create operation; if you want to change the operation it will initialize, you can pass this parameter;
101
101
-`:entry="\App\Models\Invoice::find(1)"` - if you want to use UpdateOperation or a custom form operation that needs the entry;
102
102
-`:setup="function($crud, $parent) {}"` - if you want to make changes to the operation setup (eg. add/remove fields, configure functionality), you can use this parameter; the closure passed here will be run _after_ the setup of that operation had already completed;
103
+
-`:save-actions="[]"` - provide an array of save action definitions or save action classes to replace the defaults (see [Custom save actions](#dataform-custom-save-actions));
104
+
-`:form-inside-card="true"` - render the form inside a Backpack card wrapper so it visually matches the default create/update screens; leave it `false` to output only the raw form markup.
103
105
104
106
**Advanced example:**
105
107
@@ -115,6 +117,33 @@ This component helps you show a form _anywhere you want_, so the admin can easil
115
117
/>
116
118
```
117
119
120
+
<aname="dataform-custom-save-actions"></a>
121
+
#### Custom save actions
122
+
123
+
The Dataform component can swap out the default `Save and back / edit / new` buttons with your own logic. Pass an array to the `:save-actions` attribute containing save action classes (or definitions) that implement Backpack's `SaveActionInterface`:
124
+
125
+
```php
126
+
@php
127
+
use App\Backpack\Crud\SaveActions\SaveAndApprove;
128
+
use Backpack\CRUD\app\Library\CrudPanel\SaveActions\SaveAndBack;
- an instance of a class that implements `SaveActionInterface` (recommended);
142
+
- the fully qualified class name of a save action (the container will resolve it);
143
+
- a plain array definition (see [`crud-save-actions.md`](crud-save-actions.md)).
144
+
145
+
Backpack will replace the default actions for that form, honour the order defined by each class, and fallback to the first action if no default applies.
146
+
118
147
<hr>
119
148
120
149
<aname="dataform-modal"></a>
@@ -140,6 +169,7 @@ use \Backpack\DataformModal\Http\Controllers\Operations\CreateInModalOperation;
140
169
-`operation='createInModal'` - by default, the component will pick up everything that controller sets up for the Create operation; if you want to change the operation it will initialize, you can pass this parameter, eg: `updateInModal`
141
170
-`:entry="\App\Models\Invoice::find(1)"` - if you want to use UpdateInModalOperation or a custom form operation that needs the entry;
142
171
-`:setup="function($crud, $parent) {}"` - if you want to make changes to the operation setup (eg. add/remove fields, configure functionality), you can use this parameter; the closure passed here will be run _after_ the setup of that operation had already completed;
172
+
-`:save-actions="[]"` - replace the default modal buttons with your own save action classes.
143
173
144
174
**Advanced example:**
145
175
@@ -172,6 +202,7 @@ Useful if you want to show the entries in the database, for an Eloquent model. T
172
202
**Configuration options:**
173
203
-`name='invoices_datatable'` - by default, a name will be generated; but you can pick one you can recognize;
174
204
-`operation='list'` - by default, the datatable component will pick up everything that controller sets up for the List operation; if you want to change the operation it will initialize, you can pass this parameter;
205
+
-`:useFixedHeader="false"` - set this to explicitly enable or disable the sticky header; it defaults to the operation's `useFixedHeader` setting, falling back to `true`;
175
206
-`:setup="function($crud, $parent) {}"` - if you want to make changes to the operation setup (eg. add/remove columns, configure functionality), you can use this parameter; the closure passed here will be run _after_ the setup of that operation had already completed;
Copy file name to clipboardExpand all lines: 7.x-dev/crud-save-actions.md
+85Lines changed: 85 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -16,6 +16,91 @@ There are four save actions registered by Backpack by default. They are:
16
16
-```save_and_new``` (Save and go to create new entity page)
17
17
-```save_and_preview``` (Save and go to show the current entity)
18
18
19
+
<aname="save-action-classes"></a>
20
+
## Save Action Classes
21
+
22
+
Save actions are now first-class citizens. Instead of maintaining large array definitions in each CrudController, you can encapsulate the behaviour inside PHP classes that implement `Backpack\CRUD\app\Library\CrudPanel\SaveActions\SaveActionInterface`. Backpack ships with `SaveAndBack`, `SaveAndEdit`, `SaveAndNew`, and `SaveAndPreview` as examples, and also provides `SaveAndList` for projects that want an explicit "Save and go to list" button.
23
+
24
+
### Quick start
25
+
26
+
1.**Create a class** inside your application (for example `app/Backpack/Crud/SaveActions/SaveAndApprove.php`).
27
+
2.**Extend**`AbstractSaveAction` (recommended) or implement `SaveActionInterface` directly.
28
+
3.**Override** the methods that describe your button.
29
+
4.**Register** the class with `CRUD::addSaveAction()` / `CRUD::replaceSaveActions()` or pass it to Blade components like `<x-bp-dataform>`.
30
+
31
+
```php
32
+
<?php
33
+
34
+
namespace App\Backpack\Crud\SaveActions;
35
+
36
+
use Backpack\CRUD\app\Library\CrudPanel\CrudPanel;
37
+
use Backpack\CRUD\app\Library\CrudPanel\SaveActions\AbstractSaveAction;
> **Tip:**`AbstractSaveAction` already implements `toArray()`, order handling, and sensible defaults. Override only what you need. If you must store additional data, you can still return a custom array by implementing `SaveActionInterface` yourself.
67
+
68
+
### Registering class-based actions
69
+
70
+
Inside your CrudController you can now pass the class instead of an array:
Backpack recognizes three inputs when registering save actions:
82
+
- an instantiated save action class;
83
+
- the fully qualified class name (it is resolved via the container so dependencies can be injected);
84
+
- the legacy associative array definition (still supported).
85
+
86
+
The action `order` is taken from the class (or array) and Backpack reorders conflicts automatically. If you need to adjust the order later you can still call `CRUD::orderSaveActions()`.
87
+
88
+
### Using classes in Blade components
89
+
90
+
The `bp-dataform` component accept save action classes through the `:save-actions` attribute. This allows you to reuse the same custom buttons outside CrudControllers:
0 commit comments