System\Classes\MarkupManager

Overview

MarkupManager class manages Twig functions, token parsers and filters.


Protected Properties

protected array[MarkupExtensionItem[]] $items

items are globally registered extension items


Public Methods

public static instance()

public static instance(): static 

instance creates a new instance of this singleton

public listExtensions()

public listExtensions($type $type): array 

listExtensions returns a list of the registered Twig extensions of a type.

public listFilters()

public listFilters(): array 

listFilters returns a list of the registered Twig filters.

public listFunctions()

public listFunctions(): array 

listFunctions returns a list of the registered Twig functions.

public listTokenParsers()

public listTokenParsers(): array 

listTokenParsers returns a list of the registered Twig token parsers.

public makeTwigFilters()

public makeTwigFilters(array $filters = []): array 

makeTwigFilters makes a set of Twig filters for use in a twig extension.

public makeTwigFunctions()

public makeTwigFunctions(array $functions = []): array 

makeTwigFunctions makes a set of Twig functions for use in a twig extension.

public makeTwigTokenParsers()

public makeTwigTokenParsers(array $parsers = []): array 

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

public registerCallback()

public registerCallback(callable $callback): void

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

public registerExtensions()

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

registerExtensions 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.

public registerFilters()

public registerFilters(array $definitions): void

Registers a CMS Twig Filter

public registerFunctions()

public registerFunctions(array $definitions): void

Registers a CMS Twig Function

public registerTokenParsers()

public registerTokenParsers(array $definitions): void

Registers a CMS Twig Token Parser

Protected Methods

protected defineMarkupExtensionItem()

protected defineMarkupExtensionItem(
    $config
): System\Classes\MarkupExtensionItem 

protected loadExtensions()

protected loadExtensions(): void

loadExtensions parses all registrations and adds them to this class

protected loadExtensionsFromArray()

protected loadExtensionsFromArray($items): void

loadExtensionsFromArray helper