# 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:** [3월 14, 2025, 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:** 5
**Page:** 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: [3월 14, 2025, 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>

안녕하세요, 로컬 개발에는 3.2.0.beta4-dev 버전을, 플러그인 개발에는 플러그인 API 0.8.7 버전을 사용하고 있습니다. 그러나 최근 Discourse의 변경 사항으로 인해 `addPostMenuButton`와 `component:topic-list` 함수가 수정되었습니다.

이러한 API 함수에 `api.registerValueTransformer`를 어떻게 사용할 수 있을까요? 또한 `api.registerValueTransformer`와의 호환성을 보장하기 위해 3.2.0.beta4-dev와 매칭되는 플러그인 API 버전은 어느 것이어야 할까요?

다음은 제 `addPostMenuButton` 코드입니다:

```plaintext
api.addPostMenuButton("togglePostButton", (model) => {
  const siteSettings = api.container.lookup("site-settings:main");
  const posts = siteSettings.posts;
  const array_of_posts = posts.split("|");
  const postId = model.id;
  const postIdstr = postId.toString();
  const isPost = array_of_posts.includes(postIdstr);

  return {
    action: "togglePost",
    position: "first",
    className: isPost
      ? "button.topic_hidden custom-class-hidden"
      : "button.topic_visible custom-class-visible",
    icon: isPost ? "far-eye-slash" : "far-eye",
    title: isPost ? "Hide Post" : "Show Post",
  };
});

```

그리고 `component:topic-list`를 위한 제 코드는 다음과 같습니다:

```plaintext
api.modifyClass("component:topic-list", {
  pluginId: "post-toggle",
  didInsertElement: function () {
    this._super();
    const topics = this.topics;
    for (let key in topics) {
      if (topics.hasOwnProperty(key)) {
        let newTopicLatest = [];
        const topic_id = topics[key].id;
        const topic_posters = topics[key].posters;

        topic_posters.forEach((poster) => {
          if (poster && poster.extras !== null && poster.extras.includes("latest")) {
            newTopicLatest = poster["description"].split(",");
          }
        });

        let userListLatest = newTopicLatest;
        if (userListLatest.length > 1 && userListLatest[0] === "Original Poster") {
          userListLatest = userListLatest.slice(1);
          userListLatest[0] = userListLatest[0].trim();
        }

        let i = 0;
        const element = $('tr[data-topic-id="' + topic_id + '"]').find(
          "a[data-user-card]"
        );

        if (element.length > 0) {
          element.each(function () {
            const poster_inside = topic_posters[i];
            if (poster_inside !== undefined && Object.keys(poster_inside).length !== 0) {
              const userElement = $(this);
              if (!userListLatest.includes(poster_inside.user.id.toString())) {
                userElement.hide();
              }
            }
            i++;
          });
        }
      }
    }
  }
});

```

이 부분에 대해 도움을 주실 수 있을까요?

---

<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: [3월 14, 2025, 11:23오전 UTC](https://meta.discourse.org/t/discourse-plugin-api-changes-using-api-registervaluetransformer-for-addpostmenubutton-and-component-topic-list/357240/2 "2025-03-14T11:23:17Z")

</div>

로컬 개발용 Discourse를 3.5.0.beta2-dev 버전으로 업데이트했으며, 플러그인 API 버전은 2.1.1입니다. `addPostMenuButton`과 `component:topic-list` 함수에 `api.registerValueTransformer`를 어떻게 사용할 수 있나요?

---

<div class="post-metadata">

### Author: ![merefield](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/merefield/32/176214_2.png) [@merefield](https://meta.discourse.org/u/merefield)
#### Post date: [3월 14, 2025, 11:53오전 UTC](https://meta.discourse.org/t/discourse-plugin-api-changes-using-api-registervaluetransformer-for-addpostmenubutton-and-component-topic-list/357240/3 "2025-03-14T11:53:49Z")

</div>

해당 주제를 읽어보셨나요?: [Upcoming post menu changes - How to prepare themes and plugins](https://meta.discourse.org/t/upcoming-post-menu-changes-how-to-prepare-themes-and-plugins/341014?u=merefield)

---

<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: [3월 18, 2025, 6:16오전 UTC](https://meta.discourse.org/t/discourse-plugin-api-changes-using-api-registervaluetransformer-for-addpostmenubutton-and-component-topic-list/357240/4 "2025-03-18T06:16:02Z")

</div>

네, 해당 주제에 대해 읽었고, 새로운 플러그인 API 업데이트에 따라 변경 사항을 구현했으며, `component:topic-list`도 파악했습니다.

---

<div class="post-metadata">

### Author: ![system](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/system/32/443519_2.png) [@system](https://meta.discourse.org/u/system)
#### Post date: [4월 17, 2025, 6:16오전 UTC](https://meta.discourse.org/t/discourse-plugin-api-changes-using-api-registervaluetransformer-for-addpostmenubutton-and-component-topic-list/357240/5 "2025-04-17T06:16:37Z")

</div>

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
