1
0
mirror of https://github.com/flarum/core.git synced 2025-08-09 18:07:02 +02:00

Implement post editing

This commit is contained in:
Toby Zerner
2015-02-08 15:55:33 +10:30
parent 2d181933ea
commit 59964e3b22
8 changed files with 92 additions and 29 deletions

View File

@@ -32,6 +32,7 @@ class PostSerializer extends PostBasicSerializer
protected function attributes(Post $post)
{
$attributes = parent::attributes($post);
$user = User::current();
unset($attributes['content']);
if ($post->type != 'comment') {
@@ -39,17 +40,19 @@ class PostSerializer extends PostBasicSerializer
} else {
// @todo move to a formatter class
$attributes['contentHtml'] = $post->content_html ?: '<p>'.nl2br(htmlspecialchars(trim($post->content))).'</p>';
if ($post->can($user, 'edit')) {
$attributes['content'] = $post->content;
}
}
if ($post->edit_time) {
$attributes['editTime'] = (string) $post->edit_time;
$attributes['editTime'] = $post->edit_time->toRFC3339String();
}
if ($post->delete_time) {
$attributes['deleteTime'] = (string) $post->delete_time;
$attributes['deleteTime'] = $post->delete_time->toRFC3339String();
}
$user = User::current();
$attributes += [
'canEdit' => $post->can($user, 'edit'),

View File

@@ -14,7 +14,7 @@ class CommentPost extends Post
{
parent::boot();
static::saving(function ($post) {
static::creating(function ($post) {
$post->number = ++$post->discussion->number_index;
$post->discussion->save();
});