UserPreferencesModel
User Preferences model extension, identical to System\Behaviors\SettingsModel
except values are set against the logged in user's preferences via Backend\Models\UserPreference
class Backend\Behaviors\UserPreferencesModel
extends System\Behaviors\SettingsModel
Add this the model class definition:
public $implement = ['Backend.Behaviors.UserPreferencesModel']; public $settingsCode = 'author.plugin::code'; public $settingsFields = 'fields.yaml';
Extends
Class | Description |
---|---|
SettingsModel
|
Settings model extension |
Traits
Trait | Description |
---|---|
ConfigMaker
|
Config Maker Trait Adds configuration based methods to a class |
ExtensionTrait
|
Extension trait |
Properties
private
static
$instances
:
array
= []
Internal cache of model objects.
inherited
public
static
$extendableStaticCalledClass
:
string
= null
The calling class when using a static method.
inherited
protected
$cacheTtl
:
integer
= 1440
Settings cache TTL, in seconds.
inherited protected $configPath : string
Specifies a path to the config directory.
inherited
protected
static
$extensionCallbacks
:
array
= []
Used to extend the constructor of an extension class. Eg:
BehaviorClass::extend(function($obj) { })
inherited
protected
$extensionHidden
:
mixed
= {"fields":[],"methods":["extensionIsHiddenField","extensionIsHiddenMethod"]}
inherited protected $fieldConfig : mixed
inherited
protected
$fieldValues
:
mixed
= []
inherited protected $model : Winter\Storm\Database\Model
Reference to the extended model.
inherited protected $recordCode : mixed
inherited
protected
$requiredProperties
:
mixed
= ["settingsFields","settingsCode"]
Properties that must exist in the model using this behavior.
Methods
public __construct ($model)
Constructor
Property | Type | Description |
---|---|---|
$model | mixed |
mixed
|
public beforeModelSave ()
Before the model is saved, ensure the record code is set and the jsonable field values
public getSettingsRecord () : Model
Returns the raw Model record that stores the settings.
public instance ()
Create an instance of the settings model, intended as a static method
public isConfigured () : bool
Checks if the model has been set up previously, intended as a static method
protected getCacheKey ()
Returns a cache key for this record.
protected isKeyAllowed ($key)
Checks if a key is legitimate or should be added to the field value collection
Property | Type | Description |
---|---|---|
$key | mixed |
mixed
|
inherited public afterModelFetch ()
Populate the field values from the database record.
inherited public afterModelSave () : void
After the model is saved, clear the cached query entry and restart queue workers so they have the latest settings
inherited public static clearInternalCache () : void
Clears the internal memory cache of model instances.
inherited public static extend (callable $callback)
Property | Type | Description |
---|---|---|
$callback | callable |
callable
|
inherited public extensionApplyInitCallbacks ()
inherited public static extensionExtendCallback (callable $callback) : void
Helper method for ::extend()
static method
Property | Type | Description |
---|---|---|
$callback | callable |
callable
|
inherited public extensionIsHiddenField ($name)
Property | Type | Description |
---|---|---|
$name | mixed |
mixed
|
inherited public extensionIsHiddenMethod ($name)
Property | Type | Description |
---|---|---|
$name | mixed |
mixed
|
inherited
public
get ($key, $default = null
)
Helper for getSettingsValue, intended as a static method
Property | Type | Description |
---|---|---|
$key | mixed |
mixed
|
$default | mixed |
mixed
|
inherited public static getCalledExtensionClass ()
inherited
public
getConfigPath (string $fileName, mixed $configPath = null
)
: string
Locates a file based on it's definition. If the file starts with the ~ symbol it will be returned in context of the application base path, otherwise it will be returned in context of the config path.
Property | Type | Description |
---|---|---|
$fileName | string |
string
File to load. |
$configPath | mixed |
mixed
Explicitly define a config path. |
Full path to the config file.
inherited public getFieldConfig ()
Returns the field configuration used by this model.
inherited
public
getSettingsValue ($key, $default = null
)
Get a single setting value, or return a default value
Property | Type | Description |
---|---|---|
$key | mixed |
mixed
|
$default | mixed |
mixed
|
inherited
public
guessConfigPath (string $suffix = ""
)
: string
Guess the package path for the called class.
Property | Type | Description |
---|---|---|
$suffix | string |
string
An extra path to attach to the end |
inherited
public
guessConfigPathFrom (string $class, string $suffix = ""
)
: string
Guess the package path from a specified class.
Property | Type | Description |
---|---|---|
$class | string |
string
Class to guess path from. |
$suffix | string |
string
An extra path to attach to the end |
inherited public initSettingsData ()
Default values to set for this model, override
inherited
public
makeConfig (array $configFile = []
, array $requiredConfig = []
)
: array | stdClass
Reads the contents of the supplied file and applies it to this object.
Property | Type | Description |
---|---|---|
$configFile | array |
array
|
$requiredConfig | array |
array
|
inherited
public
makeConfigFromArray (array $configArray = []
)
: stdClass
Makes a config object from an array, making the first level keys properties of a new object.
Property | Type | Description |
---|---|---|
$configArray | array |
array
Config array. |
The config object
inherited public mergeConfig (mixed $configA, mixed $configB) : stdClass
Merges two configuration sources, either prepared or not, and returns them as a single configuration object.
Property | Type | Description |
---|---|---|
$configA | mixed |
mixed
|
$configB | mixed |
mixed
|
The config object
inherited public resetDefault ()
Reset the settings to their defaults, this will delete the record model
inherited public saveModelInternal () : void
Internal save method for the model
inherited
public
set ($key, $value = null
)
Set a single or array key pair of values, intended as a static method
Property | Type | Description |
---|---|---|
$key | mixed |
mixed
|
$value | mixed |
mixed
|
inherited public setSettingsValue ($key, $value)
Set a single setting value, if allowed.
Property | Type | Description |
---|---|---|
$key | mixed |
mixed
|
$value | mixed |
mixed
|
inherited protected extensionHideField ($name)
Property | Type | Description |
---|---|---|
$name | mixed |
mixed
|
inherited protected extensionHideMethod ($name)
Property | Type | Description |
---|---|---|
$name | mixed |
mixed
|