Settings model extension

Add this the model class definition:

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

Public properties

There are no public properties in the class.

Show inherited public properties

Inherited public properties

Protected properties

protected $recordCode

protected $fieldConfig

protected $fieldValues

protected $requiredProperties

Properties that must exist in the model using this behavior.

protected string $configPath

Specifies a path to the config directory.

Show inherited protected properties

Inherited protected properties

Public methods

public void __construct($model)


  • $model

public void afterModelFetch()

Populate the field values from the database record.

public void afterModelSave()

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

public void beforeModelSave()

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

public static void clearInternalCache()

Clears the internal memory cache of model instances.

public void get($key, $default=NULL)

Helper for getSettingsValue, intended as a static method

  • $key
  • $default

public string getConfigPath(string $fileName, mixed $configPath=NULL)

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.

  • string $fileName - File to load.
  • mixed $configPath - Explicitly define a config path.

public void getFieldConfig()

Returns the field configuration used by this model.

public Model getSettingsRecord()

getSettingsRecord returns the raw Model record that stores the settings.

public void getSettingsValue($key, $default=NULL)

Get a single setting value, or return a default value

  • $key
  • $default

public string guessConfigPath(string $suffix='')

Guess the package path for the called class.

  • string $suffix - An extra path to attach to the end

public string guessConfigPathFrom(string $class, string $suffix='')

Guess the package path from a specified class.

  • string $class - Class to guess path from.
  • string $suffix - An extra path to attach to the end

public void initSettingsData()

Default values to set for this model, override

public void instance()

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

public bool isConfigured()

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

public object makeConfig(array $configFile=array(), array $requiredConfig=array())

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

  • array $configFile
  • array $requiredConfig

public stdClass makeConfigFromArray(array $configArray=array())

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

  • array $configArray - Config array.

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

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

  • mixed $configA
  • mixed $configB

public void resetDefault()

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

public void saveModelInternal()

Internal save method for the model

public void set($key, $value=NULL)

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

  • $key
  • $value

public void setSettingsValue($key, $value)

Set a single setting value, if allowed.

  • $key
  • $value

Show inherited public methods

Inherited public methods

Protected methods

protected void getCacheKey()

Returns a cache key for this record.

protected void isKeyAllowed($key)

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

  • $key

Show inherited protected methods

Inherited protected methods