SettingsManager manages the system settings

Protected properties

protected array $callbacks

callbacks for registration

protected array $items

items registered

protected array $groupedItems

groupedItems by category

protected string $contextOwner

Active plugin or module owner.

protected string $contextItemCode

contextItemCode for active item

protected static array $itemDefaults

itemDefaults for settings

protected System\Classes\PluginManager $pluginManager

protected static $instance

Public methods

public void __clone()

public void __wakeup()

public void addSettingItem(string $owner, string $code, array $definitions)

Dynamically add a single setting item

  • string $owner
  • string $code
  • array $definitions

public void addSettingItems(string $owner, array $definitions)

Dynamically add an array of setting items

  • string $owner
  • array $definitions

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

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

  • string $owner
  • string $code

public static void forgetInstance()

Forget this singleton's instance if it exists

public mixed getContext()

Returns information about the current settings context.

public static void instance()

Create a new instance of this singleton.

public array listItems(string $context=NULL)

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

  • string $context

public void 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) {
  • callable $callback - A callable function.

public void 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 if iconSvg is not provided.
  • iconSvg - path to a SVG icon file.
  • 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.
  • string $owner - Specifies the setting items owner plugin or module in the format Vendor.Module.
  • array $definitions - An array of the setting item definitions.

public void removeSettingItem($owner, $code)

Removes a single setting item

  • $owner
  • $code

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

setContext sets the navigation context

  • string $owner - Specifies the setting items owner plugin or module in the format Vendor.Module.
  • string $code - Specifies the settings item code.

Protected methods

protected void __construct()


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

Filters a set of items by a given context.

  • array $items
  • string $context

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

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

  • User $user - A user object
  • array $items - A collection of setting items

protected void init()

init initializes this singleton

protected void loadItems()


protected string makeItemKey(object $item, $code)

Internal method to make a unique key for an item.

  • object $item
  • $code