1
0
mirror of https://github.com/flarum/core.git synced 2025-10-27 05:31:29 +01:00

User Preferences Extender and Tests (#2463)

This commit is contained in:
Alexander Skvortsov
2020-12-04 15:45:08 -05:00
committed by GitHub
parent 641619e820
commit eed407812f
7 changed files with 99 additions and 14 deletions

View File

@@ -143,6 +143,9 @@ class User extends AbstractModel
Notification::whereSubject($user)->delete();
});
/**
* @deprecated beta 15, remove beta 16
*/
static::$dispatcher->dispatch(
new ConfigureUserPreferences
);
@@ -801,6 +804,8 @@ class User extends AbstractModel
}
/**
* @deprecated beta 15, remove beta 16. Use `registerPreference` instead.
*
* Register a preference with a transformer and a default value.
*
* @param string $key
@@ -808,6 +813,18 @@ class User extends AbstractModel
* @param mixed $default
*/
public static function addPreference($key, callable $transformer = null, $default = null)
{
return static::registerPreference($key, $transformer, $default);
}
/**
* Register a preference with a transformer and a default value.
*
* @param string $key
* @param callable $transformer
* @param mixed $default
*/
public static function registerPreference($key, callable $transformer = null, $default = null)
{
static::$preferences[$key] = compact('transformer', 'default');
}

View File

@@ -9,7 +9,6 @@
namespace Flarum\User;
use Flarum\Event\ConfigureUserPreferences;
use Flarum\Foundation\AbstractServiceProvider;
use Flarum\Foundation\ContainerUtil;
use Flarum\Settings\SettingsRepositoryInterface;
@@ -94,16 +93,8 @@ class UserServiceProvider extends AbstractServiceProvider
$events->subscribe(UserMetadataUpdater::class);
$events->subscribe(UserPolicy::class);
$events->listen(ConfigureUserPreferences::class, [$this, 'configureUserPreferences']);
}
/**
* @param ConfigureUserPreferences $event
*/
public function configureUserPreferences(ConfigureUserPreferences $event)
{
$event->add('discloseOnline', 'boolval', true);
$event->add('indexProfile', 'boolval', true);
$event->add('locale');
User::registerPreference('discloseOnline', 'boolval', true);
User::registerPreference('indexProfile', 'boolval', true);
User::registerPreference('locale');
}
}