discourse/docs
Sérgio Saquetim 9668592aab
DEV: Introduce a value transformer front-end plugin API (#27090)
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";
  });
});
```
2024-06-12 15:21:52 -03:00
..
ADMIN-QUICK-START-GUIDE.md FIX: uses the correct link for the General category (#26891) 2024-05-07 13:42:58 +02:00
AUTHORS.md HTTPSify links (#7046) 2019-02-22 16:29:27 +01:00
CHANGELOG-JAVASCRIPT-PLUGIN-API.md DEV: Introduce a value transformer front-end plugin API (#27090) 2024-06-12 15:21:52 -03:00
code-of-conduct.md Update Code of Conduct to v2.0 (#12296) 2021-03-04 23:44:58 -05:00
DEVELOPER-ADVANCED.md Update DEVELOPER-ADVANCED.md (#15770) 2022-02-02 11:05:37 -05:00
DEVELOPMENT-OSX-NATIVE.md DEV: Swap out optipng with oxipng (#15013) 2021-11-22 10:16:35 -07:00
INSTALL-cloud.md Update INSTALL-cloud.md screenshots and copy when landed on the forum homepage (#25671) 2024-02-14 07:31:44 -07:00
INSTALL-email.md DOCS: Update INSTALL-email to point to Brevo correctly 2023-12-04 11:46:33 +11:00
INSTALL.md DEV: Update recommended Ruby to 3.2.1 (#20444) 2023-02-24 12:51:34 -03:00
PLUGINS.md discourse/discourse change from 'master' to 'main' 2021-07-19 11:46:15 -04:00
SECURITY.md FEATURE: Increase pbkdf2 iterations to 600k (#20981) 2023-04-11 11:56:20 +01:00
TESTING.md DEV: replace mailcatcher references with mailhog (#14500) 2021-10-05 15:48:06 +05:30
TROUBLESHOOTING.md for docs, normalize on space after code fence when specifying lang 2019-01-21 01:19:28 -08:00