System\Classes\SettingsManager

Source: ~/modules/system/classes/SettingsManager.php

Manages the system settings.

Protected properties

protected array $callbacks

Cache of registration callbacks.

protected array $items

List of registered items.

protected array $groupedItems

Grouped collection of all items, by category.

protected string $contextOwner

Active plugin or module owner.

protected string $contextItemCode

Active item code.

protected static array $itemDefaults

Settings item defaults.

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

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

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

Dynamically add an array of setting items

Parameters
  • string $owner
  • array $definitions

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

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

Parameters
  • 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

Parameters
  • 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){
    $manager->registerSettingItems([...]);
});
Parameters
  • 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.
  • 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
  • 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

Parameters
  • $owner
  • $code

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

Sets the navigation context.

Parameters
  • 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()

Constructor.

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

Filters a set of items by a given context.

Parameters
  • array $items
  • string $context

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

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

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

protected void init()

Initialize this singleton.

protected void loadItems()

protected string makeItemKey(object $item, $code)

Internal method to make a unique key for an item.

Parameters
  • object $item
  • $code