SettingsManager

Manages the system settings.

 class System\Classes\SettingsManager

Traits

Trait Description
LazyOwnerAlias

Lazy Owner Alias Adds support for statically binding owner aliases

Singleton

Singleton trait.

Constants

Constant Description
CATEGORY_BACKEND
string "system::lang.system.categories.backend"
CATEGORY_CMS
string "system::lang.system.categories.cms"

Allocated category types

CATEGORY_CUSTOMERS
string "system::lang.system.categories.customers"
CATEGORY_EVENTS
string "system::lang.system.categories.events"
CATEGORY_LOGS
string "system::lang.system.categories.logs"
CATEGORY_MAIL
string "system::lang.system.categories.mail"
CATEGORY_MISC
string "system::lang.system.categories.misc"
CATEGORY_MYSETTINGS
string "system::lang.system.categories.my_settings"
CATEGORY_NOTIFICATIONS
string "system::lang.system.categories.notifications"
CATEGORY_SHOP
string "system::lang.system.categories.shop"
CATEGORY_SOCIAL
string "system::lang.system.categories.social"
CATEGORY_SYSTEM
string "system::lang.system.categories.system"
CATEGORY_TEAM
string "system::lang.system.categories.team"
CATEGORY_USERS
string "system::lang.system.categories.users"

Properties

protected $aliases : array

List of owner aliases. ['Aliased.Owner' => 'Real.Owner']

protected $callbacks : array

Cache of registration callbacks.

protected $contextItemCode : string

Active item code.

protected $contextOwner : string

Active plugin or module owner.

protected $groupedItems : array

Grouped collection of all items, by category.

protected static $itemDefaults : array

Settings item defaults.

protected $items : array

List of registered items.

protected $pluginManager : System\Classes\PluginManager

protected static $lazyAliases : array

Inherited from LazyOwnerAlias

List of aliases

Methods

public addSettingItem (string $owner, string $code, array $definition)

Dynamically add a single setting item

Parameters
Property Description
$owner
string
$code
string
$definition
array
Returns
mixed

public addSettingItems (string $owner, array $definitions)

Dynamically add an array of setting items

Parameters
Property Description
$owner
string
$definitions
array
Returns
mixed

public findSettingItem (string $owner, string $code) : mixed

Locates a setting item object by it's owner and code

Parameters
Property Description
$owner
string
$code
string
Returns
mixed

The item object or FALSE if nothing is found

public getContext () : mixed

Returns information about the current settings context.

Returns
mixed

Returns an object with the following fields:

  • itemCode
  • owner

public listItems (string $context = null) : array

Returns a collection of all settings by group, filtered by context

Parameters
Property Description
$context
string
Returns
array

public registerCallback (callable $callback)

Registers a callback function that defines setting items.

The callback function should register setting items by calling the manager's registerSettingItems() function. The manager instance is passed to the callback function as an argument. Usage:

SettingsManager::registerCallback(function ($manager) {
    $manager->registerSettingItems([...]);
});
Parameters
Property Description
$callback
callable

A callable function.

Returns
mixed

public registerOwnerAlias (string $owner, string $alias) : void

Register an owner alias

Parameters
Property Description
$owner
string

The owner to register an alias for. Example: Real.Owner

$alias
string

The alias to register. Example: Aliased.Owner

Returns
void

public registerSettingItems (string $owner, array $definitions)

Registers the back-end setting items.

The argument is an array of the settings items. The array keys represent the setting item codes, specific for the plugin/module. Each element in the array should be an associative array with the following keys:

  • label - specifies the settings label localization string key, required.
  • icon - an icon name from the Font Awesome icon collection, required.
  • url - the back-end relative URL the setting item should point to.
  • class - the back-end relative URL the setting item should point to.
  • permissions - an array of permissions the back-end user should have, optional. The item will be displayed if the user has any of the specified permissions.
  • order - a position of the item in the setting, optional.
  • category - a string to assign this item to a category, optional.
Parameters
Property Description
$owner
string

Specifies the setting items owner plugin or module in the format Vendor.Module.

$definitions
array

An array of the setting item definitions.

Returns
mixed

public removeSettingItem ($owner, $code)

Removes a single setting item

Parameters
Property Description
$owner
mixed
$code
mixed
Returns
mixed

public static setContext (string $owner, string $code)

Sets the navigation context.

Parameters
Property Description
$owner
string

Specifies the setting items owner plugin or module in the format Vendor.Module.

$code
string

Specifies the settings item code.

Returns
mixed

protected filterByContext (array $items, string $context) : array

Filters a set of items by a given context.

Parameters
Property Description
$items
array
$context
string
Returns
array

protected filterItemPermissions (User $user, array $items) : array

Removes settings items from an array if the supplied user lacks permission.

Parameters
Property Description
$user
User

A user object

$items
array

A collection of setting items

Returns
array

The filtered settings items

protected init ()

Initialize this singleton.

Returns
mixed

protected loadItems ()

Returns
mixed

protected makeItemKey ($owner, $code) : string

Internal method to make a unique key for an item.

Parameters
Property Description
$owner
mixed
$code
mixed
Returns
string

public __clone ()

Inherited from Singleton
Returns
mixed

public __wakeup ()

Inherited from Singleton
Returns
mixed

public static final forgetInstance ($container = null) : void

Inherited from Singleton

Forget this singleton's instance if it exists

Parameters
Property Description
$container
mixed
Returns
void

public static final instance ($container = null) : static

Inherited from Singleton

Create a new instance of this singleton.

Parameters
Property Description
$container
mixed
Returns
static

public static lazyRegisterOwnerAlias (string $owner, string $alias) : void

Inherited from LazyOwnerAlias

Binds the alias of an owner to the lazy alias list. This allows us to bind aliases prior to init() which is necessary to do before to PluginManager being registered.

Parameters
Property Description
$owner
string
$alias
string
Returns
void

protected final __construct ()

Inherited from Singleton

Constructor.

Returns
mixed
Copyright © 2024 Winter CMS