mirror of
https://github.com/flarum/core.git
synced 2025-08-02 22:47:33 +02:00
Implement user "bio" field
Perhaps this should be an extension, but it is pretty essential and I can’t think of many instances where it wouldn’t be wanted. Would be very easy to extract later on if need be.
This commit is contained in:
@@ -2,12 +2,14 @@
|
||||
|
||||
use Illuminate\Contracts\Hashing\Hasher;
|
||||
use Tobscure\Permissible\Permissible;
|
||||
use Flarum\Core\Formatter\FormatterManager;
|
||||
use Flarum\Core\Exceptions\InvalidConfirmationTokenException;
|
||||
use Flarum\Core\Events\UserWasDeleted;
|
||||
use Flarum\Core\Events\UserWasRegistered;
|
||||
use Flarum\Core\Events\UserWasRenamed;
|
||||
use Flarum\Core\Events\UserEmailWasChanged;
|
||||
use Flarum\Core\Events\UserPasswordWasChanged;
|
||||
use Flarum\Core\Events\UserBioWasChanged;
|
||||
use Flarum\Core\Events\UserWasActivated;
|
||||
use Flarum\Core\Events\UserEmailWasConfirmed;
|
||||
|
||||
@@ -15,6 +17,13 @@ class User extends Model
|
||||
{
|
||||
use Permissible;
|
||||
|
||||
/**
|
||||
* The text formatter instance.
|
||||
*
|
||||
* @var \Flarum\Core\Formatter\Formatter
|
||||
*/
|
||||
protected static $formatter;
|
||||
|
||||
/**
|
||||
* The validation rules for this model.
|
||||
*
|
||||
@@ -146,6 +155,37 @@ class User extends Model
|
||||
$this->attributes['password'] = $value ? static::$hasher->make($value) : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Change the user's bio.
|
||||
*
|
||||
* @param string $bio
|
||||
* @return $this
|
||||
*/
|
||||
public function changeBio($bio)
|
||||
{
|
||||
$this->bio = $bio;
|
||||
|
||||
$this->raise(new UserBioWasChanged($this));
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the content formatter as HTML.
|
||||
*
|
||||
* @param string $value
|
||||
* @return string
|
||||
*/
|
||||
public function getBioHtmlAttribute($value)
|
||||
{
|
||||
if (! $value) {
|
||||
$this->bio_html = $value = static::formatBio($this->bio);
|
||||
$this->save();
|
||||
}
|
||||
|
||||
return $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Mark all discussions as read by setting the user's read_time.
|
||||
*
|
||||
@@ -332,4 +372,35 @@ class User extends Model
|
||||
{
|
||||
static::$hasher = $hasher;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get text formatter instance.
|
||||
*
|
||||
* @return \Flarum\Core\Formatter\FormatterManager
|
||||
*/
|
||||
public static function getFormatter()
|
||||
{
|
||||
return static::$formatter;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set text formatter instance.
|
||||
*
|
||||
* @param \Flarum\Core\Formatter\FormatterManager $formatter
|
||||
*/
|
||||
public static function setFormatter(FormatterManager $formatter)
|
||||
{
|
||||
static::$formatter = $formatter;
|
||||
}
|
||||
|
||||
/**
|
||||
* Format a string of post content using the set formatter.
|
||||
*
|
||||
* @param string $content
|
||||
* @return string
|
||||
*/
|
||||
protected static function formatBio($content)
|
||||
{
|
||||
return static::$formatter->format($content);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user