Documentation

SettingsManager
in package
Uses Singleton

Manages the system settings.

Tags
author

Alexey Bobkov, Samuel Georges

Table of Contents

CATEGORY_BACKEND  = 'system::lang.system.categories.backend'
CATEGORY_CMS  = 'system::lang.system.categories.cms'
Allocated category types
CATEGORY_CUSTOMERS  = 'system::lang.system.categories.customers'
CATEGORY_EVENTS  = 'system::lang.system.categories.events'
CATEGORY_LOGS  = 'system::lang.system.categories.logs'
CATEGORY_MAIL  = 'system::lang.system.categories.mail'
CATEGORY_MISC  = 'system::lang.system.categories.misc'
CATEGORY_MYSETTINGS  = 'system::lang.system.categories.my_settings'
CATEGORY_NOTIFICATIONS  = 'system::lang.system.categories.notifications'
CATEGORY_SHOP  = 'system::lang.system.categories.shop'
CATEGORY_SOCIAL  = 'system::lang.system.categories.social'
CATEGORY_SYSTEM  = 'system::lang.system.categories.system'
CATEGORY_TEAM  = 'system::lang.system.categories.team'
CATEGORY_USERS  = 'system::lang.system.categories.users'
$callbacks  : array<string|int, mixed>
$contextItemCode  : string
$contextOwner  : string
$groupedItems  : array<string|int, mixed>
$instance  : mixed
$itemDefaults  : array<string|int, mixed>
$items  : array<string|int, mixed>
$pluginManager  : PluginManager
__clone()  : mixed
__wakeup()  : mixed
addSettingItem()  : mixed
Dynamically add a single setting item
addSettingItems()  : mixed
Dynamically add an array of setting items
findSettingItem()  : mixed
Locates a setting item object by it's owner and code
forgetInstance()  : mixed
Forget this singleton's instance if it exists
getContext()  : mixed
Returns information about the current settings context.
instance()  : mixed
Create a new instance of this singleton.
listItems()  : array<string|int, mixed>
Returns a collection of all settings by group, filtered by context
registerCallback()  : mixed
Registers a callback function that defines setting items.
registerSettingItems()  : mixed
Registers the back-end setting items.
removeSettingItem()  : mixed
Removes a single setting item
setContext()  : mixed
Sets the navigation context.
__construct()  : mixed
Constructor.
filterByContext()  : array<string|int, mixed>
Filters a set of items by a given context.
filterItemPermissions()  : array<string|int, mixed>
Removes settings items from an array if the supplied user lacks permission.
init()  : mixed
Initialize this singleton.
loadItems()  : mixed
makeItemKey()  : string
Internal method to make a unique key for an item.

Constants

CATEGORY_BACKEND

public mixed CATEGORY_BACKEND = 'system::lang.system.categories.backend'

CATEGORY_CMS

Allocated category types

public mixed CATEGORY_CMS = 'system::lang.system.categories.cms'

CATEGORY_CUSTOMERS

public mixed CATEGORY_CUSTOMERS = 'system::lang.system.categories.customers'

CATEGORY_EVENTS

public mixed CATEGORY_EVENTS = 'system::lang.system.categories.events'

CATEGORY_LOGS

public mixed CATEGORY_LOGS = 'system::lang.system.categories.logs'

CATEGORY_MAIL

public mixed CATEGORY_MAIL = 'system::lang.system.categories.mail'

CATEGORY_MISC

public mixed CATEGORY_MISC = 'system::lang.system.categories.misc'

CATEGORY_MYSETTINGS

public mixed CATEGORY_MYSETTINGS = 'system::lang.system.categories.my_settings'

CATEGORY_NOTIFICATIONS

public mixed CATEGORY_NOTIFICATIONS = 'system::lang.system.categories.notifications'

CATEGORY_SHOP

public mixed CATEGORY_SHOP = 'system::lang.system.categories.shop'

CATEGORY_SOCIAL

public mixed CATEGORY_SOCIAL = 'system::lang.system.categories.social'

