# \[Solved\] In plugin: opening the composer without changing the route

**URL:** https://meta.discourse.org/t/solved-in-plugin-opening-the-composer-without-changing-the-route/67710
**Category:** Development
**Created:** [2017年八月9日 12:02 UTC](https://meta.discourse.org/t/solved-in-plugin-opening-the-composer-without-changing-the-route/67710 "2017-08-09T12:02:07Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![jack2](https://avatars.discourse-cdn.com/v4/letter/j/ac91a4/32.png) [@jack2](https://meta.discourse.org/u/jack2)
#### Post date: [2017年八月9日 12:02 UTC](https://meta.discourse.org/t/solved-in-plugin-opening-the-composer-without-changing-the-route/67710/1 "2017-08-09T12:02:07Z")

</div>

I would like to open the composer from my plugin. But I cannot use the [composing a new pre-filled topic via URL](https://meta.discourse.org/t/compose-a-new-pre-filled-topic-via-url/28074) method, because I don’t want to change the route.

I’ve tried the method explained [here](https://meta.discourse.org/t/client-side-hooks-and-functions/38397/4), but it doesn’t seem to work. I’ve tried to send the `composer:opened` event to other objects (router, application route, application controller, composer controller) but without any success.

I’ve been more successful with the method described [here](https://meta.discourse.org/t/how-to-open-composer-with-prefilled-content/13801), using this kind of code:

```javascript
container.lookup('controller:composer').open({			
	action: Composer.CREATE_TOPIC,
	draftKey: 'new_topic'
})

```

The composer opens correctly, but:

- the preview pane doesn’t seem to work
- I get the following errors in the console:

```plaintext
Uncaught SyntaxError: Unexpected token < markdown-it-bundle.js:1
Error: Could not find module pretty-text/engines/discourse-markdown/helpers discourse/lib/text:40 
    at missingModule (discourse-loader:134)
    at require (discourse-loader:149)
    at setup (pretty-text/engines/discourse-markdown-it:242)
    at buildOptions (pretty-text/pretty-text:100)
    at getOpts (discourse/lib/text:25)
    at cook (discourse/lib/text:30)
    at eval (discourse/lib/text:38)
    at tryCatch (ember:50180)
    at invokeCallback (ember:50195)
    at publish (ember:50163)

```

Any idea?

---

<div class="post-metadata">

### Author: ![zogstrip](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/zogstrip/32/512781_2.png) [@zogstrip](https://meta.discourse.org/u/zogstrip)
#### Post date: [2017年八月9日 14:25 UTC](https://meta.discourse.org/t/solved-in-plugin-opening-the-composer-without-changing-the-route/67710/2 "2017-08-09T14:25:13Z")

</div>

You need to use the `api.modifyClass` plugin api in an initializer

```javascript
withPluginApi("0.8", api => {
  api.modifyClass("controller:composer", {
    action: Composer.CREATE_TOPIC,
   draftKey: 'new_topic'
  });
});

```

---

<div class="post-metadata">

### Author: ![jack2](https://avatars.discourse-cdn.com/v4/letter/j/ac91a4/32.png) [@jack2](https://meta.discourse.org/u/jack2)
#### Post date: [2017年八月9日 19:23 UTC](https://meta.discourse.org/t/solved-in-plugin-opening-the-composer-without-changing-the-route/67710/3 "2017-08-09T19:23:40Z")

</div>

Thanks a lot @zogstrip.

Your code runs correctly but the composer doesn’t show up. Additionally, I get the following warning in the console:

```plaintext
"controller:composer" was already cached in the container. Changes won't be applied.

```

Does it makes sense to you?

---

<div class="post-metadata">

### Author: ![zogstrip](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/zogstrip/32/512781_2.png) [@zogstrip](https://meta.discourse.org/u/zogstrip)
#### Post date: [2017年八月9日 19:40 UTC](https://meta.discourse.org/t/solved-in-plugin-opening-the-composer-without-changing-the-route/67710/4 "2017-08-09T19:40:55Z")

</div>

It does, I added that warning yesterday because I got bitten by it.

It means that you (or another plugin) have previously called `container.lookup("controller:composer")` which cached the instance of the composer controller on the container and any changes made to the composer class (through `modifyClass` or `reopen`) won’t apply.

If you did the `lookup`, then you need to move the `modifyClass` **before** it.  
If you didn’t, you need to put your initializer **before** the one calling it.

---

<div class="post-metadata">

### Author: ![jack2](https://avatars.discourse-cdn.com/v4/letter/j/ac91a4/32.png) [@jack2](https://meta.discourse.org/u/jack2)
#### Post date: [2017年八月9日 21:01 UTC](https://meta.discourse.org/t/solved-in-plugin-opening-the-composer-without-changing-the-route/67710/5 "2017-08-09T21:01:00Z")

</div>

Thanks, got it, I’ve fixed the warning.  
However, I’ve just realized the markdown error is not linked to me wanting to open the composer from my plugin. I’m ashamed I didn’t check earlier, but the problem occurs also when creating a new topic using Discourse UI.  
I’m about to report this issue in another topic, so that people landing here are not too confused.  
EDIT: [here](https://meta.discourse.org/t/dev-instance-topic-preview-not-working/67738) is the new topic.
