Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use drivers for display names, add display name extender #2174

Merged
merged 12 commits into from
May 19, 2020
Merged
Prev Previous commit
Next Next commit
Configured User class to use new driver-based system for display names
  • Loading branch information
askvortsov1 committed May 18, 2020
commit ea9e7652c40cdd8a3edf815255658b8d61927ab3
21 changes: 20 additions & 1 deletion src/User/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
use Flarum\Http\UrlGenerator;
use Flarum\Notification\Notification;
use Flarum\Post\Post;
use Flarum\User\DisplayName\DriverInterface;
use Flarum\User\Event\Activated;
use Flarum\User\Event\AvatarChanged;
use Flarum\User\Event\CheckingPassword;
Expand Down Expand Up @@ -93,6 +94,13 @@ class User extends AbstractModel
*/
protected static $preferences = [];

/**
* A driver for getting display names.
*
* @var DriverInterface
*/
protected static $displayNameDriver;

/**
* The hasher with which to hash passwords.
*
Expand Down Expand Up @@ -172,6 +180,16 @@ public static function setGate($gate)
static::$gate = $gate;
}

/**
* Set the display name driver.
*
* @param DriverInterface $driver
*/
public static function setDisplayNameDriver(DriverInterface $driver)
{
static::$displayNameDriver = $driver;
}

/**
* Rename the user.
*
Expand Down Expand Up @@ -309,7 +327,8 @@ public function getAvatarUrlAttribute(string $value = null)
*/
public function getDisplayNameAttribute()
{
return static::$dispatcher->until(new GetDisplayName($this)) ?: $this->username;
// Event is deprecated in beta 14, remove in beta 15.
return static::$dispatcher->until(new GetDisplayName($this)) ?: static::$displayNameDriver->displayName($this);
}

/**
Expand Down