discourse/app
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
..
assets DEV: Introduce a value transformer front-end plugin API (#27090) 2024-06-12 15:21:52 -03:00
controllers FIX: fix Webhook events filter 'loadMore' not taking params (#27403) 2024-06-11 20:17:47 -05:00
helpers DEV: Remove duplicate definition of RTL locales and add Uyghur to the list (#27387) 2024-06-08 21:24:39 +02:00
jobs FIX: `Jobs::EnsureS3UploadsExistence` broken for multisite (#27401) 2024-06-10 16:26:39 +08:00
mailers FIX: correctly compute the window for email summaries 2024-05-27 22:33:51 +02:00
models FIX: Use the proper i18n argument name 2024-06-12 11:11:02 +02:00
serializers UX: Show message and chat buttons on hidden profiles (#27326) 2024-06-10 10:38:22 -03:00
services FIX: Message for bulk closing topics silently (#27400) 2024-06-11 09:36:54 +10:00
views FIX: send activity summaries based on "last seen" (#27035) 2024-05-22 10:23:03 +02:00