Skip to content

Commit 86a69d7

Browse files
committed
DEV: Use new addSaveableUserField plugin API
Simplify preference saving by using the new `addSaveableUserField(name, { page: "emails" })` API. This replaces manual value transformer registration and backward compatibility code with a single declarative API call. cf. discourse/discourse#36757
1 parent bfd5468 commit 86a69d7

File tree

2 files changed

+4
-28
lines changed

2 files changed

+4
-28
lines changed

.discourse-compatibility

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
< 3.6.0.beta3-dev: bfd5468a8b5290f1d2eb3c83a8659615ed9a6ba0
12
< 3.6.0.beta1-dev: 93efc23f23a15db8974d18ab3c5256a9f4ee7b32
23
< 3.5.0.beta5-dev: 29c34a083dae6f8ab62ce71a7cf7b027a54a7ac8
34
< 3.5.0.beta1-dev: 68ad17e19c5f13e9f3984b9345739362460a3a4e
Lines changed: 3 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,18 @@
11
import { withPluginApi } from "discourse/lib/plugin-api";
2-
import { VALUE_TRANSFORMERS } from "discourse/lib/transformer/registry";
32

43
export default {
54
name: "discourse-newsletter-integration-setup",
65

76
initialize() {
87
withPluginApi((api) => {
9-
const currentUser = api.getCurrentUser();
10-
if (!currentUser) {
8+
if (!api.getCurrentUser()) {
119
return;
1210
}
1311

1412
api.addSaveableUserField(
15-
"newsletter_integration_subscribe_global_newsletter"
13+
"newsletter_integration_subscribe_global_newsletter",
14+
{ page: "emails" }
1615
);
17-
18-
if (VALUE_TRANSFORMERS.includes("preferences-save-attributes")) {
19-
api.registerValueTransformer(
20-
"preferences-save-attributes",
21-
({ value: attrs, context }) => {
22-
if (context.page === "emails") {
23-
attrs.push("newsletter_integration_subscribe_global_newsletter");
24-
}
25-
return attrs;
26-
}
27-
);
28-
} else {
29-
// Backward compatibility for older Discourse versions
30-
api.modifyClass("controller:preferences/emails", {
31-
pluginId: "discourse-newsletter-integration-emails-preference",
32-
33-
init() {
34-
this._super(...arguments);
35-
this.saveAttrNames.push(
36-
"newsletter_integration_subscribe_global_newsletter"
37-
);
38-
},
39-
});
40-
}
4116
});
4217
},
4318
};

0 commit comments

Comments
 (0)