'(:all)reply-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()); $newComment = [ 'page' => [ 'uri' => (string) $page->parent()->uri(), 'title' => (string) $page->parent()->title(), ], 'file' => [ 'uuid' => (string) $file->uuid(), 'pageIndex' => $data->filePageIndex, ], 'text' => $data->text, 'user' => [ 'name' => (string) $user->name(), 'email' => (string) $user->email(), 'uuid' => (string) $user->uuid(), 'role' => (string) $user->role() ], 'date' => (string) $data->date, 'id' => $data->id, 'type' => 'comment' ]; $comments[$data->parentId]['replies'][$data->id] = $newComment; $newFile = $file->update([ 'comments' => $comments ]); $user->sendNotification('comments', $newComment); return getFileData($newFile); } ];