generated from filamentphp/plugin-skeleton
-
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathDeletePageBuilderBlockAction.php
More file actions
53 lines (35 loc) · 1.51 KB
/
DeletePageBuilderBlockAction.php
File metadata and controls
53 lines (35 loc) · 1.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
<?php
namespace Redberry\PageBuilderPlugin\Components\Forms\Actions;
use Closure;
use Filament\Forms\Components\Actions\Action;
use Redberry\PageBuilderPlugin\Components\Forms\PageBuilder;
class DeletePageBuilderBlockAction extends Action
{
public static function getDefaultName(): ?string
{
return 'delete-page-builder-block';
}
protected function setUp(): void
{
parent::setUp();
$this->requiresConfirmation();
$this->color('danger');
$this->hiddenLabel();
$this->label(__('filament-actions::delete.single.label'));
$this->modalHeading(function ($arguments, $component) {
$block = $component->getState()[$arguments['index']];
$closure = Closure::fromCallable([$block['block_type'], 'getBlockLabel']);
$label = (string) $this->evaluate($closure);
return __('filament-actions::delete.single.modal.heading', ['label' => $label]);
});
$this->modalSubmitActionLabel(__('filament-actions::delete.single.modal.actions.delete.label'));
$this->successNotificationTitle(__('filament-actions::delete.single.notifications.deleted.title'));
$this->action(function ($arguments, Action $action, PageBuilder $component) {
$items = $component->getState();
unset($items[$arguments['index']]);
$component->state(array_values($items));
$action->sendSuccessNotification();
$component->callAfterStateUpdated();
});
}
}