# javascriptから"DiscourseEvent.on(:post\_created)"イベントに追加の'opts'データを追加できますか？

**URL:** <https://meta.discourse.org/t/adding-extra-opts-data-to-the-discourseevent-on-post-created-event-from-javascript/84889>\
**Category:** Development\
**Created:** [2018 年 4 月 9 日午後 4:05 UTC](https://meta.discourse.org/t/adding-extra-opts-data-to-the-discourseevent-on-post-created-event-from-javascript/84889 "2018-04-09T16:05:46Z")\
**Posts on this page:** 1\
**Showing post:** 10

<div class="post-metadata">

**Author:** ![angus](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/angus/32/341715_2.png) [@angus](https://meta.discourse.org/u/angus)\
**Post date:** [2018 年 4 月 11 日午後 10:48 UTC](https://meta.discourse.org/t/adding-extra-opts-data-to-the-discourseevent-on-post-created-event-from-javascript/84889/10 "2018-04-11T22:48:02Z")

</div>

Replace all of your code with this and it will work. I just tested it. Let me know if you have questions about specific parts.

Client

```plaintext
import Composer from 'discourse/models/composer';
import { withPluginApi } from 'discourse/lib/plugin-api';

export default {
  name: 'test-initializer',
  initialize() {
    Composer.serializeOnCreate('hide_devs', 'hideDevs');

    withPluginApi('0.8.12', api => {
      const user = api.getCurrentUser();

      user.findDetails().then(function() {
        const groups = user.get('groups');
        const inHideGroup = groups.find((g) => g.name == "hide_devs");

        if (inHideGroup) {
          api.modifyClass('model:composer', {
            hideDevs: false
          })

          api.onToolbarCreate(toolbar => {
            toolbar.addButton({
              id: "toggle-hide-devs-btn",
              group: "extras",
              icon: "user-secret",
              action: "toggleHideDevs"
            });
          });

          api.modifyClass('component:d-editor', {
            actions: {
              toggleHideDevs() {
                this.toggleProperty('outletArgs.composer.hideDevs');
              }
            }
          });
        }
      })
    })
  }
}

```

Server

```plaintext
# name: discourse-test
# about: test
# version: 1.0
# authors: Angus McLeod
# url: test.com

after_initialize do
   add_permitted_post_create_param('hide_devs')

   DiscourseEvent.on(:post_created) do |post, opts, user|
     puts "Hide devs: #{opts[:hide_devs]}"
   end
end

```

---

_[View the full topic](https://meta.discourse.org/t/adding-extra-opts-data-to-the-discourseevent-on-post-created-event-from-javascript/84889)._
