SettingsModel

Settings model extension

 class System\Behaviors\SettingsModel
extends System\Classes\ModelBehavior

Add this the model class definition:

public $implement = ['System.Behaviors.SettingsModel'];
public $settingsCode = 'author_plugin_code';
public $settingsFields = 'fields.yaml';

Optionally:

public $settingsCacheTtl = 1440;

Traits

Trait Description
ConfigMaker

Config Maker Trait Adds configuration based methods to a class

ExtensionTrait

Extension trait

Properties

protected $cacheTtl : integer

Settings cache TTL, in seconds.

protected $fieldConfig : mixed

protected $fieldValues : mixed

protected $recordCode : mixed

protected $requiredProperties : mixed

Properties that must exist in the model using this behavior.

private static $instances : array

Internal cache of model objects.

public static $extendableStaticCalledClass : string

Inherited from ModelBehavior

The calling class when using a static method.

protected $configPath : string

Inherited from ConfigMaker

Specifies a path to the config directory.

protected static $extensionCallbacks : array

Inherited from ModelBehavior

Used to extend the constructor of an extension class. Eg:

BehaviorClass::extend(function($obj) { })

protected $extensionHidden : mixed

Inherited from ModelBehavior

protected $model : Winter\Storm\Database\Model

Inherited from ModelBehavior

Reference to the extended model.

Methods

public __construct ($model)

Constructor

Parameters
Property Description
$model
mixed
Returns
mixed

public afterModelFetch ()

Populate the field values from the database record.

Returns
mixed

public afterModelSave () : void

After the model is saved, clear the cached query entry and restart queue workers so they have the latest settings

Returns
void

public beforeModelSave ()

Before the model is saved, ensure the record code is set and the jsonable field values

Returns
mixed

public static clearInternalCache () : void

Clears the internal memory cache of model instances.

Returns
void

public get ($key, $default = null)

Helper for getSettingsValue, intended as a static method

Parameters
Property Description
$key
mixed
$default
mixed
Returns
mixed

public getFieldConfig ()

Returns the field configuration used by this model.

Returns
mixed

public getSettingsRecord () : Model

Returns the raw Model record that stores the settings.

Returns
Model

public getSettingsValue ($key, $default = null)

Get a single setting value, or return a default value

Parameters
Property Description
$key
mixed
$default
mixed
Returns
mixed

public initSettingsData ()

Default values to set for this model, override

Returns
mixed

public instance ()

Create an instance of the settings model, intended as a static method

Returns
mixed

public isConfigured () : bool

Checks if the model has been set up previously, intended as a static method

Returns
bool

public resetDefault ()

Reset the settings to their defaults, this will delete the record model

Returns
mixed

public saveModelInternal () : void

Internal save method for the model

Returns
void

public set ($key, $value = null)

Set a single or array key pair of values, intended as a static method

Parameters
Property Description
$key
mixed
$value
mixed
Returns
mixed

public setSettingsValue ($key, $value)

Set a single setting value, if allowed.

Parameters
Property Description
$key
mixed
$value
mixed
Returns
mixed

protected getCacheKey ()

Returns a cache key for this record.

Returns
mixed

protected isKeyAllowed ($key)

Checks if a key is legitimate or should be added to the field value collection

Parameters
Property Description
$key
mixed
Returns
mixed

public static extend (callable $callback)

Inherited from ModelBehavior
Parameters
Property Description
$callback
callable
Returns
mixed

public extensionApplyInitCallbacks ()

Inherited from ModelBehavior
Returns
mixed

public static extensionExtendCallback (callable $callback) : void

Inherited from ModelBehavior

Helper method for ::extend() static method

Parameters
Property Description
$callback
callable
Returns
void

public extensionIsHiddenField ($name)

Inherited from ModelBehavior
Parameters
Property Description
$name
mixed
Returns
mixed

public extensionIsHiddenMethod ($name)

Inherited from ModelBehavior
Parameters
Property Description
$name
mixed
Returns
mixed

public static getCalledExtensionClass ()

Inherited from ModelBehavior
Returns
mixed

public getConfigPath (string $fileName, mixed $configPath = null) : string

Inherited from ConfigMaker

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.

Parameters
Property Description
$fileName
string

File to load.

$configPath
mixed

Explicitly define a config path.

Returns
string

Full path to the config file.

public guessConfigPath (string $suffix = "") : string

Inherited from ConfigMaker

Guess the package path for the called class.

Parameters
Property Description
$suffix
string

An extra path to attach to the end

Returns
string

public guessConfigPathFrom (string $class, string $suffix = "") : string

Inherited from ConfigMaker

Guess the package path from a specified class.

Parameters
Property Description
$class
string

Class to guess path from.

$suffix
string

An extra path to attach to the end

Returns
string

public makeConfig (array $configFile = [], array $requiredConfig = []) : array | stdClass

Inherited from ConfigMaker

Reads the contents of the supplied file and applies it to this object.

Parameters
Property Description
$configFile
array
$requiredConfig
array
Returns
array | stdClass

public makeConfigFromArray (array $configArray = []) : stdClass

Inherited from ConfigMaker

Makes a config object from an array, making the first level keys properties of a new object.

Parameters
Property Description
$configArray
array

Config array.

Returns
stdClass

The config object

public mergeConfig (mixed $configA, mixed $configB) : stdClass

Inherited from ConfigMaker

Merges two configuration sources, either prepared or not, and returns them as a single configuration object.

Parameters
Property Description
$configA
mixed
$configB
mixed
Returns
stdClass

The config object

protected extensionHideField ($name)

Inherited from ModelBehavior
Parameters
Property Description
$name
mixed
Returns
mixed

protected extensionHideMethod ($name)

Inherited from ModelBehavior
Parameters
Property Description
$name
mixed
Returns
mixed
Copyright © 2024 Winter CMS