System\Classes\SettingsManager

Overview

SettingsManager manages the system settings


Protected Properties

protected array $items

items registered

protected array $groupedItems

groupedItems by category

protected string $contextOwner

contextOwner is the active plugin or module owner.

protected string $contextItemCode

contextItemCode for active item


Public Methods

public addSettingItem()

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

addSettingItem dynamically adds a single setting item

public addSettingItems()

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

addSettingItems dynamically adds an array of setting items

public findSettingItem()

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

findSettingItem locates a setting item object by its owner and code. Returns the item object or FALSE if nothing is found.

public getContext()

public getContext(): mixed 

getContext returns information about the current settings context. Returns an object with the following fields:

  • itemCode
  • owner

public static instance()

public static instance(): static 

instance creates a new instance of this singleton

public listItems()

public listItems(string $context = null): array 

listItems returns a collection of all settings by group, filtered by context

public registerCallback()

public registerCallback(callable $callback): void

registerCallback 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([...]);
});

public registerSettingItems()

public registerSettingItems(string $owner, array $definitions): void

registerSettingItems registers the backend 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.

public removeSettingItem()

public removeSettingItem(string $owner, string $code): void

removeSettingItem using its owner and code

public static setContext()

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

setContext sets the navigation context. The owner specifies the setting items owner plugin or module in the format Vendor.Module. The code specifies the settings item code.

Protected Methods

protected defineSettingsMenuItem()

protected defineSettingsMenuItem($config): System\Classes\SettingsMenuItem 

protected filterByContext()

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

filterByContext filters a set of items by a given context.

protected filterItemPermissions()

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

filterItemPermissions removes settings items if the supplied user lacks permission. Returns the filtered settings items.

protected loadItems()

protected loadItems(): void

protected makeItemKey()

protected makeItemKey(object $item, $code): string 

makeItemKey is an internal method to make a unique key for an item.