49 lines
1.3 KiB
PHP
49 lines
1.3 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Filament\Resources\BaselineProfileResource\Pages;
|
|
|
|
use App\Filament\Resources\BaselineProfileResource;
|
|
use App\Models\BaselineProfile;
|
|
use App\Support\Audit\AuditActionId;
|
|
use Filament\Notifications\Notification;
|
|
use Filament\Resources\Pages\EditRecord;
|
|
|
|
class EditBaselineProfile extends EditRecord
|
|
{
|
|
protected static string $resource = BaselineProfileResource::class;
|
|
|
|
/**
|
|
* @param array<string, mixed> $data
|
|
* @return array<string, mixed>
|
|
*/
|
|
protected function mutateFormDataBeforeSave(array $data): array
|
|
{
|
|
$policyTypes = $data['scope_jsonb']['policy_types'] ?? [];
|
|
$data['scope_jsonb'] = ['policy_types' => is_array($policyTypes) ? array_values($policyTypes) : []];
|
|
|
|
return $data;
|
|
}
|
|
|
|
protected function afterSave(): void
|
|
{
|
|
$record = $this->record;
|
|
|
|
if (! $record instanceof BaselineProfile) {
|
|
return;
|
|
}
|
|
|
|
BaselineProfileResource::audit($record, AuditActionId::BaselineProfileUpdated, [
|
|
'baseline_profile_id' => (int) $record->getKey(),
|
|
'name' => (string) $record->name,
|
|
'status' => (string) $record->status,
|
|
]);
|
|
|
|
Notification::make()
|
|
->title('Baseline profile updated')
|
|
->success()
|
|
->send();
|
|
}
|
|
}
|