'(:all)create-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()); $data = [ 'page' => $page, 'file' => $file, 'position' => [ 'pageIndex' => $data->position->pageIndex, 'x' => $data->position->x, 'y' => $data->position->y ], 'replies' => [], 'text' => $data->text, 'author' => $user, 'date' => (string) $data->date, 'id' => $data->id, 'type' => 'comment' ]; $newComment = new Comment($data); $comments[] = $newComment->toArray(); $newFile = $file->update([ 'comments' => $comments ]); echo json_encode(getFileData($newFile)); try { $user->sendNotification($page->parent()->uri(), $newComment->toArray()); } catch (\Throwable $th) { throw new Exception($th->getMessage(), 1); } exit; } ];