Fixing widget publishing upon initial creation.

This fixes the case where a widget is not published when it's first created.
This commit is contained in:
Sipke Schoorstra
2014-08-10 23:39:04 -07:00
parent fdeae4e583
commit 04f30ccd29

View File

@@ -170,11 +170,25 @@ namespace Orchard.Widgets.Controllers {
}
[HttpPost, ActionName("AddWidget")]
public ActionResult AddWidgetPOST([Bind(Prefix = "WidgetPart.LayerId")] int layerId, string widgetType, string returnUrl) {
[FormValueRequired("submit.Save")]
public ActionResult AddWidgetSavePOST([Bind(Prefix = "WidgetPart.LayerId")] int layerId, string widgetType, string returnUrl) {
return AddWidgetPOST(layerId, widgetType, returnUrl, contentItem => {
if (!contentItem.Has<IPublishingControlAspect>() && !contentItem.TypeDefinition.Settings.GetModel<ContentTypeSettings>().Draftable)
Services.ContentManager.Publish(contentItem);
});
}
[HttpPost, ActionName("AddWidget")]
[FormValueRequired("submit.Publish")]
public ActionResult AddWidgetPublishPOST([Bind(Prefix = "WidgetPart.LayerId")] int layerId, string widgetType, string returnUrl) {
return AddWidgetPOST(layerId, widgetType, returnUrl, contentItem => Services.ContentManager.Publish(contentItem));
}
private ActionResult AddWidgetPOST([Bind(Prefix = "WidgetPart.LayerId")] int layerId, string widgetType, string returnUrl, Action<ContentItem> conditionallyPublish) {
if (!IsAuthorizedToManageWidgets())
return new HttpUnauthorizedResult();
WidgetPart widgetPart = _widgetsService.CreateWidget(layerId, widgetType, "", "", "");
var widgetPart = _widgetsService.CreateWidget(layerId, widgetType, "", "", "");
if (widgetPart == null)
return HttpNotFound();
@@ -182,6 +196,7 @@ namespace Orchard.Widgets.Controllers {
try {
// override the CommonPart's persisting of the current container
widgetPart.LayerPart = _widgetsService.GetLayer(layerId);
conditionallyPublish(widgetPart.ContentItem);
}
catch (Exception exception) {
Logger.Error(T("Creating widget failed: {0}", exception.Message).Text);
@@ -332,7 +347,7 @@ namespace Orchard.Widgets.Controllers {
});
}
public ActionResult EditWidgetPOST(int id, int layerId, string returnUrl, Action<ContentItem> conditionallyPublish) {
private ActionResult EditWidgetPOST(int id, int layerId, string returnUrl, Action<ContentItem> conditionallyPublish) {
if (!IsAuthorizedToManageWidgets())
return new HttpUnauthorizedResult();