# DiscourseプラグインAPIの変更: addPostMenuButtonとcomponent:topic-listに対してapi.registerValueTransformerを使用する

**URL:** <https://meta.discourse.org/t/discourse-plugin-api-changes-using-api-registervaluetransformer-for-addpostmenubutton-and-component-topic-list/357240>\
**Category:** Development\
**Created:** [2025 年 3 月 14 日午前 6:16 UTC](https://meta.discourse.org/t/discourse-plugin-api-changes-using-api-registervaluetransformer-for-addpostmenubutton-and-component-topic-list/357240 "2025-03-14T06:16:53Z")\
**Posts on this page:** 1\
**Showing post:** 1

<div class="post-metadata">

**Author:** ![omppatil](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/omppatil/32/359876_2.png) [@omppatil](https://meta.discourse.org/u/omppatil)\
**Post date:** [2025 年 3 月 14 日午前 6:16 UTC](https://meta.discourse.org/t/discourse-plugin-api-changes-using-api-registervaluetransformer-for-addpostmenubutton-and-component-topic-list/357240/1 "2025-03-14T06:16:53Z")

</div>

{“content”: “こんにちは、私はローカル開発用にバージョン3.2.0.beta4-devを使用しており、プラグインAPIのバージョンは0.8.7です。ただし、最近のDiscourseの変更により、`addPostMenuButton`と`component:topic-list`関数が変更されました。\n\nこれらのAPI関数に対して`api.registerValueTransformer`をどのように使用すればよいですか？また、`api.registerValueTransformer`に互換性のあるバージョンのプラグインAPIを使用するには、どのバージョンを選べばよいですか？\n\nこちらは`addPostMenuButton`のコードです：\n`\napi.addPostMenuButton("togglePostButton", (model) => {\n const siteSettings = api.container.lookup("site-settings:main");\n const posts = siteSettings.posts;\n const array_of_posts = posts.split("|");\n const postId = model.id;\n const postIdstr = postId.toString();\n const isPost = array_of_posts.includes(postIdstr);\n\n return {\n action: "togglePost",\n position: "first",\n className: isPost\n ? "button.topic_hidden custom-class-hidden"\n : "button.topic_visible custom-class-visible",\n icon: isPost ? "far-eye-slash" : "far-eye",\n title: isPost ? "Hide Post" : "Show Post",\n };\n});\n`\nこちらは`component:topic-list`のコードです：\n`\napi.modifyClass("component:topic-list", {\n pluginId: "post-toggle",\n didInsertElement: function () {\n this._super();\n const topics = this.topics;\n for (let key in topics) {\n if (topics.hasOwnProperty(key)) {\n let newTopicLatest = [];\n const topic_id = topics[key].id;\n const topic_posters = topics[key].posters;\n\n topic_posters.forEach((poster) => {\n if (poster && poster.extras !== null && poster.extras.includes("latest")) {\n newTopicLatest = poster["description"].split(",");\n }\n });\n\n let userListLatest = newTopicLatest;\n if (userListLatest.length > 1 && userListLatest[0] === "Original Poster") {\n userListLatest = userListLatest.slice(1);\n userListLatest[0] = userListLatest[0].trim();\n }\n\n let i = 0;\n const element = $('tr[data-topic-id="' + topic_id + '"]').find(\n "a[data-user-card]"\n );\n\n if (element.length > 0) {\n element.each(function () {\n const poster_inside = topic_posters[i];\n if (poster_inside !== undefined && Object.keys(poster_inside).length !== 0) {\n const userElement = $(this);\n if (!userListLatest.includes(poster_inside.user.id.toString())) {\n userElement.hide();\n }\n }\n i++;\n });\n }\n }\n }\n }\n});\n`\n誰か助けてくれますか？”}

---

_[View the full topic](https://meta.discourse.org/t/discourse-plugin-api-changes-using-api-registervaluetransformer-for-addpostmenubutton-and-component-topic-list/357240)._
