1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Backpack\CRUD\app\Http\Controllers\CrudFeatures; |
4
|
|
|
|
5
|
|
|
//save_and_back save_and_edit save_and_new |
6
|
|
|
trait SaveActions |
7
|
|
|
{ |
8
|
|
|
/** |
9
|
|
|
* Get the save configured save action or the one stored in a session variable. |
10
|
|
|
* @return [type] [description] |
|
|
|
|
11
|
|
|
*/ |
12
|
|
|
public function getSaveAction() |
13
|
|
|
{ |
14
|
|
|
$saveAction = session('save_action', config('backback.crud.default_save_action', 'save_and_back')); |
15
|
|
|
$saveOptions = []; |
16
|
|
|
$saveCurrent = [ |
17
|
|
|
'value' => $saveAction, |
18
|
|
|
'label' => $this->getSaveActionButtonName($saveAction), |
19
|
|
|
]; |
20
|
|
|
|
21
|
|
|
switch ($saveAction) { |
22
|
|
View Code Duplication |
case 'save_and_edit': |
|
|
|
|
23
|
|
|
$saveOptions['save_and_back'] = $this->getSaveActionButtonName('save_and_back'); |
24
|
|
|
$saveOptions['save_and_new'] = $this->getSaveActionButtonName('save_and_new'); |
25
|
|
|
break; |
26
|
|
View Code Duplication |
case 'save_and_new': |
|
|
|
|
27
|
|
|
$saveOptions['save_and_back'] = $this->getSaveActionButtonName('save_and_back'); |
28
|
|
|
$saveOptions['save_and_edit'] = $this->getSaveActionButtonName('save_and_edit'); |
29
|
|
|
break; |
30
|
|
|
case 'save_and_black': |
31
|
|
View Code Duplication |
default: |
|
|
|
|
32
|
|
|
$saveOptions['save_and_edit'] = $this->getSaveActionButtonName('save_and_edit'); |
33
|
|
|
$saveOptions['save_and_new'] = $this->getSaveActionButtonName('save_and_new'); |
34
|
|
|
break; |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
return [ |
38
|
|
|
'active' => $saveCurrent, |
39
|
|
|
'options' => $saveOptions, |
40
|
|
|
]; |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* Change the session variable that remembers what to do after the "Save" action. |
45
|
|
|
* @param [type] $forceSaveAction [description] |
|
|
|
|
46
|
|
|
*/ |
47
|
|
|
public function setSaveAction($forceSaveAction = null) |
48
|
|
|
{ |
49
|
|
|
if ($forceSaveAction) { |
50
|
|
|
$saveAction = $forceSaveAction; |
51
|
|
|
} else { |
52
|
|
|
$saveAction = \Request::input('save_action', config('backback.crud.default_save_action', 'save_and_back')); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
if (session('save_action', 'save_and_back') !== $saveAction) { |
56
|
|
|
\Alert::info(trans('backpack::crud.save_action_changed_notification'))->flash(); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
session(['save_action' => $saveAction]); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* Redirect to the correct URL, depending on which save action has been selected. |
64
|
|
|
* @param [type] $itemId [description] |
|
|
|
|
65
|
|
|
* @return [type] [description] |
|
|
|
|
66
|
|
|
*/ |
67
|
|
|
public function performSaveAction($itemId = null) |
68
|
|
|
{ |
69
|
|
|
$saveAction = \Request::input('save_action', config('backback.crud.default_save_action', 'save_and_back')); |
70
|
|
|
$itemId = $itemId ? $itemId : \Request::input('id'); |
71
|
|
|
|
72
|
|
|
switch ($saveAction) { |
73
|
|
|
case 'save_and_new': |
74
|
|
|
$redirectUrl = $this->crud->route.'/create'; |
|
|
|
|
75
|
|
|
break; |
76
|
|
|
case 'save_and_edit': |
77
|
|
|
$redirectUrl = $this->crud->route.'/'.$itemId.'/edit'; |
78
|
|
|
if (\Request::has('locale')) { |
79
|
|
|
$redirectUrl .= '?locale='.\Request::input('locale'); |
80
|
|
|
} |
81
|
|
|
break; |
82
|
|
|
case 'save_and_back': |
83
|
|
|
default: |
84
|
|
|
$redirectUrl = $this->crud->route; |
85
|
|
|
break; |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
return \Redirect::to($redirectUrl); |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
/** |
92
|
|
|
* Get the translated text for the Save button. |
93
|
|
|
* @param string $actionValue [description] |
94
|
|
|
* @return [type] [description] |
|
|
|
|
95
|
|
|
*/ |
96
|
|
|
private function getSaveActionButtonName($actionValue = 'save_and_black') |
97
|
|
|
{ |
98
|
|
|
switch ($actionValue) { |
99
|
|
|
case 'save_and_edit': |
100
|
|
|
return trans('backpack::crud.save_action_save_and_edit'); |
101
|
|
|
break; |
|
|
|
|
102
|
|
|
case 'save_and_new': |
103
|
|
|
return trans('backpack::crud.save_action_save_and_new'); |
104
|
|
|
break; |
|
|
|
|
105
|
|
|
case 'save_and_back': |
106
|
|
|
default: |
107
|
|
|
return trans('backpack::crud.save_action_save_and_back'); |
108
|
|
|
break; |
|
|
|
|
109
|
|
|
} |
110
|
|
|
} |
111
|
|
|
} |
112
|
|
|
|
This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.