class Theme implements ExtenderInterface

Methods

overrideLessImport(string $file, string $newFilePath, string|null $extensionId = null)

This can be used to override `LESS` files that are imported within the code.

overrideFileSource(string $file, string $newFilePath, string|null $extensionId = null)

This method allows overriding LESS file sources.

addCustomLessFunction(string $functionName, callable $callable)

This method allows you to add custom Less functions.

addCustomLessVariable(string $variableName, callable $value)

Defines a new Less variable to be accessible in all Less files.

void
extend(Container $container, Extension|null $extension = null)

No description

Details

Theme overrideLessImport(string $file, string $newFilePath, string|null $extensionId = null)

This can be used to override `LESS` files that are imported within the code.

For example, core's `forum.less` file imports a `forum/DiscussionListItem.less` file. The contents of this file can be overridden with this method.

Parameters

string $file : Relative path of the file to override, for example: `forum/Hero.less`
string $newFilePath : Absolute path of the new file.
string|null $extensionId : If overriding an extension file, specify its ID, for example: `flarum-tags`.

Return Value

Theme

Theme overrideFileSource(string $file, string $newFilePath, string|null $extensionId = null)

This method allows overriding LESS file sources.

For example `forum.less`, `admin.less`, `mixins.less` and `variables.less` are file sources, and can therefore be overridden using this method.

Parameters

string $file : Name of the file to override, for example: `admin.less`
string $newFilePath : Absolute path of the new file.
string|null $extensionId : If overriding an extension file, specify its ID, for example: `flarum-tags`.

Return Value

Theme

Theme addCustomLessFunction(string $functionName, callable $callable)

This method allows you to add custom Less functions.

All custom Less functions may only return numbers, strings or booleans. **Example usage:** ```php (new Extend\Theme) ->addCustomLessFunction('is-flarum', function (mixed $text) { return strtolower($text) === 'flarum' }), ```

Parameters

string $functionName Name of the function identifier.
callable $callable The PHP function to run when the Less function is called.

Return Value

Theme

See also

https://leafo.net/lessphp/docs/#custom_functions

Theme addCustomLessVariable(string $variableName, callable $value)

Defines a new Less variable to be accessible in all Less files.

If you want to expose a setting from your database to Less, you should use the `registerLessConfigVar` extender from `Extend\Settings` instead. Please note the value returned from the callable will be inserted directly into the Less source. If it is unsafe in some way (e.g., contains a semi-colon), this will result in potential security issues with your stylesheet. Likewise, if you need your variable to be a string, you should surround it with quotes yourself. ```php (new Extend\Theme()) ->addCustomLessVariable('my-extension__asset_path', function () { $url = resolve(UrlGenerator::class); $assetUrl = $url->to('forum')->base().'/assets/extensions/my-extension/my-asset.jpg'; return "\"$assetUrl\""; }) ```

Parameters

string $variableName Name of the variable identifier.
callable $value The PHP function to run, which returns the value for the variable.

Return Value

Theme

void extend(Container $container, Extension|null $extension = null)

Parameters

Container $container
Extension|null $extension

Return Value

void