Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 12 additions & 10 deletions 7.x/crud-save-actions.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,25 @@
<a name="about"></a>
## About

`Create` and `Update` forms end in a Save button with a drop menu. Every option in that dropdown is a SaveAction - they determine where the user is redirected after the saving is complete.
`Create` and `Update` forms end in a Save button with a drop menu. Every option in that dropdown is a save action - they determine where the user is redirected after the saving is complete.

<a name="defaults"></a>
## Default Save Actions

There are four save actions registered by Backpack by default. They are:
- ```save_and_back``` (Save your entity and go back to previous URL)
- ```save_and_edit``` (Save and edit the current entry)
- ```save_and_new``` (Save and go to create new entity page)
- ```save_and_preview``` (Save and go to show the current entity)
- `save_and_back` (Save your entity and go back to previous URL)
- `save_and_edit` (Save and edit the current entry)
- `save_and_new` (Save and go to create new entity page)
- `save_and_preview` (Save and go to show the current entity)

> **Note:** The `save_and_preview` action is only visible if the `show` operation is enabled for the entity.

<a name="save-action-classes"></a>
## Save Action Classes

You can define save actions either as simple arrays (inside the API methods) or as classes (starting with Backpack v7). Creating classes for your save actions has multiple benefits:
- any call will only occupy one line in your CrudController (instead of 10);
- you can easily re-use that saveaction in other CrudControllers;
- you can easily re-use that save action in other CrudControllers;

Backpack ships with a few save action classes itself:
- `SaveAndBack`, `SaveAndEdit`, `SaveAndNew` and `SaveAndPreview` are the default;
Expand Down Expand Up @@ -117,9 +119,9 @@ When no save actions are provided, Backpack falls back to the defaults registere

Inside your CrudController, inside your ```setupCreateOperation()``` or ```setupUpdateOperation()``` methods, you can change what save buttons are shown for each operation by using the methods below:

#### addSaveAction(array $saveAction)
#### addSaveAction($saveAction)

Adds a new SaveAction to the "Save" button/dropdown.
Adds a new save action to the "Save" button/dropdown.

```php
// using save action classes
Expand Down Expand Up @@ -182,7 +184,7 @@ CRUD::addSaveActions([
This allows you to replace the current save actions with the ones provided in an array.

```php
CRUD::replaceSaveActions(
CRUD::replaceSaveActions([
[
'name' => 'save_action_one',
'visible' => function($crud) {
Expand All @@ -192,7 +194,7 @@ CRUD::replaceSaveActions(
return $crud->route;
},
],
);
]);
```


Expand Down