Closed drpeck closed 6 years ago
Correction - it doesn't prevent saving, but it does throw the exception on every save
I have a workaround for this, but not sure if it is too hacky for inclusion. Can provide a PR if it is wanted.
angular.module('umbraco.services').config([
'$httpProvider',
function ($httpProvider) {
//Prevent macros throwing an error in Fluidity
$httpProvider.interceptors.push(function ($q) {
return {
'request': function (request) {
var pageId;
// If this is a call to get the macro HTML
if (request.url === "/umbraco/backoffice/UmbracoApi/Macro/GetMacroResultAsHtmlForEditor") {
pageId = request.data.pageId || "";
if (0 <= pageId.indexOf("!")) {
request.url = "/umbraco/backoffice/fluidity/Macro/GetMacroResultAsHtmlForEditor";
}
}
return request || $q.when(request);
}
};
});
}]);
--interceptor.js
[PluginController("fluidity")]
public class MacroController : UmbracoAuthorizedJsonController, IRequiresSessionState
{
[HttpGet]
public new HttpResponseMessage GetMacroResultAsHtmlForEditor(string macroAlias, string pageId, [FromUri] IDictionary<string, object> macroParams)
{
var wrappedController = WrappedController();
var pageIdInt = PageId(pageId);
return wrappedController.GetMacroResultAsHtmlForEditor(macroAlias, pageIdInt, macroParams);
}
[HttpPost]
public new HttpResponseMessage GetMacroResultAsHtmlForEditor(FluidityMacroParameterModel model)
{
var wrappedController = WrappedController();
var pageIdInt = PageId(model.PageId);
var baseModel = model.ToBaseModel(pageIdInt);
return wrappedController.GetMacroResultAsHtmlForEditor(baseModel);
}
private int PageId(string fluidityPageId)
{
if (int.TryParse(fluidityPageId, out var pageIdInt) == false)
pageIdInt = UmbracoContext.ContentCache.GetAtRoot().FirstOrDefault()?.Id ?? throw new InvalidOperationException("Macros in Fluidity are only supported when there is some content added in the content tree");
return pageIdInt;
}
private Umbraco.Web.Editors.MacroController WrappedController()
{
return new Umbraco.Web.Editors.MacroController
{
ActionContext = this.ActionContext,
ControllerContext = this.ControllerContext
};
}
public class FluidityMacroParameterModel
{
public string MacroAlias { get; set; }
public string PageId { get; set; }
public IDictionary<string, object> MacroParams { get; set; }
public Umbraco.Web.Editors.MacroController.MacroParameterModel ToBaseModel(int pageId)
{
return new Umbraco.Web.Editors.MacroController.MacroParameterModel
{
MacroAlias = this.MacroAlias,
PageId = pageId,
MacroParams = this.MacroParams,
};
}
}
}
--API controller
@drpeck glad that you found a workaround, but I think I might just have to log this as a known issue as I don't think a reasonable solution can be found. Thanks for raising the issue though 👍
One question, do you get the error if you disable previewing in RTE on the macro config?
Yes, you do.
From: Matt Brailsford notifications@github.com Sent: Wednesday, October 31, 2018 2:31:29 PM To: umco/umbraco-fluidity Cc: David Peck; Mention Subject: Re: [umco/umbraco-fluidity] Macros don't work in the RTE (#68)
One question, do you get the error if you disable previewing in RTE on the macro config?
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHubhttps://github.com/umco/umbraco-fluidity/issues/68#issuecomment-434709314, or mute the threadhttps://github.com/notifications/unsubscribe-auth/ABJAD1QDoibr0RDdu0nB-cmKBonL12Efks5uqbRBgaJpZM4WRVIW.
Ok, cool, I'll update the known issues to say Macros don't work at all in RTE's then 👍
I do have them working to be clear, but it required hacking the controllers through angular injectors. Also the render macro functions don't work without their being a current page so that required done further hacking.
The known issues list is probably most appropriate.
From: Matt Brailsford notifications@github.com Sent: Wednesday, October 31, 2018 4:20:10 PM To: umco/umbraco-fluidity Cc: David Peck; Mention Subject: Re: [umco/umbraco-fluidity] Macros don't work in the RTE (#68)
Ok, cool, I'll update the known issues to say Macros don't work at all in RTE's then 👍
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHubhttps://github.com/umco/umbraco-fluidity/issues/68#issuecomment-434748795, or mute the threadhttps://github.com/notifications/unsubscribe-auth/ABJAD0aoHr7vT882I5X91L15aIGE4hvfks5uqc25gaJpZM4WRVIW.
Yup, understood. People can find this if they really need them to work, but yea, I think it's a bit too brute force to become core code so I think the known issues list is the best place for it.
Thanks for the input 👍
On Wed, 31 Oct 2018, 4:32 pm David Peck <notifications@github.com wrote:
I do have them working to be clear, but it required hacking the controllers through angular injectors. Also the render macro functions don't work without their being a current page so that required done further hacking.
The known issues list is probably most appropriate.
From: Matt Brailsford notifications@github.com Sent: Wednesday, October 31, 2018 4:20:10 PM To: umco/umbraco-fluidity Cc: David Peck; Mention Subject: Re: [umco/umbraco-fluidity] Macros don't work in the RTE (#68)
Ok, cool, I'll update the known issues to say Macros don't work at all in RTE's then 👍
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub< https://github.com/umco/umbraco-fluidity/issues/68#issuecomment-434748795>, or mute the thread< https://github.com/notifications/unsubscribe-auth/ABJAD0aoHr7vT882I5X91L15aIGE4hvfks5uqc25gaJpZM4WRVIW>.
— You are receiving this because you modified the open/close state. Reply to this email directly, view it on GitHub https://github.com/umco/umbraco-fluidity/issues/68#issuecomment-434752911, or mute the thread https://github.com/notifications/unsubscribe-auth/AAgLyZ5JfjR8cakHqPxjF80x9sptIzQVks5uqdCLgaJpZM4WRVIW .
I presume because the pageId includes the collection name, you get an error adding macros to an RTE which prevents saving