From da6edc117cd7fcb27390a2a1b4a071c3a601e57d Mon Sep 17 00:00:00 2001 From: David Taylor Date: Tue, 13 Apr 2021 15:05:46 +0100 Subject: [PATCH] FIX: Allow raw-view classes to be resolved from themes/plugins (#12685) Since cd24eff5d98e74db4afe0257e4d9de1ad2556c5d, theme modules are now prefixed with the theme id. Therefore themes which defined raw-view classes will be broken This commit updates the `raw` helper to use the resolver for looking up the view class. This automatically takes care of trying theme/plugin paths in addition to core paths. --- .../javascripts/discourse/app/helpers/raw.js | 24 ++++++++++++++----- 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/app/assets/javascripts/discourse/app/helpers/raw.js b/app/assets/javascripts/discourse/app/helpers/raw.js index b34a0fc10a6..c9dd07f8b4f 100644 --- a/app/assets/javascripts/discourse/app/helpers/raw.js +++ b/app/assets/javascripts/discourse/app/helpers/raw.js @@ -2,6 +2,20 @@ import { helperContext, registerUnbound } from "discourse-common/lib/helpers"; import { findRawTemplate } from "discourse-common/lib/raw-templates"; import { htmlSafe } from "@ember/template"; import { RUNTIME_OPTIONS } from "discourse-common/lib/raw-handlebars-helpers"; +import { buildResolver } from "discourse-common/resolver"; + +let resolver; + +function lookupView(templateName) { + if (!resolver) { + resolver = buildResolver("discourse").create(); + } + + return resolver.customResolve({ + type: "raw-view", + fullNameWithoutType: templateName, + }); +} function renderRaw(ctx, template, templateName, params) { params = jQuery.extend({}, params); @@ -9,12 +23,10 @@ function renderRaw(ctx, template, templateName, params) { let context = helperContext(); if (!params.view) { - const module = `discourse/raw-views/${templateName}`; - if (requirejs.entries[module]) { - const viewClass = requirejs(module, null, null, true); - if (viewClass && viewClass.default) { - params.view = viewClass.default.create(params, context); - } + const viewClass = lookupView(templateName); + + if (viewClass) { + params.view = viewClass.create(params, context); } if (!params.view) {