mirror of
https://github.com/flarum/core.git
synced 2025-10-21 03:36:05 +02:00
Make formatter extensible
This commit is contained in:
@@ -37,12 +37,14 @@ class CommentPost extends Post
|
||||
{
|
||||
$post = new static;
|
||||
|
||||
$post->content = $content;
|
||||
$post->time = time();
|
||||
$post->discussion_id = $discussionId;
|
||||
$post->user_id = $userId;
|
||||
$post->type = static::$type;
|
||||
|
||||
// Set content last, as the parsing may rely on other post attributes.
|
||||
$post->content = $content;
|
||||
|
||||
$post->raise(new PostWasPosted($post));
|
||||
|
||||
return $post;
|
||||
@@ -113,15 +115,26 @@ class CommentPost extends Post
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse the content before it is saved to the database.
|
||||
* Unparse the parsed content.
|
||||
*
|
||||
* @param string $value
|
||||
* @return string
|
||||
*/
|
||||
public function getContentAttribute($value)
|
||||
{
|
||||
return static::$formatter->unparse($value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the parsed/raw content.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getParsedContentAttribute()
|
||||
{
|
||||
return $this->attributes['content'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse the content before it is saved to the database.
|
||||
*
|
||||
@@ -129,7 +142,7 @@ class CommentPost extends Post
|
||||
*/
|
||||
public function setContentAttribute($value)
|
||||
{
|
||||
$this->attributes['content'] = static::$formatter->parse($value);
|
||||
$this->attributes['content'] = static::$formatter->parse($value, $this);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -140,7 +153,7 @@ class CommentPost extends Post
|
||||
*/
|
||||
public function getContentHtmlAttribute($value)
|
||||
{
|
||||
return static::$formatter->render($this->attributes['content']);
|
||||
return static::$formatter->render($this->attributes['content'], $this);
|
||||
}
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user