Skip to content

Commit 0c7504a

Browse files
committed
Merge branch 'master' of git://github.com/luqmanrom/CRUD into luqmanrom-master
2 parents 1b4bf48 + 71250e7 commit 0c7504a

File tree

1 file changed

+30
-1
lines changed

1 file changed

+30
-1
lines changed

src/app/Library/CrudPanel/Traits/Buttons.php

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,36 @@ trait Buttons
1010
// BUTTONS
1111
// ------------
1212

13-
// TODO: $this->crud->reorderButtons('stack_name', ['one', 'two']);
13+
/**
14+
* Reorder buttons to the CRUD table view.
15+
*
16+
* @param string $stack Stack where the buttons belongs. Options: top, line, bottom.
17+
* @param array $buttons Name of the buttons. ['update', 'delete', 'show']
18+
*/
19+
public function reorderButtons($stack, $buttons)
20+
{
21+
$newBtns = collect([]);
22+
23+
$this->buttons()->each(function ($btn) use ($stack, $newBtns) {
24+
if ($btn->stack != $stack) {
25+
$newBtns->push($btn);
26+
}
27+
});
28+
29+
collect($buttons)->each(function ($btnKey) use ($newBtns) {
30+
$btnInstance = $this->buttons()->filter(function ($btn) use ($btnKey) {
31+
return $btn->name == $btnKey;
32+
})->first();
33+
34+
if (! $btnInstance) {
35+
abort(500, 'Sorry, button cannot be found');
36+
}
37+
38+
$newBtns->push($btnInstance);
39+
});
40+
41+
$this->setOperationSetting('buttons', $newBtns);
42+
}
1443

1544
/**
1645
* Add a button to the CRUD table view.

0 commit comments

Comments
 (0)