mirror of
https://github.com/discourse/discourse.git
synced 2024-11-24 18:00:39 -06:00
9668592aab
This commit introduces the `valueTransformer`API to safely override values defined in Discourse. Two new plugin APIs are introduced: - `addValueTransformerName` which allows plugins and theme-components to add a new valid transformer name if they want to provide overridable values; - `registerValueTransformer` to register a transformer to override values. It also introduces the function `applyValueTransformer` which can be imported from `discourse/lib/transformer`. This function marks the desired value as overridable and applies the transformer logic. How does it work? ## Marking a value as overridable: To mark a value as overridable, in Discourse core, first the transformer name must be added to `app/assets/javascripts/discourse/app/lib/transformer/registry.js`. For plugins and theme-components, use the plugin API `addValueTransformerName` instead. Then, in your component or class, use the function `applyValueTransformer` to mark the value as overridable and handle the logic: - example: ```js export default class HomeLogo extends Component { @service session; @service site; ... get href() { return applyValueTransformer("home-logo-href", getURL("/")); } ``` ## Overriding a value in plugins or themes To override a value in plugins, themes, or TCs use the plugin API `registerValueTransformer`: - Example: ```js withPluginApi("1.34.0", (api) => { api.registerValueTransformer("example-transformer", ({ value }) => { return "new-value"; }); }); ``` |
||
---|---|---|
.. | ||
ADMIN-QUICK-START-GUIDE.md | ||
AUTHORS.md | ||
CHANGELOG-JAVASCRIPT-PLUGIN-API.md | ||
code-of-conduct.md | ||
DEVELOPER-ADVANCED.md | ||
DEVELOPMENT-OSX-NATIVE.md | ||
INSTALL-cloud.md | ||
INSTALL-email.md | ||
INSTALL.md | ||
PLUGINS.md | ||
SECURITY.md | ||
TESTING.md | ||
TROUBLESHOOTING.md |