CATEGORY_SYSTEM

public mixed CATEGORY_SYSTEM = 'system::lang.system.categories.system'

CATEGORY_TEAM

public mixed CATEGORY_TEAM = 'system::lang.system.categories.team'

CATEGORY_USERS

public mixed CATEGORY_USERS = 'system::lang.system.categories.users'

Properties

$callbacks

protected array<string|int, mixed> $callbacks = []

Cache of registration callbacks.

$contextItemCode

protected string $contextItemCode

Active item code.

$contextOwner

protected string $contextOwner

Active plugin or module owner.

$groupedItems

protected array<string|int, mixed> $groupedItems

Grouped collection of all items, by category.

$itemDefaults

protected static array<string|int, mixed> $itemDefaults = ['code' => null, 'label' => null, 'category' => null, 'icon' => null, 'url' => null, 'permissions' => [], 'order' => 500, 'context' => 'system', 'keywords' => null]

Settings item defaults.

$items

protected array<string|int, mixed> $items

List of registered items.

Methods

__clone()

public __clone() : mixed
Return values
mixed

__wakeup()

public __wakeup() : mixed
Return values
mixed

addSettingItem()

Dynamically add a single setting item

public addSettingItem(string $owner, string $code, array<string|int, mixed> $definition) : mixed
Parameters
$owner : string
$code : string
$definition : array<string|int, mixed>
Return values
mixed

addSettingItems()

Dynamically add an array of setting items

public addSettingItems(string $owner, array<string|int, mixed> $definitions) : mixed
Parameters
$owner : string
$definitions : array<string|int, mixed>
Return values
mixed

findSettingItem()

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

public findSettingItem(string $owner, string $code) : mixed
Parameters
$owner : string
$code : string
Return values
mixed

The item object or FALSE if nothing is found

forgetInstance()

Forget this singleton's instance if it exists

public final static forgetInstance() : mixed
Return values
mixed

getContext()

Returns information about the current settings context.

public getContext() : mixed
Return values
mixed

Returns an object with the following fields:

  • itemCode
  • owner

instance()

Create a new instance of this singleton.

public final static instance() : mixed
Return values
mixed

listItems()

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

public listItems([string $context = null ]) : array<string|int, mixed>
Parameters
$context : string = null
Return values
array<string|int, mixed>

registerCallback()

Registers a callback function that defines setting items.

public registerCallback(callable $callback) : mixed

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
$callback : callable

A callable function.

Return values
mixed

registerSettingItems()

Registers the back-end setting items.

public registerSettingItems(string $owner, array<string|int, mixed> $definitions) : mixed

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
$owner : string

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

$definitions : array<string|int, mixed>

An array of the setting item definitions.

Return values
mixed

removeSettingItem()

Removes a single setting item

public removeSettingItem(mixed $owner, mixed $code) : mixed
Parameters
$owner : mixed
$code : mixed
Return values
mixed

setContext()

Sets the navigation context.

public static setContext(string $owner, string $code) : mixed
Parameters
$owner : string

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

$code : string

Specifies the settings item code.

Return values
mixed

__construct()

Constructor.

protected final __construct() : mixed
Return values
mixed

filterByContext()

Filters a set of items by a given context.

protected filterByContext(array<string|int, mixed> $items, string $context) : array<string|int, mixed>
Parameters
$items : array<string|int, mixed>
$context : string
Return values
array<string|int, mixed>

filterItemPermissions()

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

protected filterItemPermissions(User $user, array<string|int, mixed> $items) : array<string|int, mixed>
Parameters
$user : User

A user object

$items : array<string|int, mixed>

A collection of setting items

Return values
array<string|int, mixed>

The filtered settings items

init()

Initialize this singleton.

protected init() : mixed
Return values
mixed

makeItemKey()

Internal method to make a unique key for an item.

protected makeItemKey(mixed $owner, mixed $code) : string
Parameters
$owner : mixed
$code : mixed
Return values
string

Search results