System\Classes\MarkupManager

MarkupManager class manages Twig functions, token parsers and filters.

Protected properties

protected array $callbacks

Cache of registration callbacks.

protected array[MarkupExtentionItem[]] $items

Globally registered extension items

protected System\Classes\PluginManager $pluginManager

protected static $instance

Public methods

public void __clone()

public void __wakeup()

public static void forgetInstance()

Forget this singleton's instance if it exists

public static void instance()

Create a new instance of this singleton.

public array listExtensions($type $type)

Returns a list of the registered Twig extensions of a type.

Parameters
  • $type $type - String The Twig extension type

public array listFilters()

Returns a list of the registered Twig filters.

public array listFunctions()

Returns a list of the registered Twig functions.

public array listTokenParsers()

Returns a list of the registered Twig token parsers.

public array makeTwigFilters(array $filters=array())

Makes a set of Twig filters for use in a twig extension.

Parameters
  • array $filters - Current collection

public array makeTwigFunctions(array $functions=array())

Makes a set of Twig functions for use in a twig extension.

Parameters
  • array $functions - Current collection

public array makeTwigTokenParsers(array $parsers=array())

Makes a set of Twig token parsers for use in a twig extension.

Parameters
  • array $parsers - Current collection

public void registerCallback(callable $callback)

Registers a callback function that defines simple Twig extensions. The callback function should register menu items by calling the manager's registerFunctions, registerFilters, registerTokenParsers function. The manager instance is passed to the callback function as an argument. Usage:

MarkupManager::registerCallback(function ($manager) {
    $manager->registerFilters([...]);
    $manager->registerFunctions([...]);
    $manager->registerTokenParsers([...]);
});
Parameters
  • callable $callback - A callable function.

public void registerExtensions(string $type, array $definitions)

Registers the CMS Twig extension items. The argument is an array of the extension definitions. The array keys represent the function/filter name, specific for the plugin/module. Each element in the array should be an associative array.

Parameters
  • string $type - The extension type: filters, functions, tokens
  • array $definitions - An array of the extension definitions.

public void registerFilters(array $definitions)

Registers a CMS Twig Filter

Parameters
  • array $definitions - An array of the extension definitions.

public void registerFunctions(array $definitions)

Registers a CMS Twig Function

Parameters
  • array $definitions - An array of the extension definitions.

public void registerTokenParsers(array $definitions)

Registers a CMS Twig Token Parser

Parameters
  • array $definitions - An array of the extension definitions.

Protected methods

protected void __construct()

Constructor.

protected void init()

Initialize this singleton.

protected void loadExtensions()

loadExtensions parses all registrations and adds them to this class