mirror of
https://github.com/flarum/framework.git
synced 2024-12-03 15:43:59 +08:00
Clean up post type API
This commit is contained in:
parent
ee1302c9ef
commit
2e2617e5b0
|
@ -113,8 +113,8 @@ class CoreServiceProvider extends ServiceProvider
|
|||
|
||||
public function registerPostTypes()
|
||||
{
|
||||
Post::addType('comment', 'Flarum\Core\Models\CommentPost');
|
||||
Post::addType('discussionRenamed', 'Flarum\Core\Models\DiscussionRenamedPost');
|
||||
Post::addType('Flarum\Core\Models\CommentPost');
|
||||
Post::addType('Flarum\Core\Models\DiscussionRenamedPost');
|
||||
|
||||
CommentPost::setFormatter($this->app['flarum.formatter']);
|
||||
}
|
||||
|
|
|
@ -8,6 +8,13 @@ use Flarum\Core\Events\PostWasRestored;
|
|||
|
||||
class CommentPost extends Post
|
||||
{
|
||||
/**
|
||||
* The type of post this is, to be stored in the posts table.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public static $type = 'comment';
|
||||
|
||||
/**
|
||||
* The text formatter instance.
|
||||
*
|
||||
|
|
|
@ -2,6 +2,13 @@
|
|||
|
||||
class DiscussionRenamedPost extends ActivityPost
|
||||
{
|
||||
/**
|
||||
* The type of post this is, to be stored in the posts table.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public static $type = 'discussionRenamed';
|
||||
|
||||
/**
|
||||
* Merge the post into another post of the same type.
|
||||
*
|
||||
|
@ -35,7 +42,6 @@ class DiscussionRenamedPost extends ActivityPost
|
|||
$post->time = time();
|
||||
$post->discussion_id = $discussionId;
|
||||
$post->user_id = $userId;
|
||||
$post->type = 'discussionRenamed';
|
||||
|
||||
return $post;
|
||||
}
|
||||
|
|
|
@ -58,6 +58,7 @@ class Post extends Model
|
|||
parent::boot();
|
||||
|
||||
static::creating(function ($post) {
|
||||
$post->type = $post::$type;
|
||||
$post->number = ++$post->discussion->number_index;
|
||||
$post->discussion->save();
|
||||
});
|
||||
|
@ -161,13 +162,12 @@ class Post extends Model
|
|||
/**
|
||||
* Register a post type and its model class.
|
||||
*
|
||||
* @param string $type
|
||||
* @param string $class
|
||||
* @param string $class
|
||||
* @return void
|
||||
*/
|
||||
public static function addType($type, $class)
|
||||
public static function addType($class)
|
||||
{
|
||||
static::$types[$type] = $class;
|
||||
static::$types[$class::$type] = $class;
|
||||
}
|
||||
|
||||
public static function getTypes()
|
||||
|
|
Loading…
Reference in New Issue
Block a user