designtopack/public/site/plugins/comments/routes/delete.php
2024-10-29 11:12:57 +01:00

25 lines
No EOL
588 B
PHP

<?php
return [
'pattern' => '(:all)delete-comment.json',
'method' => 'POST',
'action' => function () {
$json = file_get_contents('php://input');
$data = json_decode($json);
$page = page($data->pageUri);
$file = $page->file($data->fileName);
$user = kirby()->user($data->userUuid);
$comments = $file->comments()->isEmpty() == true ? [] : Yaml::decode($file->comments()->value());
unset($comments[$data->id] );
$newFile = $file->update([
'comments' => $comments
]);
return getFileData($newFile);
}
];