diff --git a/app/assets/javascripts/discourse/app/lib/show-modal.js b/app/assets/javascripts/discourse/app/lib/show-modal.js index 6a6fb17a71b..bc409f0f8f2 100644 --- a/app/assets/javascripts/discourse/app/lib/show-modal.js +++ b/app/assets/javascripts/discourse/app/lib/show-modal.js @@ -1,13 +1,17 @@ import I18n from "I18n"; import { dasherize } from "@ember/string"; +let _container; +export function setModalContainer(container) { + _container = container; +} + export default function(name, opts) { opts = opts || {}; - const container = Discourse.__container__; // We use the container here because modals are like singletons // in Discourse. Only one can be shown with a particular state. - const route = container.lookup("route:application"); + const route = _container.lookup("route:application"); const modalController = route.controllerFor("modal"); modalController.set( @@ -18,7 +22,7 @@ export default function(name, opts) { const controllerName = opts.admin ? `modals/${name}` : name; modalController.set("name", controllerName); - let controller = container.lookup("controller:" + controllerName); + let controller = _container.lookup("controller:" + controllerName); const templateName = opts.templateName || dasherize(name); const renderArgs = { into: "modal", outlet: "modalBody" }; @@ -27,7 +31,7 @@ export default function(name, opts) { } else { // use a basic controller renderArgs.controller = "basic-modal-body"; - controller = container.lookup(`controller:${renderArgs.controller}`); + controller = _container.lookup(`controller:${renderArgs.controller}`); } if (opts.addModalBodyView) { diff --git a/app/assets/javascripts/discourse/app/pre-initializers/discourse-bootstrap.js b/app/assets/javascripts/discourse/app/pre-initializers/discourse-bootstrap.js index 1f209bee96c..3cfabb5a201 100644 --- a/app/assets/javascripts/discourse/app/pre-initializers/discourse-bootstrap.js +++ b/app/assets/javascripts/discourse/app/pre-initializers/discourse-bootstrap.js @@ -13,6 +13,7 @@ import deprecated from "discourse-common/lib/deprecated"; import { setIconList } from "discourse-common/lib/icon-library"; import { setPluginContainer } from "discourse/lib/plugin-api"; import { setURLContainer } from "discourse/lib/url"; +import { setModalContainer } from "discourse/lib/show-modal"; export default { name: "discourse-bootstrap", @@ -21,6 +22,7 @@ export default { initialize(container, app) { setPluginContainer(container); setURLContainer(container); + setModalContainer(container); // Our test environment has its own bootstrap code if (isTesting()) { diff --git a/test/javascripts/helpers/qunit-helpers.js b/test/javascripts/helpers/qunit-helpers.js index 8be26c06409..70f8a27d0f3 100644 --- a/test/javascripts/helpers/qunit-helpers.js +++ b/test/javascripts/helpers/qunit-helpers.js @@ -29,6 +29,7 @@ import { currentSettings, mergeSettings } from "helpers/site-settings"; import { getOwner } from "discourse-common/lib/get-owner"; import { setTopicList } from "discourse/lib/topic-list-tracker"; import { setURLContainer } from "discourse/lib/url"; +import { setModalContainer } from "discourse/lib/show-modal"; export function currentUser() { return User.create(sessionFixtures["/session/current.json"].current_user); @@ -176,6 +177,7 @@ export function acceptance(name, options) { this.container = getOwner(this); setPluginContainer(this.container); setURLContainer(this.container); + setModalContainer(this.container); if (options.beforeEach) { options.beforeEach.call(this); } @@ -205,6 +207,7 @@ export function acceptance(name, options) { setTopicList(null); _clearSnapshots(); setURLContainer(null); + setModalContainer(null); Discourse._runInitializer( "instanceInitializers", (initName, initializer) => {