Skip to content

Commit

Permalink
Added unpublish button to edit widget (shown if widget is draftable o…
Browse files Browse the repository at this point in the history
…nly)
  • Loading branch information
AndreaPiovanelli committed Oct 18, 2022
1 parent 6428a90 commit cff5db9
Showing 1 changed file with 9 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,22 +36,27 @@ protected override DriverResult Editor(WidgetPart widgetPart, dynamic shapeHelpe
() => shapeHelper.EditorTemplate(TemplateName: "Parts.Widgets.WidgetPart", Model: widgetPart, Prefix: Prefix))
};

if (widgetPart.Id > 0 && widgetPart.TypeDefinition.Settings.GetModel<ContentTypeSettings>().Draftable) {
results.Add(ContentShape("Content_UnpublishButton",
unpublishButton => unpublishButton));
}

return Combined(results.ToArray());
}

protected override DriverResult Editor(WidgetPart widgetPart, IUpdateModel updater, dynamic shapeHelper) {
updater.TryUpdateModel(widgetPart, Prefix, null, null);

if(string.IsNullOrWhiteSpace(widgetPart.Title)) {
if (string.IsNullOrWhiteSpace(widgetPart.Title)) {
updater.AddModelError("Title", T("Title can't be empty."));
}

// if there is a name, ensure it's unique
if(!string.IsNullOrWhiteSpace(widgetPart.Name)) {
if (!string.IsNullOrWhiteSpace(widgetPart.Name)) {
widgetPart.Name = widgetPart.Name.ToHtmlName();

var widgets = _contentManager.Query<WidgetPart, WidgetPartRecord>().Where(x => x.Name == widgetPart.Name && x.Id != widgetPart.Id).Count();
if(widgets > 0) {
if (widgets > 0) {
updater.AddModelError("Name", T("A Widget with the same Name already exists."));
}
}
Expand Down

0 comments on commit cff5db9

Please sign in to comment.