Setting
Click here if you want to read this article for the latest version.
Piwik\Settings\
Setting
Base setting type class.
Methods
The class defines the following methods:
__construct()— Constructor.getName()— Get the name of the setting.getType()— Get the PHP type of the setting.getDefaultValue()setDefaultValue()— Sets/overwrites the current default valuesetIsWritableByCurrentUser()— Set whether setting is writable or not.isWritableByCurrentUser()— Returnstrueif this setting is writable for the current user,falseif otherwise.save()— Saves (persists) the value for this setting in the database if a value has been actually set.getValue()— Returns the previously persisted setting value.setValue()— Sets and persists this setting's value overwriting any existing value.
__construct()
Constructor.
Signature
- It accepts the following parameter(s):
$name(string) — The setting's persisted name. Only alphanumeric characters are allowed, eg,'refreshInterval'.$defaultValue(mixed) — Default value for this setting if no value was specified.$type(string) — Eg an array, int, ... see SettingConfig::TYPE_* constants$pluginName(string) — The name of the plugin the setting belongs to
- It throws one of the following exceptions:
getName()
Get the name of the setting.
Signature
- It returns a
stringvalue.
getType()
Get the PHP type of the setting.
Signature
- It returns a
stringvalue.
getDefaultValue()
Signature
- It returns a
mixedvalue.
setDefaultValue()
Sets/overwrites the current default value
Signature
It accepts the following parameter(s):
$defaultValue(string) —
It does not return anything or a mixed result.
setIsWritableByCurrentUser()
Set whether setting is writable or not. For example to hide setting from the UI set it to false.
Signature
It accepts the following parameter(s):
$isWritable(bool) —
It does not return anything or a mixed result.
isWritableByCurrentUser()
Returns true if this setting is writable for the current user, false if otherwise. In case it returns
writable for the current user it will be visible in the Plugin settings UI.
Signature
- It returns a
boolvalue.
save()
Saves (persists) the value for this setting in the database if a value has been actually set.
Signature
- It does not return anything or a mixed result.
getValue()
Returns the previously persisted setting value. If no value was set, the default value is returned.
Signature
- It returns a
mixedvalue.
setValue()
Sets and persists this setting's value overwriting any existing value.
Before a value is actually set it will be made sure the current user is allowed to change the value. The value will be first validated either via a system built-in validate method or via a set FieldConfig::$validate custom method. Afterwards the value will be transformed via a possibly specified FieldConfig::$transform method. Before storing the actual value, the value will be converted to the actually specified $type.
Signature
It accepts the following parameter(s):
$value(mixed) —
It does not return anything or a mixed result.
- It throws one of the following exceptions:
Exception— If the current user is not allowed to change the value of this setting.