#7412: Cloning overrides for some content parts, including deep clone for records (Lombiq Technologies: ORCH-204) (#8854)

Co-authored-by: matteo.piovanelli <matteo.piovanelli@laser-group.com>
Co-authored-by: Gábor Domonkos <gabor.domonkos@lombiq.com>
This commit is contained in:
Benedek Farkas
2025-10-29 15:30:16 +01:00
committed by GitHub
parent d8537f14fb
commit 5b6edacbc7
37 changed files with 536 additions and 295 deletions

View File

@@ -4,13 +4,13 @@ using System.Web.Mvc;
using System.Xml; using System.Xml;
using Orchard.ContentManagement; using Orchard.ContentManagement;
using Orchard.ContentManagement.Drivers; using Orchard.ContentManagement.Drivers;
using Orchard.ContentManagement.Handlers;
using Orchard.Core.Common.Models; using Orchard.Core.Common.Models;
using Orchard.Core.Containers.Models; using Orchard.Core.Containers.Models;
using Orchard.Core.Containers.Services; using Orchard.Core.Containers.Services;
using Orchard.Core.Containers.Settings; using Orchard.Core.Containers.Settings;
using Orchard.Core.Containers.ViewModels; using Orchard.Core.Containers.ViewModels;
using Orchard.Localization; using Orchard.Localization;
using Orchard.ContentManagement.Handlers;
namespace Orchard.Core.Containers.Drivers { namespace Orchard.Core.Containers.Drivers {
public class ContainablePartDriver : ContentPartDriver<ContainablePart> { public class ContainablePartDriver : ContentPartDriver<ContainablePart> {
@@ -96,5 +96,9 @@ namespace Orchard.Core.Containers.Drivers {
protected override void Exporting(ContainablePart part, ExportContentContext context) { protected override void Exporting(ContainablePart part, ExportContentContext context) {
context.Element(part.PartDefinition.Name).SetAttributeValue("Position", part.Position); context.Element(part.PartDefinition.Name).SetAttributeValue("Position", part.Position);
} }
protected override void Cloning(ContainablePart originalPart, ContainablePart clonePart, CloneContentContext context) {
clonePart.Position = originalPart.Position;
}
} }
} }

View File

@@ -1,6 +1,7 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Web.Routing;
using System.Xml; using System.Xml;
using Orchard.ContentManagement; using Orchard.ContentManagement;
using Orchard.ContentManagement.Drivers; using Orchard.ContentManagement.Drivers;
@@ -11,12 +12,11 @@ using Orchard.Core.Common.Models;
using Orchard.Core.Containers.Models; using Orchard.Core.Containers.Models;
using Orchard.Core.Containers.Services; using Orchard.Core.Containers.Services;
using Orchard.Core.Containers.ViewModels; using Orchard.Core.Containers.ViewModels;
using Orchard.Localization;
using Orchard.UI.Notify;
using System.Web.Routing;
using Orchard.Settings;
using Orchard.Core.Feeds; using Orchard.Core.Feeds;
using Orchard.Localization;
using Orchard.Settings;
using Orchard.UI.Navigation; using Orchard.UI.Navigation;
using Orchard.UI.Notify;
namespace Orchard.Core.Containers.Drivers { namespace Orchard.Core.Containers.Drivers {
public class ContainerPartDriver : ContentPartDriver<ContainerPart> { public class ContainerPartDriver : ContentPartDriver<ContainerPart> {
@@ -57,7 +57,7 @@ namespace Orchard.Core.Containers.Drivers {
var metadata = container.ContentManager.GetItemMetadata(container); var metadata = container.ContentManager.GetItemMetadata(container);
if (metadata != null) { if (metadata != null) {
_feedManager.Register(metadata.DisplayText, "rss", new RouteValueDictionary {{"containerid", container.Id}}); _feedManager.Register(metadata.DisplayText, "rss", new RouteValueDictionary { { "containerid", container.Id } });
} }
// Retrieving pager parameters. // Retrieving pager parameters.
@@ -179,5 +179,17 @@ namespace Orchard.Core.Containers.Drivers {
context.Element(part.PartDefinition.Name).SetAttributeValue("AdminMenuImageSet", part.AdminMenuImageSet); context.Element(part.PartDefinition.Name).SetAttributeValue("AdminMenuImageSet", part.AdminMenuImageSet);
context.Element(part.PartDefinition.Name).SetAttributeValue("ItemCount", part.ItemCount); context.Element(part.PartDefinition.Name).SetAttributeValue("ItemCount", part.ItemCount);
} }
protected override void Cloning(ContainerPart originalPart, ContainerPart clonePart, CloneContentContext context) {
clonePart.ItemContentTypes = originalPart.ItemContentTypes;
clonePart.ItemsShown = originalPart.ItemsShown;
clonePart.Paginated = originalPart.Paginated;
clonePart.PageSize = originalPart.PageSize;
clonePart.ShowOnAdminMenu = originalPart.ShowOnAdminMenu;
clonePart.AdminMenuText = originalPart.AdminMenuText;
clonePart.AdminMenuPosition = originalPart.AdminMenuPosition;
clonePart.AdminMenuImageSet = originalPart.AdminMenuImageSet;
clonePart.ItemCount = originalPart.ItemCount;
}
} }
} }

View File

@@ -436,15 +436,15 @@ namespace Orchard.Core.Contents.Controllers {
} }
[HttpPost] [HttpPost]
public ActionResult Clone(int id) { public ActionResult Clone(int id, string returnUrl) {
var originalContentItem = _contentManager.GetLatest(id); var originalContentItem = _contentManager.GetLatest(id);
if (!Services.Authorizer.Authorize(Permissions.ViewContent, originalContentItem, T("You do not have permission to view existing content."))) if (!Services.Authorizer.Authorize(Permissions.ViewContent, originalContentItem, T("You do not have permission to view existing content.")))
return new HttpUnauthorizedResult(); return new HttpUnauthorizedResult();
if (!Services.Authorizer.Authorize(Permissions.CreateContent, originalContentItem, T("Couldn't clone content"))) if (!Services.Authorizer.Authorize(Permissions.CreateContent, originalContentItem, T("Couldn't clone content")))
return new HttpUnauthorizedResult(); return new HttpUnauthorizedResult();
// pass a dummy content to the authorization check to check for "own" variations // pass a dummy content to the authorization check to check for "own" variations
var dummyContent = _contentManager.New(originalContentItem.ContentType); var dummyContent = _contentManager.New(originalContentItem.ContentType);
@@ -461,8 +461,13 @@ namespace Orchard.Core.Contents.Controllers {
? T("The content has been cloned as a draft.") ? T("The content has been cloned as a draft.")
: T("The {0} has been cloned as a draft.", originalContentItem.TypeDefinition.DisplayName)); : T("The {0} has been cloned as a draft.", originalContentItem.TypeDefinition.DisplayName));
var adminRouteValues = _contentManager.GetItemMetadata(cloneContentItem).AdminRouteValues; if (string.IsNullOrWhiteSpace(returnUrl)) {
return RedirectToRoute(adminRouteValues); var adminRouteValues = _contentManager.GetItemMetadata(cloneContentItem).AdminRouteValues;
return RedirectToRoute(adminRouteValues);
}
else {
return this.RedirectLocal(returnUrl, () => RedirectToAction("List"));
}
} }
[HttpPost] [HttpPost]

View File

@@ -6,7 +6,7 @@
@if (Authorizer.Authorize(Permissions.CreateContent, contentPart)) { @if (Authorizer.Authorize(Permissions.CreateContent, contentPart)) {
<ul class="action-links action-links-item"> <ul class="action-links action-links-item">
<li class="action-link"> <li class="action-link">
<a href="@Url.Action("Clone", "Admin", new { Id = Model.ContentItem.Id, ReturnUrl = Request.RawUrl, Area = "Contents" })" itemprop="UnsafeUrl">@T("Clone")</a> <a href="@Url.Action("Clone", "Admin", new { Id = Model.ContentItem.Id, Area = "Contents" })" itemprop="UnsafeUrl">@T("Clone")</a>
</li> </li>
</ul> </ul>
} }

View File

@@ -26,7 +26,7 @@
</li> </li>
} }
<li class="action-link"> <li class="action-link">
@Html.ActionLink(T("Clone").Text, "Clone", "Admin", new { Id = contentItem.Id, ReturnUrl = Request.RawUrl, Area = "Contents" }, new { itemprop = "UnsafeUrl" }) @Html.ActionLink(T("Clone").Text, "Clone", "Admin", new { Id = contentItem.Id, Area = "Contents" }, new { itemprop = "UnsafeUrl" })
</li> </li>
} }

View File

@@ -231,10 +231,12 @@ namespace Orchard.Core.Navigation.Controllers {
_contentManager.Create(contentItem); _contentManager.Create(contentItem);
menuPart.Menu = menu; menuPart.Menu = menu;
menuPart.MenuPosition = Position.GetNext(_navigationManager.BuildMenu(menu));
var model = _contentManager.UpdateEditor(contentItem, this); var model = _contentManager.UpdateEditor(contentItem, this);
// This needs to be called after UpdateEditor for INavigationFilters not to operate with stale data.
menuPart.MenuPosition = Position.GetNext(_navigationManager.BuildMenu(menu));
if (!ModelState.IsValid) { if (!ModelState.IsValid) {
_transactionManager.Cancel(); _transactionManager.Cancel();
return View(model); return View(model);

View File

@@ -1,6 +1,7 @@
using System; using System;
using Orchard.ContentManagement; using Orchard.ContentManagement;
using Orchard.ContentManagement.Drivers; using Orchard.ContentManagement.Drivers;
using Orchard.ContentManagement.Handlers;
using Orchard.Core.Navigation.Models; using Orchard.Core.Navigation.Models;
using Orchard.Core.Navigation.Settings; using Orchard.Core.Navigation.Settings;
using Orchard.Localization; using Orchard.Localization;
@@ -94,5 +95,11 @@ namespace Orchard.Core.Navigation.Drivers {
context.Element(part.PartDefinition.Name).SetAttributeValue("AdminMenuPosition", part.AdminMenuPosition); context.Element(part.PartDefinition.Name).SetAttributeValue("AdminMenuPosition", part.AdminMenuPosition);
context.Element(part.PartDefinition.Name).SetAttributeValue("OnAdminMenu", part.OnAdminMenu); context.Element(part.PartDefinition.Name).SetAttributeValue("OnAdminMenu", part.OnAdminMenu);
} }
protected override void Cloning(AdminMenuPart originalPart, AdminMenuPart clonePart, CloneContentContext context) {
clonePart.AdminMenuText = originalPart.AdminMenuText;
clonePart.AdminMenuPosition = originalPart.AdminMenuPosition;
clonePart.OnAdminMenu = originalPart.OnAdminMenu;
}
} }
} }

View File

@@ -1,5 +1,6 @@
using Orchard.ContentManagement; using Orchard.ContentManagement;
using Orchard.ContentManagement.Drivers; using Orchard.ContentManagement.Drivers;
using Orchard.ContentManagement.Handlers;
using Orchard.Core.Navigation.Models; using Orchard.Core.Navigation.Models;
using Orchard.Security; using Orchard.Security;
@@ -29,9 +30,7 @@ namespace Orchard.Core.Navigation.Drivers {
if (!_authorizationService.TryCheckAccess(Permissions.ManageMenus, currentUser, menu)) // tests if the current user has permissions to manage that specific menu if (!_authorizationService.TryCheckAccess(Permissions.ManageMenus, currentUser, menu)) // tests if the current user has permissions to manage that specific menu
return null; return null;
if (updater != null) { updater?.TryUpdateModel(part, Prefix, null, null);
updater.TryUpdateModel(part, Prefix, null, null);
}
return Editor(part, shapeHelper); return Editor(part, shapeHelper);
} }
@@ -50,5 +49,9 @@ namespace Orchard.Core.Navigation.Drivers {
protected override void Exporting(MenuItemPart part, ContentManagement.Handlers.ExportContentContext context) { protected override void Exporting(MenuItemPart part, ContentManagement.Handlers.ExportContentContext context) {
context.Element(part.PartDefinition.Name).SetAttributeValue("Url", part.Url); context.Element(part.PartDefinition.Name).SetAttributeValue("Url", part.Url);
} }
protected override void Cloning(MenuItemPart originalPart, MenuItemPart clonePart, CloneContentContext context) {
clonePart.Url = originalPart.Url;
}
} }
} }

View File

@@ -1,6 +1,7 @@
using System.Linq; using System.Linq;
using Orchard.ContentManagement; using Orchard.ContentManagement;
using Orchard.ContentManagement.Drivers; using Orchard.ContentManagement.Drivers;
using Orchard.ContentManagement.Handlers;
using Orchard.Core.Navigation.Models; using Orchard.Core.Navigation.Models;
using Orchard.Core.Navigation.Services; using Orchard.Core.Navigation.Services;
using Orchard.Core.Navigation.ViewModels; using Orchard.Core.Navigation.ViewModels;
@@ -17,8 +18,8 @@ namespace Orchard.Core.Navigation.Drivers {
private readonly IMenuService _menuService; private readonly IMenuService _menuService;
public MenuPartDriver( public MenuPartDriver(
IAuthorizationService authorizationService, IAuthorizationService authorizationService,
INavigationManager navigationManager, INavigationManager navigationManager,
IOrchardServices orchardServices, IOrchardServices orchardServices,
IMenuService menuService) { IMenuService menuService) {
_authorizationService = authorizationService; _authorizationService = authorizationService;
@@ -58,7 +59,7 @@ namespace Orchard.Core.Navigation.Drivers {
protected override DriverResult Editor(MenuPart part, IUpdateModel updater, dynamic shapeHelper) { protected override DriverResult Editor(MenuPart part, IUpdateModel updater, dynamic shapeHelper) {
var model = new MenuPartViewModel(); var model = new MenuPartViewModel();
if(updater.TryUpdateModel(model, Prefix, null, null)) { if (updater.TryUpdateModel(model, Prefix, null, null)) {
var menu = model.OnMenu ? _orchardServices.ContentManager.Get(model.CurrentMenuId) : null; var menu = model.OnMenu ? _orchardServices.ContentManager.Get(model.CurrentMenuId) : null;
if (!_authorizationService.TryCheckAccess(Permissions.ManageMenus, _orchardServices.WorkContext.CurrentUser, menu)) if (!_authorizationService.TryCheckAccess(Permissions.ManageMenus, _orchardServices.WorkContext.CurrentUser, menu))
@@ -103,7 +104,7 @@ namespace Orchard.Core.Navigation.Drivers {
protected override void Exporting(MenuPart part, ContentManagement.Handlers.ExportContentContext context) { protected override void Exporting(MenuPart part, ContentManagement.Handlers.ExportContentContext context) {
// is it on a menu ? // is it on a menu ?
if(part.Menu == null) { if (part.Menu == null) {
return; return;
} }
@@ -114,5 +115,11 @@ namespace Orchard.Core.Navigation.Drivers {
context.Element(part.PartDefinition.Name).SetAttributeValue("MenuText", part.MenuText); context.Element(part.PartDefinition.Name).SetAttributeValue("MenuText", part.MenuText);
context.Element(part.PartDefinition.Name).SetAttributeValue("MenuPosition", part.MenuPosition); context.Element(part.PartDefinition.Name).SetAttributeValue("MenuPosition", part.MenuPosition);
} }
protected override void Cloning(MenuPart originalPart, MenuPart clonePart, CloneContentContext context) {
clonePart.MenuText = originalPart.MenuText;
clonePart.MenuPosition = originalPart.MenuPosition;
clonePart.Menu = originalPart.Menu;
}
} }
} }

View File

@@ -11,7 +11,6 @@ using Orchard.Core.Title.Models;
using Orchard.Localization; using Orchard.Localization;
using Orchard.UI.Navigation; using Orchard.UI.Navigation;
using Orchard.Utility.Extensions; using Orchard.Utility.Extensions;
using Orchard.ContentManagement.Utilities;
namespace Orchard.Core.Navigation.Drivers { namespace Orchard.Core.Navigation.Drivers {
public class MenuWidgetPartDriver : ContentPartDriver<MenuWidgetPart> { public class MenuWidgetPartDriver : ContentPartDriver<MenuWidgetPart> {
@@ -41,10 +40,10 @@ namespace Orchard.Core.Navigation.Drivers {
} }
protected override DriverResult Display(MenuWidgetPart part, string displayType, dynamic shapeHelper) { protected override DriverResult Display(MenuWidgetPart part, string displayType, dynamic shapeHelper) {
return ContentShape( "Parts_MenuWidget", () => { return ContentShape("Parts_MenuWidget", () => {
var menu = _menuService.GetMenu(part.MenuContentItemId); var menu = _menuService.GetMenu(part.MenuContentItemId);
if(menu == null) { if (menu == null) {
return null; return null;
} }
@@ -57,9 +56,9 @@ namespace Orchard.Core.Navigation.Drivers {
} }
var localized = new List<MenuItem>(); var localized = new List<MenuItem>();
foreach(var menuItem in menuItems) { foreach (var menuItem in menuItems) {
// if there is no associated content, it as culture neutral // if there is no associated content, it as culture neutral
if(menuItem.Content == null) { if (menuItem.Content == null) {
localized.Add(menuItem); localized.Add(menuItem);
} }
@@ -73,7 +72,7 @@ namespace Orchard.Core.Navigation.Drivers {
var request = _workContextAccessor.GetContext().HttpContext.Request; var request = _workContextAccessor.GetContext().HttpContext.Request;
var routeData = request.RequestContext.RouteData; var routeData = request.RequestContext.RouteData;
var selectedPath = NavigationHelper.SetSelectedPath(menuItems, request, routeData); var selectedPath = NavigationHelper.SetSelectedPath(menuItems, request, routeData);
var menuShape = shapeHelper.Menu(); var menuShape = shapeHelper.Menu();
if (part.Breadcrumb) { if (part.Breadcrumb) {
@@ -135,9 +134,9 @@ namespace Orchard.Core.Navigation.Drivers {
} }
// limit the number of levels to display (down from and including the start level) // limit the number of levels to display (down from and including the start level)
if(part.Levels > 0) { if (part.Levels > 0) {
var current = topLevelItems.ToList(); var current = topLevelItems.ToList();
for (var i = 1; current.Any() && i < part.Levels; i++ ) { for (var i = 1; current.Any() && i < part.Levels; i++) {
var temp = new List<MenuItem>(); var temp = new List<MenuItem>();
foreach (var menuItem in current) { foreach (var menuItem in current) {
temp.AddRange(menuItem.Items); temp.AddRange(menuItem.Items);
@@ -147,7 +146,7 @@ namespace Orchard.Core.Navigation.Drivers {
// cut the sub-levels beneath any menu items that are at the lowest level being displayed // cut the sub-levels beneath any menu items that are at the lowest level being displayed
foreach (var menuItem in current) { foreach (var menuItem in current) {
menuItem.Items = Enumerable.Empty<MenuItem>(); menuItem.Items = Enumerable.Empty<MenuItem>();
} }
} }
menuItems = topLevelItems; menuItems = topLevelItems;
} }
@@ -160,29 +159,29 @@ namespace Orchard.Core.Navigation.Drivers {
return shapeHelper.Parts_MenuWidget(Menu: menuShape); return shapeHelper.Parts_MenuWidget(Menu: menuShape);
}); });
} }
protected override DriverResult Editor(MenuWidgetPart part, dynamic shapeHelper) { protected override DriverResult Editor(MenuWidgetPart part, dynamic shapeHelper) {
return ContentShape("Parts_MenuWidget_Edit", () => { return ContentShape("Parts_MenuWidget_Edit", () => {
var model = new MenuWidgetViewModel { var model = new MenuWidgetViewModel {
CurrentMenuId = part.MenuContentItemId, CurrentMenuId = part.MenuContentItemId,
StartLevel = part.StartLevel, StartLevel = part.StartLevel,
StopLevel = part.Levels, StopLevel = part.Levels,
Breadcrumb = part.Breadcrumb, Breadcrumb = part.Breadcrumb,
AddCurrentPage = part.AddCurrentPage, AddCurrentPage = part.AddCurrentPage,
AddHomePage = part.AddHomePage, AddHomePage = part.AddHomePage,
ShowFullMenu = part.ShowFullMenu, ShowFullMenu = part.ShowFullMenu,
Menus = _menuService.GetMenus(), Menus = _menuService.GetMenus(),
}; };
return shapeHelper.EditorTemplate(TemplateName: "Parts.MenuWidget.Edit", Model: model, Prefix: Prefix); return shapeHelper.EditorTemplate(TemplateName: "Parts.MenuWidget.Edit", Model: model, Prefix: Prefix);
}); });
} }
protected override DriverResult Editor(MenuWidgetPart part, IUpdateModel updater, dynamic shapeHelper) { protected override DriverResult Editor(MenuWidgetPart part, IUpdateModel updater, dynamic shapeHelper) {
var model = new MenuWidgetViewModel(); var model = new MenuWidgetViewModel();
if(updater.TryUpdateModel(model, Prefix, null, null)) { if (updater.TryUpdateModel(model, Prefix, null, null)) {
part.StartLevel = model.StartLevel; part.StartLevel = model.StartLevel;
part.Levels = model.StopLevel; part.Levels = model.StopLevel;
part.Breadcrumb = model.Breadcrumb; part.Breadcrumb = model.Breadcrumb;
@@ -223,5 +222,14 @@ namespace Orchard.Core.Navigation.Drivers {
context.Element(part.PartDefinition.Name).SetAttributeValue("ShowFullMenu", part.ShowFullMenu); context.Element(part.PartDefinition.Name).SetAttributeValue("ShowFullMenu", part.ShowFullMenu);
} }
protected override void Cloning(MenuWidgetPart originalPart, MenuWidgetPart clonePart, CloneContentContext context) {
clonePart.StartLevel = originalPart.StartLevel;
clonePart.Levels = originalPart.Levels;
clonePart.Breadcrumb = originalPart.Breadcrumb;
clonePart.AddCurrentPage = originalPart.AddCurrentPage;
clonePart.AddHomePage = originalPart.AddHomePage;
clonePart.ShowFullMenu = originalPart.ShowFullMenu;
clonePart.MenuContentItemId = originalPart.MenuContentItemId;
}
} }
} }

View File

@@ -48,5 +48,9 @@ namespace Orchard.Core.Navigation.Drivers {
protected override void Exporting(ShapeMenuItemPart part, ExportContentContext context) { protected override void Exporting(ShapeMenuItemPart part, ExportContentContext context) {
context.Element(part.PartDefinition.Name).SetAttributeValue("ShapeType", part.ShapeType); context.Element(part.PartDefinition.Name).SetAttributeValue("ShapeType", part.ShapeType);
} }
protected override void Cloning(ShapeMenuItemPart originalPart, ShapeMenuItemPart clonePart, CloneContentContext context) {
clonePart.ShapeType = originalPart.ShapeType;
}
} }
} }

View File

@@ -1,6 +1,5 @@
using System; using System;
using Orchard.AntiSpam.Models; using Orchard.AntiSpam.Models;
using Orchard.AntiSpam.Settings;
using Orchard.ContentManagement.Drivers; using Orchard.ContentManagement.Drivers;
using Orchard.ContentManagement.Handlers; using Orchard.ContentManagement.Handlers;
using Orchard.Localization; using Orchard.Localization;
@@ -39,17 +38,19 @@ namespace Orchard.AntiSpam.Drivers {
} }
var status = context.Attribute(part.PartDefinition.Name, "Status"); var status = context.Attribute(part.PartDefinition.Name, "Status");
if (status != null) { if (status != null && Enum.TryParse(status, out SpamStatus value)) {
SpamStatus value; part.Status = value;
if(Enum.TryParse(status, out value)) {
part.Status = value;
}
} }
} }
protected override void Exporting(SpamFilterPart part, ExportContentContext context) { protected override void Exporting(SpamFilterPart part, ExportContentContext context) {
context.Element(part.PartDefinition.Name).SetAttributeValue("Status", part.Status.ToString()); context.Element(part.PartDefinition.Name).SetAttributeValue("Status", part.Status.ToString());
} }
protected override void Cloning(SpamFilterPart originalPart, SpamFilterPart clonePart, CloneContentContext context) {
clonePart.Status = originalPart.Status;
}
} }
} }

View File

@@ -66,7 +66,7 @@ namespace Orchard.ArchiveLater.Drivers {
var model = BuildViewModelFromPart(part); var model = BuildViewModelFromPart(part);
return ContentShape("Parts_ArchiveLater_Edit", return ContentShape("Parts_ArchiveLater_Edit",
() => shapeHelper.EditorTemplate(TemplateName: TemplateName, Model: model, Prefix: Prefix)); () => shapeHelper.EditorTemplate(TemplateName: TemplateName, Model: model, Prefix: Prefix));
} }
protected override DriverResult Editor(ArchiveLaterPart part, IUpdateModel updater, dynamic shapeHelper) { protected override DriverResult Editor(ArchiveLaterPart part, IUpdateModel updater, dynamic shapeHelper) {
@@ -76,10 +76,10 @@ namespace Orchard.ArchiveLater.Drivers {
if (model.ArchiveLater) { if (model.ArchiveLater) {
try { try {
var utcDateTime = _dateLocalizationServices.ConvertFromLocalizedString(model.Editor.Date, model.Editor.Time); var utcDateTime = _dateLocalizationServices.ConvertFromLocalizedString(model.Editor.Date, model.Editor.Time);
_archiveLaterService.ArchiveLater(model.ContentItem, utcDateTime.HasValue ? utcDateTime.Value : DateTime.MaxValue); _archiveLaterService.ArchiveLater(model.ContentItem, utcDateTime ?? DateTime.MaxValue);
} }
catch (FormatException) { catch (FormatException) {
updater.AddModelError(Prefix, T("'{0} {1}' could not be parsed as a valid date and time.", model.Editor.Date, model.Editor.Time)); updater.AddModelError(Prefix, T("'{0} {1}' could not be parsed as a valid date and time.", model.Editor.Date, model.Editor.Time));
} }
} }
else { else {
@@ -88,7 +88,7 @@ namespace Orchard.ArchiveLater.Drivers {
} }
return ContentShape("Parts_ArchiveLater_Edit", return ContentShape("Parts_ArchiveLater_Edit",
() => shapeHelper.EditorTemplate(TemplateName: TemplateName, Model: model, Prefix: Prefix)); () => shapeHelper.EditorTemplate(TemplateName: TemplateName, Model: model, Prefix: Prefix));
} }
protected override void Importing(ArchiveLaterPart part, ImportContentContext context) { protected override void Importing(ArchiveLaterPart part, ImportContentContext context) {
@@ -109,5 +109,10 @@ namespace Orchard.ArchiveLater.Drivers {
.SetAttributeValue("ScheduledArchiveUtc", XmlConvert.ToString(scheduled.Value, XmlDateTimeSerializationMode.Utc)); .SetAttributeValue("ScheduledArchiveUtc", XmlConvert.ToString(scheduled.Value, XmlDateTimeSerializationMode.Utc));
} }
} }
protected override void Cloning(ArchiveLaterPart originalPart, ArchiveLaterPart clonePart, CloneContentContext context) {
clonePart.ScheduledArchiveUtc.Value = originalPart.ScheduledArchiveUtc.Value;
}
} }
} }

View File

@@ -13,7 +13,6 @@ using Orchard.ContentManagement.Handlers;
using Orchard.Localization; using Orchard.Localization;
using Orchard.Localization.Services; using Orchard.Localization.Services;
using Orchard.Mvc; using Orchard.Mvc;
using Orchard.Security;
using Orchard.UI.Notify; using Orchard.UI.Notify;
using Orchard.Utility.Extensions; using Orchard.Utility.Extensions;
@@ -29,10 +28,9 @@ namespace Orchard.Autoroute.Drivers {
public AutoroutePartDriver( public AutoroutePartDriver(
IAutorouteService autorouteService, IAutorouteService autorouteService,
INotifier notifier, INotifier notifier,
IHomeAliasService homeAliasService, IHomeAliasService homeAliasService,
IAliasService aliasService, IAliasService aliasService,
IAuthorizer authorizer,
ICultureManager cultureManager, ICultureManager cultureManager,
IContentManager contentManager, IContentManager contentManager,
IHttpContextAccessor httpContextAccessor) { IHttpContextAccessor httpContextAccessor) {
@@ -57,7 +55,7 @@ namespace Orchard.Autoroute.Drivers {
protected override DriverResult Editor(AutoroutePart part, IUpdateModel updater, dynamic shapeHelper) { protected override DriverResult Editor(AutoroutePart part, IUpdateModel updater, dynamic shapeHelper) {
var settings = part.TypePartDefinition.Settings.GetModel<AutorouteSettings>(); var settings = part.TypePartDefinition.Settings.GetModel<AutorouteSettings>();
var itemCulture = _cultureManager.GetSiteCulture(); var itemCulture = _cultureManager.GetSiteCulture();
// If we are editing an existing content item, check to see if we are an ILocalizableAspect so we can use its culture for alias generation. // If we are editing an existing content item, check to see if we are an ILocalizableAspect so we can use its culture for alias generation.
if (part.Record.Id != 0) { if (part.Record.Id != 0) {
var localizableAspect = part.As<ILocalizableAspect>(); var localizableAspect = part.As<ILocalizableAspect>();
@@ -87,7 +85,7 @@ namespace Orchard.Autoroute.Drivers {
foreach (var pattern in settings.DefaultPatterns.Where(x => String.IsNullOrWhiteSpace(x.Culture))) { foreach (var pattern in settings.DefaultPatterns.Where(x => String.IsNullOrWhiteSpace(x.Culture))) {
pattern.Culture = _cultureManager.GetSiteCulture(); pattern.Culture = _cultureManager.GetSiteCulture();
} }
// If the content type has no pattern for autoroute, then use a default one. // If the content type has no pattern for autoroute, then use a default one.
if (!settings.Patterns.Any(x => String.Equals(x.Culture, itemCulture, StringComparison.OrdinalIgnoreCase))) { if (!settings.Patterns.Any(x => String.Equals(x.Culture, itemCulture, StringComparison.OrdinalIgnoreCase))) {
settings.Patterns = new List<RoutePattern> { new RoutePattern { Name = "Title", Description = "my-title", Pattern = "{Content.Slug}", Culture = itemCulture } }; settings.Patterns = new List<RoutePattern> { new RoutePattern { Name = "Title", Description = "my-title", Pattern = "{Content.Slug}", Culture = itemCulture } };
@@ -100,10 +98,12 @@ namespace Orchard.Autoroute.Drivers {
if (!String.IsNullOrWhiteSpace(settings.DefaultPatternIndex)) { if (!String.IsNullOrWhiteSpace(settings.DefaultPatternIndex)) {
var patternIndex = settings.DefaultPatternIndex; var patternIndex = settings.DefaultPatternIndex;
settings.DefaultPatterns.Add(new DefaultPattern { PatternIndex = patternIndex, Culture = itemCulture }); settings.DefaultPatterns.Add(new DefaultPattern { PatternIndex = patternIndex, Culture = itemCulture });
} else { }
else {
settings.DefaultPatterns.Add(new DefaultPattern { PatternIndex = "0", Culture = itemCulture }); settings.DefaultPatterns.Add(new DefaultPattern { PatternIndex = "0", Culture = itemCulture });
} }
} else { }
else {
settings.DefaultPatterns.Add(new DefaultPattern { PatternIndex = "0", Culture = itemCulture }); settings.DefaultPatterns.Add(new DefaultPattern { PatternIndex = "0", Culture = itemCulture });
} }
} }
@@ -128,7 +128,7 @@ namespace Orchard.Autoroute.Drivers {
var previous = part.DisplayAlias; var previous = part.DisplayAlias;
if (updater != null && updater.TryUpdateModel(viewModel, Prefix, null, null)) { if (updater != null && updater.TryUpdateModel(viewModel, Prefix, null, null)) {
// Remove any leading slash in the permalink. // Remove any leading slash in the permalink.
if (viewModel.CurrentUrl != null) { if (viewModel.CurrentUrl != null) {
viewModel.CurrentUrl = viewModel.CurrentUrl.TrimStart('/'); viewModel.CurrentUrl = viewModel.CurrentUrl.TrimStart('/');
@@ -137,15 +137,15 @@ namespace Orchard.Autoroute.Drivers {
part.DisplayAlias = viewModel.CurrentUrl; part.DisplayAlias = viewModel.CurrentUrl;
// Reset the alias if we need to force regeneration, and the user didn't provide a custom one. // Reset the alias if we need to force regeneration, and the user didn't provide a custom one.
if(settings.AutomaticAdjustmentOnEdit && previous == part.DisplayAlias) { if (settings.AutomaticAdjustmentOnEdit && previous == part.DisplayAlias) {
part.DisplayAlias = String.Empty; part.DisplayAlias = String.Empty;
} }
if (!_autorouteService.IsPathValid(part.DisplayAlias)) { if (!_autorouteService.IsPathValid(part.DisplayAlias)) {
updater.AddModelError("CurrentUrl", T("Please do not use any of the following characters in your permalink: \":\", \"?\", \"#\", \"[\", \"]\", \"@\", \"!\", \"$\", \"&\", \"'\", \"(\", \")\", \"*\", \"+\", \",\", \";\", \"=\", \", \"<\", \">\", \"\\\", \"|\", \"%\", \".\". No spaces are allowed (please use dashes or underscores instead).")); updater.AddModelError("CurrentUrl", T("Please do not use any of the following characters in your permalink: \":\", \"?\", \"#\", \"[\", \"]\", \"@\", \"!\", \"$\", \"&\", \"'\", \"(\", \")\", \"*\", \"+\", \",\", \";\", \"=\", \", \"<\", \">\", \"\\\", \"|\", \"%\", \".\". No spaces are allowed (please use dashes or underscores instead)."));
} }
if (part.DisplayAlias != null && part.DisplayAlias.Length > 1850){ if (part.DisplayAlias != null && part.DisplayAlias.Length > 1850) {
updater.AddModelError("CurrentUrl", T("Your permalink is too long. The permalink can only be up to 1,850 characters.")); updater.AddModelError("CurrentUrl", T("Your permalink is too long. The permalink can only be up to 1,850 characters."));
} }
@@ -153,7 +153,7 @@ namespace Orchard.Autoroute.Drivers {
part.PromoteToHomePage = viewModel.PromoteToHomePage; part.PromoteToHomePage = viewModel.PromoteToHomePage;
} }
return ContentShape("Parts_Autoroute_Edit", return ContentShape("Parts_Autoroute_Edit",
() => shapeHelper.EditorTemplate(TemplateName: "Parts.Autoroute.Edit", Model: viewModel, Prefix: Prefix)); () => shapeHelper.EditorTemplate(TemplateName: "Parts.Autoroute.Edit", Model: viewModel, Prefix: Prefix));
} }
@@ -177,5 +177,11 @@ namespace Orchard.Autoroute.Drivers {
context.Element(part.PartDefinition.Name).SetAttributeValue("UseCulturePattern", part.Record.UseCulturePattern); context.Element(part.PartDefinition.Name).SetAttributeValue("UseCulturePattern", part.Record.UseCulturePattern);
context.Element(part.PartDefinition.Name).SetAttributeValue("PromoteToHomePage", part.PromoteToHomePage); context.Element(part.PartDefinition.Name).SetAttributeValue("PromoteToHomePage", part.PromoteToHomePage);
} }
protected override void Cloning(AutoroutePart originalPart, AutoroutePart clonePart, CloneContentContext context) {
clonePart.CustomPattern = originalPart.CustomPattern;
clonePart.UseCustomPattern = originalPart.UseCustomPattern;
clonePart.UseCulturePattern = originalPart.UseCulturePattern;
}
} }
} }

View File

@@ -13,7 +13,7 @@ namespace Orchard.Blogs.Drivers {
private readonly IContentManager _contentManager; private readonly IContentManager _contentManager;
public BlogArchivesPartDriver( public BlogArchivesPartDriver(
IBlogService blogService, IBlogService blogService,
IBlogPostService blogPostService, IBlogPostService blogPostService,
IContentManager contentManager) { IContentManager contentManager) {
_blogService = blogService; _blogService = blogService;
@@ -22,25 +22,24 @@ namespace Orchard.Blogs.Drivers {
} }
protected override DriverResult Display(BlogArchivesPart part, string displayType, dynamic shapeHelper) { protected override DriverResult Display(BlogArchivesPart part, string displayType, dynamic shapeHelper) {
return ContentShape("Parts_Blogs_BlogArchives", return ContentShape("Parts_Blogs_BlogArchives", () => {
() => { var blog = _blogService.Get(part.BlogId, VersionOptions.Published).As<BlogPart>();
var blog = _blogService.Get(part.BlogId, VersionOptions.Published).As<BlogPart>();
if (blog == null) if (blog == null)
return null; return null;
return shapeHelper.Parts_Blogs_BlogArchives(Blog: blog, Archives: _blogPostService.GetArchives(blog)); return shapeHelper.Parts_Blogs_BlogArchives(Blog: blog, Archives: _blogPostService.GetArchives(blog));
}); });
} }
protected override DriverResult Editor(BlogArchivesPart part, dynamic shapeHelper) { protected override DriverResult Editor(BlogArchivesPart part, dynamic shapeHelper) {
var viewModel = new BlogArchivesViewModel { var viewModel = new BlogArchivesViewModel {
BlogId = part.BlogId, BlogId = part.BlogId,
Blogs = _blogService.Get().ToList().OrderBy(b => _contentManager.GetItemMetadata(b).DisplayText) Blogs = _blogService.Get().ToList().OrderBy(b => _contentManager.GetItemMetadata(b).DisplayText)
}; };
return ContentShape("Parts_Blogs_BlogArchives_Edit", return ContentShape("Parts_Blogs_BlogArchives_Edit",
() => shapeHelper.EditorTemplate(TemplateName: "Parts.Blogs.BlogArchives", Model: viewModel, Prefix: Prefix)); () => shapeHelper.EditorTemplate(TemplateName: "Parts.Blogs.BlogArchives", Model: viewModel, Prefix: Prefix));
} }
protected override DriverResult Editor(BlogArchivesPart part, IUpdateModel updater, dynamic shapeHelper) { protected override DriverResult Editor(BlogArchivesPart part, IUpdateModel updater, dynamic shapeHelper) {
@@ -69,5 +68,8 @@ namespace Orchard.Blogs.Drivers {
context.Element(part.PartDefinition.Name).SetAttributeValue("Blog", blogIdentity); context.Element(part.PartDefinition.Name).SetAttributeValue("Blog", blogIdentity);
} }
protected override void Cloning(BlogArchivesPart originalPart, BlogArchivesPart clonePart, CloneContentContext context) {
clonePart.BlogId = originalPart.BlogId;
}
} }
} }

View File

@@ -2,6 +2,7 @@
using Orchard.Blogs.Models; using Orchard.Blogs.Models;
using Orchard.ContentManagement; using Orchard.ContentManagement;
using Orchard.ContentManagement.Drivers; using Orchard.ContentManagement.Drivers;
using Orchard.ContentManagement.Handlers;
namespace Orchard.Blogs.Drivers { namespace Orchard.Blogs.Drivers {
public class BlogPartDriver : ContentPartDriver<BlogPart> { public class BlogPartDriver : ContentPartDriver<BlogPart> {
@@ -31,7 +32,7 @@ namespace Orchard.Blogs.Drivers {
return Editor(blogPart, shapeHelper); return Editor(blogPart, shapeHelper);
} }
protected override void Importing(BlogPart part, ContentManagement.Handlers.ImportContentContext context) { protected override void Importing(BlogPart part, ImportContentContext context) {
// Don't do anything if the tag is not specified. // Don't do anything if the tag is not specified.
if (context.Data.Element(part.PartDefinition.Name) == null) { if (context.Data.Element(part.PartDefinition.Name) == null) {
return; return;
@@ -50,10 +51,16 @@ namespace Orchard.Blogs.Drivers {
); );
} }
protected override void Exporting(BlogPart part, ContentManagement.Handlers.ExportContentContext context) { protected override void Exporting(BlogPart part, ExportContentContext context) {
context.Element(part.PartDefinition.Name).SetAttributeValue("Description", part.Description); context.Element(part.PartDefinition.Name).SetAttributeValue("Description", part.Description);
context.Element(part.PartDefinition.Name).SetAttributeValue("PostCount", part.PostCount); context.Element(part.PartDefinition.Name).SetAttributeValue("PostCount", part.PostCount);
context.Element(part.PartDefinition.Name).SetAttributeValue("FeedProxyUrl", part.FeedProxyUrl); context.Element(part.PartDefinition.Name).SetAttributeValue("FeedProxyUrl", part.FeedProxyUrl);
} }
protected override void Cloning(BlogPart originalPart, BlogPart clonePart, CloneContentContext context) {
clonePart.Description = originalPart.Description;
clonePart.PostCount = originalPart.PostCount;
clonePart.FeedProxyUrl = originalPart.FeedProxyUrl;
}
} }
} }

View File

@@ -14,7 +14,7 @@ namespace Orchard.Blogs.Drivers {
private readonly IContentManager _contentManager; private readonly IContentManager _contentManager;
public RecentBlogPostsPartDriver( public RecentBlogPostsPartDriver(
IBlogService blogService, IBlogService blogService,
IContentManager contentManager) { IContentManager contentManager) {
_blogService = blogService; _blogService = blogService;
_contentManager = contentManager; _contentManager = contentManager;
@@ -22,7 +22,7 @@ namespace Orchard.Blogs.Drivers {
protected override DriverResult Display(RecentBlogPostsPart part, string displayType, dynamic shapeHelper) { protected override DriverResult Display(RecentBlogPostsPart part, string displayType, dynamic shapeHelper) {
return ContentShape("Parts_Blogs_RecentBlogPosts", () => { return ContentShape("Parts_Blogs_RecentBlogPosts", () => {
var blog = _contentManager.Get<BlogPart>(part.BlogId); var blog = _contentManager.Get<BlogPart>(part.BlogId);
if (blog == null) { if (blog == null) {
return null; return null;
@@ -87,5 +87,10 @@ namespace Orchard.Blogs.Drivers {
context.Element(part.PartDefinition.Name).SetAttributeValue("Blog", blogIdentity); context.Element(part.PartDefinition.Name).SetAttributeValue("Blog", blogIdentity);
context.Element(part.PartDefinition.Name).SetAttributeValue("Count", part.Count); context.Element(part.PartDefinition.Name).SetAttributeValue("Count", part.Count);
} }
protected override void Cloning(RecentBlogPostsPart originalPart, RecentBlogPostsPart clonePart, CloneContentContext context) {
clonePart.BlogId = originalPart.BlogId;
clonePart.Count = originalPart.Count;
}
} }
} }

View File

@@ -2,12 +2,13 @@ using System;
using System.Globalization; using System.Globalization;
using System.Xml; using System.Xml;
using Orchard.Comments.Models; using Orchard.Comments.Models;
using Orchard.ContentManagement;
using Orchard.ContentManagement.Drivers;
using Orchard.ContentManagement.Aspects;
using Orchard.Services;
using Orchard.Localization;
using Orchard.Comments.Services; using Orchard.Comments.Services;
using Orchard.ContentManagement;
using Orchard.ContentManagement.Aspects;
using Orchard.ContentManagement.Drivers;
using Orchard.ContentManagement.Handlers;
using Orchard.Localization;
using Orchard.Services;
using Orchard.UI.Notify; using Orchard.UI.Notify;
namespace Orchard.Comments.Drivers { namespace Orchard.Comments.Drivers {
@@ -41,17 +42,17 @@ namespace Orchard.Comments.Drivers {
return Combined( return Combined(
ContentShape("Parts_Comment", () => shapeHelper.Parts_Comment()), ContentShape("Parts_Comment", () => shapeHelper.Parts_Comment()),
ContentShape("Parts_Comment_SummaryAdmin", () => shapeHelper.Parts_Comment_SummaryAdmin()) ContentShape("Parts_Comment_SummaryAdmin", () => shapeHelper.Parts_Comment_SummaryAdmin())
); );
} }
// GET // GET
protected override DriverResult Editor(CommentPart part, dynamic shapeHelper) { protected override DriverResult Editor(CommentPart part, dynamic shapeHelper) {
if (UI.Admin.AdminFilter.IsApplied(_workContextAccessor.GetContext().HttpContext.Request.RequestContext)) { if (UI.Admin.AdminFilter.IsApplied(_workContextAccessor.GetContext().HttpContext.Request.RequestContext)) {
return ContentShape("Parts_Comment_AdminEdit", return ContentShape("Parts_Comment_AdminEdit",
() => shapeHelper.EditorTemplate(TemplateName: "Parts.Comment.AdminEdit", Model: part, Prefix: Prefix)); () => shapeHelper.EditorTemplate(TemplateName: "Parts.Comment.AdminEdit", Model: part, Prefix: Prefix));
} }
else { else {
return ContentShape("Parts_Comment_Edit", return ContentShape("Parts_Comment_Edit",
() => shapeHelper.EditorTemplate(TemplateName: "Parts.Comment", Model: part, Prefix: Prefix)); () => shapeHelper.EditorTemplate(TemplateName: "Parts.Comment", Model: part, Prefix: Prefix));
} }
} }
@@ -102,9 +103,9 @@ namespace Orchard.Comments.Drivers {
} }
var currentUser = workContext.CurrentUser; var currentUser = workContext.CurrentUser;
part.UserName = (currentUser != null ? currentUser.UserName : null); part.UserName = currentUser?.UserName;
if (currentUser != null) if (currentUser != null)
part.Author = currentUser.UserName; part.Author = currentUser.UserName;
else if (string.IsNullOrWhiteSpace(part.Author)) { else if (string.IsNullOrWhiteSpace(part.Author)) {
updater.AddModelError("Comments.Author", T("Name is mandatory")); updater.AddModelError("Comments.Author", T("Name is mandatory"));
@@ -227,5 +228,33 @@ namespace Orchard.Comments.Drivers {
} }
} }
} }
protected override void Cloning(CommentPart originalPart, CommentPart clonePart, CloneContentContext context) {
clonePart.Author = originalPart.Author;
clonePart.SiteName = originalPart.SiteName;
clonePart.UserName = originalPart.UserName;
clonePart.Email = originalPart.Email;
clonePart.Position = originalPart.Position;
clonePart.Status = originalPart.Status;
clonePart.CommentDateUtc = originalPart.CommentDateUtc;
clonePart.CommentText = originalPart.CommentText;
var commentedOn = _contentManager.Get(originalPart.CommentedOn);
if (commentedOn != null) {
clonePart.CommentedOn = originalPart.CommentedOn;
}
if (originalPart.RepliedOn.HasValue) {
var repliedOn = _contentManager.Get(originalPart.RepliedOn.Value);
if (repliedOn != null) {
clonePart.RepliedOn = originalPart.RepliedOn;
}
}
else {
clonePart.RepliedOn = null;
}
var commentedOnContainer = _contentManager.Get(originalPart.CommentedOnContainer);
if (commentedOnContainer != null) {
clonePart.CommentedOnContainer = originalPart.CommentedOnContainer;
}
}
} }
} }

View File

@@ -5,13 +5,13 @@ using System.Xml;
using Orchard.ContentManagement; using Orchard.ContentManagement;
using Orchard.ContentManagement.Drivers; using Orchard.ContentManagement.Drivers;
using Orchard.ContentManagement.Handlers; using Orchard.ContentManagement.Handlers;
using Orchard.ContentPermissions.Models;
using Orchard.ContentPermissions.Settings;
using Orchard.ContentPermissions.ViewModels;
using Orchard.Localization; using Orchard.Localization;
using Orchard.Roles.Models; using Orchard.Roles.Models;
using Orchard.Roles.Services; using Orchard.Roles.Services;
using Orchard.Security; using Orchard.Security;
using Orchard.ContentPermissions.Models;
using Orchard.ContentPermissions.Settings;
using Orchard.ContentPermissions.ViewModels;
namespace Orchard.ContentPermissions.Drivers { namespace Orchard.ContentPermissions.Drivers {
public class ContentPermissionsPartDriver : ContentPartDriver<ContentPermissionsPart> { public class ContentPermissionsPartDriver : ContentPartDriver<ContentPermissionsPart> {
@@ -50,7 +50,7 @@ namespace Orchard.ContentPermissions.Drivers {
var allRoles = _roleService.GetRoles().Select(x => x.Name).OrderBy(x => x).ToList(); var allRoles = _roleService.GetRoles().Select(x => x.Name).OrderBy(x => x).ToList();
if(settings == null) { if (settings == null) {
settings = new ContentPermissionsPartSettings { settings = new ContentPermissionsPartSettings {
View = ContentPermissionsPartViewModel.SerializePermissions(allRoles.Select(x => new RoleEntry { Role = x, Checked = _authorizationService.TryCheckAccess(Core.Contents.Permissions.ViewContent, UserSimulation.Create(x), null) }).ToList()), View = ContentPermissionsPartViewModel.SerializePermissions(allRoles.Select(x => new RoleEntry { Role = x, Checked = _authorizationService.TryCheckAccess(Core.Contents.Permissions.ViewContent, UserSimulation.Create(x), null) }).ToList()),
ViewOwn = ContentPermissionsPartViewModel.SerializePermissions(allRoles.Select(x => new RoleEntry { Role = x, Checked = _authorizationService.TryCheckAccess(Core.Contents.Permissions.ViewOwnContent, UserSimulation.Create(x), null) }).ToList()), ViewOwn = ContentPermissionsPartViewModel.SerializePermissions(allRoles.Select(x => new RoleEntry { Role = x, Checked = _authorizationService.TryCheckAccess(Core.Contents.Permissions.ViewOwnContent, UserSimulation.Create(x), null) }).ToList()),
@@ -73,12 +73,12 @@ namespace Orchard.ContentPermissions.Drivers {
model = new ContentPermissionsPartViewModel { model = new ContentPermissionsPartViewModel {
ViewRoles = ContentPermissionsPartViewModel.ExtractRoleEntries(allRoles, settings.View), ViewRoles = ContentPermissionsPartViewModel.ExtractRoleEntries(allRoles, settings.View),
ViewOwnRoles = ContentPermissionsPartViewModel.ExtractRoleEntries(allRoles, settings.ViewOwn), ViewOwnRoles = ContentPermissionsPartViewModel.ExtractRoleEntries(allRoles, settings.ViewOwn),
PublishRoles= ContentPermissionsPartViewModel.ExtractRoleEntries(allRoles, settings.Publish), PublishRoles = ContentPermissionsPartViewModel.ExtractRoleEntries(allRoles, settings.Publish),
PublishOwnRoles= ContentPermissionsPartViewModel.ExtractRoleEntries(allRoles, settings.PublishOwn), PublishOwnRoles = ContentPermissionsPartViewModel.ExtractRoleEntries(allRoles, settings.PublishOwn),
EditRoles= ContentPermissionsPartViewModel.ExtractRoleEntries(allRoles, settings.Edit), EditRoles = ContentPermissionsPartViewModel.ExtractRoleEntries(allRoles, settings.Edit),
EditOwnRoles= ContentPermissionsPartViewModel.ExtractRoleEntries(allRoles, settings.EditOwn), EditOwnRoles = ContentPermissionsPartViewModel.ExtractRoleEntries(allRoles, settings.EditOwn),
DeleteRoles= ContentPermissionsPartViewModel.ExtractRoleEntries(allRoles, settings.Delete), DeleteRoles = ContentPermissionsPartViewModel.ExtractRoleEntries(allRoles, settings.Delete),
DeleteOwnRoles= ContentPermissionsPartViewModel.ExtractRoleEntries(allRoles, settings.DeleteOwn), DeleteOwnRoles = ContentPermissionsPartViewModel.ExtractRoleEntries(allRoles, settings.DeleteOwn),
PreviewRoles = ContentPermissionsPartViewModel.ExtractRoleEntries(allRoles, settings.Preview), PreviewRoles = ContentPermissionsPartViewModel.ExtractRoleEntries(allRoles, settings.Preview),
PreviewOwnRoles = ContentPermissionsPartViewModel.ExtractRoleEntries(allRoles, settings.PreviewOwn), PreviewOwnRoles = ContentPermissionsPartViewModel.ExtractRoleEntries(allRoles, settings.PreviewOwn),
AllRoles = ContentPermissionsPartViewModel.ExtractRoleEntries(allRoles, settings.DisplayedRoles) AllRoles = ContentPermissionsPartViewModel.ExtractRoleEntries(allRoles, settings.DisplayedRoles)
@@ -185,46 +185,60 @@ namespace Orchard.ContentPermissions.Drivers {
context.ImportAttribute(part.PartDefinition.Name, "PreviewOwnContent", s => part.PreviewOwnContent = s); context.ImportAttribute(part.PartDefinition.Name, "PreviewOwnContent", s => part.PreviewOwnContent = s);
} }
protected override void Cloning(ContentPermissionsPart originalPart, ContentPermissionsPart clonePart, CloneContentContext context) {
clonePart.Enabled = originalPart.Enabled;
clonePart.ViewContent = originalPart.ViewContent;
clonePart.EditContent = originalPart.EditContent;
clonePart.PublishContent = originalPart.PublishContent;
clonePart.DeleteContent = originalPart.DeleteContent;
clonePart.PreviewContent = originalPart.PreviewContent;
clonePart.ViewOwnContent = originalPart.ViewOwnContent;
clonePart.EditOwnContent = originalPart.EditOwnContent;
clonePart.PublishOwnContent = originalPart.PublishOwnContent;
clonePart.DeleteOwnContent = originalPart.DeleteOwnContent;
clonePart.PreviewOwnContent = originalPart.PreviewOwnContent;
}
private void OverrideDefaultPermissions(ContentPermissionsPart part, List<string> allRoles, ContentPermissionsPartSettings settings) { private void OverrideDefaultPermissions(ContentPermissionsPart part, List<string> allRoles, ContentPermissionsPartSettings settings) {
// reset permissions the user can't change // reset permissions the user can't change
if (!_authorizer.Authorize(Core.Contents.Permissions.ViewContent, part.ContentItem)) { if (!_authorizer.Authorize(Core.Contents.Permissions.ViewContent, part.ContentItem)) {
part.ViewContent = settings == null ? ContentPermissionsPartViewModel.SerializePermissions(allRoles.Select(x => new RoleEntry {Role = x, Checked = _authorizationService.TryCheckAccess(Core.Contents.Permissions.ViewContent, UserSimulation.Create(x), null)})) : settings.View; part.ViewContent = settings == null ? ContentPermissionsPartViewModel.SerializePermissions(allRoles.Select(x => new RoleEntry { Role = x, Checked = _authorizationService.TryCheckAccess(Core.Contents.Permissions.ViewContent, UserSimulation.Create(x), null) })) : settings.View;
} }
if (!_authorizer.Authorize(Core.Contents.Permissions.ViewOwnContent, part.ContentItem)) { if (!_authorizer.Authorize(Core.Contents.Permissions.ViewOwnContent, part.ContentItem)) {
part.ViewOwnContent = settings == null ? ContentPermissionsPartViewModel.SerializePermissions(allRoles.Select(x => new RoleEntry {Role = x, Checked = _authorizationService.TryCheckAccess(Core.Contents.Permissions.ViewOwnContent, UserSimulation.Create(x), null)})) : settings.ViewOwn; part.ViewOwnContent = settings == null ? ContentPermissionsPartViewModel.SerializePermissions(allRoles.Select(x => new RoleEntry { Role = x, Checked = _authorizationService.TryCheckAccess(Core.Contents.Permissions.ViewOwnContent, UserSimulation.Create(x), null) })) : settings.ViewOwn;
} }
if (!_authorizer.Authorize(Core.Contents.Permissions.PublishContent, part.ContentItem)) { if (!_authorizer.Authorize(Core.Contents.Permissions.PublishContent, part.ContentItem)) {
part.PublishContent = settings == null ? ContentPermissionsPartViewModel.SerializePermissions(allRoles.Select(x => new RoleEntry {Role = x, Checked = _authorizationService.TryCheckAccess(Core.Contents.Permissions.PublishContent, UserSimulation.Create(x), null)})) : settings.Publish; part.PublishContent = settings == null ? ContentPermissionsPartViewModel.SerializePermissions(allRoles.Select(x => new RoleEntry { Role = x, Checked = _authorizationService.TryCheckAccess(Core.Contents.Permissions.PublishContent, UserSimulation.Create(x), null) })) : settings.Publish;
} }
if (!_authorizer.Authorize(Core.Contents.Permissions.PublishOwnContent, part.ContentItem)) { if (!_authorizer.Authorize(Core.Contents.Permissions.PublishOwnContent, part.ContentItem)) {
part.PublishOwnContent = settings == null ? ContentPermissionsPartViewModel.SerializePermissions(allRoles.Select(x => new RoleEntry {Role = x, Checked = _authorizationService.TryCheckAccess(Core.Contents.Permissions.PublishOwnContent, UserSimulation.Create(x), null)})) : settings.PublishOwn; part.PublishOwnContent = settings == null ? ContentPermissionsPartViewModel.SerializePermissions(allRoles.Select(x => new RoleEntry { Role = x, Checked = _authorizationService.TryCheckAccess(Core.Contents.Permissions.PublishOwnContent, UserSimulation.Create(x), null) })) : settings.PublishOwn;
} }
if (!_authorizer.Authorize(Core.Contents.Permissions.EditContent, part.ContentItem)) { if (!_authorizer.Authorize(Core.Contents.Permissions.EditContent, part.ContentItem)) {
part.EditContent = settings == null ? ContentPermissionsPartViewModel.SerializePermissions(allRoles.Select(x => new RoleEntry {Role = x, Checked = _authorizationService.TryCheckAccess(Core.Contents.Permissions.EditContent, UserSimulation.Create(x), null)})) : settings.Edit; part.EditContent = settings == null ? ContentPermissionsPartViewModel.SerializePermissions(allRoles.Select(x => new RoleEntry { Role = x, Checked = _authorizationService.TryCheckAccess(Core.Contents.Permissions.EditContent, UserSimulation.Create(x), null) })) : settings.Edit;
} }
if (!_authorizer.Authorize(Core.Contents.Permissions.EditOwnContent, part.ContentItem)) { if (!_authorizer.Authorize(Core.Contents.Permissions.EditOwnContent, part.ContentItem)) {
part.EditOwnContent = settings == null ? ContentPermissionsPartViewModel.SerializePermissions(allRoles.Select(x => new RoleEntry {Role = x, Checked = _authorizationService.TryCheckAccess(Core.Contents.Permissions.EditOwnContent, UserSimulation.Create(x), null)})) : settings.EditOwn; part.EditOwnContent = settings == null ? ContentPermissionsPartViewModel.SerializePermissions(allRoles.Select(x => new RoleEntry { Role = x, Checked = _authorizationService.TryCheckAccess(Core.Contents.Permissions.EditOwnContent, UserSimulation.Create(x), null) })) : settings.EditOwn;
} }
if (!_authorizer.Authorize(Core.Contents.Permissions.DeleteContent, part.ContentItem)) { if (!_authorizer.Authorize(Core.Contents.Permissions.DeleteContent, part.ContentItem)) {
part.DeleteContent = settings == null ? ContentPermissionsPartViewModel.SerializePermissions(allRoles.Select(x => new RoleEntry {Role = x, Checked = _authorizationService.TryCheckAccess(Core.Contents.Permissions.DeleteContent, UserSimulation.Create(x), null)})) : settings.Delete; part.DeleteContent = settings == null ? ContentPermissionsPartViewModel.SerializePermissions(allRoles.Select(x => new RoleEntry { Role = x, Checked = _authorizationService.TryCheckAccess(Core.Contents.Permissions.DeleteContent, UserSimulation.Create(x), null) })) : settings.Delete;
} }
if (!_authorizer.Authorize(Core.Contents.Permissions.DeleteOwnContent, part.ContentItem)) { if (!_authorizer.Authorize(Core.Contents.Permissions.DeleteOwnContent, part.ContentItem)) {
part.DeleteOwnContent = settings == null ? ContentPermissionsPartViewModel.SerializePermissions(allRoles.Select(x => new RoleEntry {Role = x, Checked = _authorizationService.TryCheckAccess(Core.Contents.Permissions.DeleteOwnContent, UserSimulation.Create(x), null)})) : settings.DeleteOwn; part.DeleteOwnContent = settings == null ? ContentPermissionsPartViewModel.SerializePermissions(allRoles.Select(x => new RoleEntry { Role = x, Checked = _authorizationService.TryCheckAccess(Core.Contents.Permissions.DeleteOwnContent, UserSimulation.Create(x), null) })) : settings.DeleteOwn;
} }
if (!_authorizer.Authorize(Core.Contents.Permissions.PreviewContent, part.ContentItem)) { if (!_authorizer.Authorize(Core.Contents.Permissions.PreviewContent, part.ContentItem)) {
part.PreviewContent = settings == null ? ContentPermissionsPartViewModel.SerializePermissions(allRoles.Select(x => new RoleEntry {Role = x, Checked = _authorizationService.TryCheckAccess(Core.Contents.Permissions.PreviewContent, UserSimulation.Create(x), null)})) : settings.Preview; part.PreviewContent = settings == null ? ContentPermissionsPartViewModel.SerializePermissions(allRoles.Select(x => new RoleEntry { Role = x, Checked = _authorizationService.TryCheckAccess(Core.Contents.Permissions.PreviewContent, UserSimulation.Create(x), null) })) : settings.Preview;
} }
if (!_authorizer.Authorize(Core.Contents.Permissions.PreviewOwnContent, part.ContentItem)) { if (!_authorizer.Authorize(Core.Contents.Permissions.PreviewOwnContent, part.ContentItem)) {
part.PreviewOwnContent = settings == null ? ContentPermissionsPartViewModel.SerializePermissions(allRoles.Select(x => new RoleEntry {Role = x, Checked = _authorizationService.TryCheckAccess(Core.Contents.Permissions.PreviewOwnContent, UserSimulation.Create(x), null)})) : settings.PreviewOwn; part.PreviewOwnContent = settings == null ? ContentPermissionsPartViewModel.SerializePermissions(allRoles.Select(x => new RoleEntry { Role = x, Checked = _authorizationService.TryCheckAccess(Core.Contents.Permissions.PreviewOwnContent, UserSimulation.Create(x), null) })) : settings.PreviewOwn;
} }
} }
} }

View File

@@ -4,8 +4,6 @@ using Orchard.ContentManagement.Handlers;
using Orchard.ContentPicker.Models; using Orchard.ContentPicker.Models;
using Orchard.ContentPicker.ViewModels; using Orchard.ContentPicker.ViewModels;
using Orchard.Core.Navigation; using Orchard.Core.Navigation;
using Orchard.Core.Navigation.Models;
using Orchard.Core.Navigation.ViewModels;
using Orchard.Localization; using Orchard.Localization;
using Orchard.Security; using Orchard.Security;
@@ -17,7 +15,7 @@ namespace Orchard.ContentPicker.Drivers {
public ContentMenuItemPartDriver( public ContentMenuItemPartDriver(
IContentManager contentManager, IContentManager contentManager,
IAuthorizationService authorizationService, IAuthorizationService authorizationService,
IWorkContextAccessor workContextAccessor) { IWorkContextAccessor workContextAccessor) {
_contentManager = contentManager; _contentManager = contentManager;
_authorizationService = authorizationService; _authorizationService = authorizationService;
@@ -29,14 +27,13 @@ namespace Orchard.ContentPicker.Drivers {
public Localizer T { get; set; } public Localizer T { get; set; }
protected override DriverResult Editor(ContentMenuItemPart part, dynamic shapeHelper) { protected override DriverResult Editor(ContentMenuItemPart part, dynamic shapeHelper) {
return ContentShape("Parts_ContentMenuItem_Edit", return ContentShape("Parts_ContentMenuItem_Edit", () => {
() => { var model = new ContentMenuItemEditViewModel {
var model = new ContentMenuItemEditViewModel { ContentItemId = part.Content == null ? -1 : part.Content.Id,
ContentItemId = part.Content == null ? -1 : part.Content.Id, Part = part
Part = part };
}; return shapeHelper.EditorTemplate(TemplateName: "Parts.ContentMenuItem.Edit", Model: model, Prefix: Prefix);
return shapeHelper.EditorTemplate(TemplateName: "Parts.ContentMenuItem.Edit", Model: model, Prefix: Prefix); });
});
} }
protected override DriverResult Editor(ContentMenuItemPart part, IUpdateModel updater, dynamic shapeHelper) { protected override DriverResult Editor(ContentMenuItemPart part, IUpdateModel updater, dynamic shapeHelper) {
@@ -48,9 +45,9 @@ namespace Orchard.ContentPicker.Drivers {
var model = new ContentMenuItemEditViewModel(); var model = new ContentMenuItemEditViewModel();
if(updater.TryUpdateModel(model, Prefix, null, null)) { if (updater.TryUpdateModel(model, Prefix, null, null)) {
var contentItem = _contentManager.Get(model.ContentItemId, VersionOptions.Latest); var contentItem = _contentManager.Get(model.ContentItemId, VersionOptions.Latest);
if(contentItem == null) { if (contentItem == null) {
updater.AddModelError("ContentItemId", T("You must select a Content Item")); updater.AddModelError("ContentItemId", T("You must select a Content Item"));
} }
else { else {
@@ -67,12 +64,14 @@ namespace Orchard.ContentPicker.Drivers {
return; return;
} }
context.ImportAttribute(part.PartDefinition.Name, "ContentItem", context.ImportAttribute(
part.PartDefinition.Name,
"ContentItem",
contentItemId => { contentItemId => {
var contentItem = context.GetItemFromSession(contentItemId); var contentItem = context.GetItemFromSession(contentItemId);
part.Content = contentItem; part.Content = contentItem;
}, () => },
part.Content = null () => part.Content = null
); );
} }
@@ -85,5 +84,9 @@ namespace Orchard.ContentPicker.Drivers {
} }
} }
} }
protected override void Cloning(ContentMenuItemPart originalPart, ContentMenuItemPart clonePart, CloneContentContext context) {
clonePart.Content = originalPart.Content;
}
} }
} }

View File

@@ -10,7 +10,7 @@ namespace Orchard.MediaLibrary.Drivers {
ContentShape("Parts_Audio_SummaryAdmin", () => shapeHelper.Parts_Audio_SummaryAdmin()), ContentShape("Parts_Audio_SummaryAdmin", () => shapeHelper.Parts_Audio_SummaryAdmin()),
ContentShape("Parts_Audio_Summary", () => shapeHelper.Parts_Audio_Summary()), ContentShape("Parts_Audio_Summary", () => shapeHelper.Parts_Audio_Summary()),
ContentShape("Parts_Audio", () => shapeHelper.Parts_Audio()) ContentShape("Parts_Audio", () => shapeHelper.Parts_Audio())
); );
} }
protected override void Exporting(AudioPart part, ContentManagement.Handlers.ExportContentContext context) { protected override void Exporting(AudioPart part, ContentManagement.Handlers.ExportContentContext context) {
@@ -27,6 +27,7 @@ namespace Orchard.MediaLibrary.Drivers {
part.Length = int.Parse(length) part.Length = int.Parse(length)
); );
} }
protected override void Cloning(AudioPart originalPart, AudioPart clonePart, CloneContentContext context) { protected override void Cloning(AudioPart originalPart, AudioPart clonePart, CloneContentContext context) {
clonePart.Length = originalPart.Length; clonePart.Length = originalPart.Length;
} }

View File

@@ -27,6 +27,7 @@ namespace Orchard.MediaLibrary.Drivers {
part.Length = int.Parse(length) part.Length = int.Parse(length)
); );
} }
protected override void Cloning(DocumentPart originalPart, DocumentPart clonePart, CloneContentContext context) { protected override void Cloning(DocumentPart originalPart, DocumentPart clonePart, CloneContentContext context) {
clonePart.Length = originalPart.Length; clonePart.Length = originalPart.Length;
} }

View File

@@ -32,10 +32,11 @@ namespace Orchard.MediaLibrary.Drivers {
} }
protected override DriverResult Editor(MediaPart part, dynamic shapeHelper) { protected override DriverResult Editor(MediaPart part, dynamic shapeHelper) {
return ContentShape("Parts_Media_Edit", () => shapeHelper.EditorTemplate(TemplateName: "Parts.Media.Edit", Model: part, Prefix: Prefix)); return ContentShape("Parts_Media_Edit",
() => shapeHelper.EditorTemplate(TemplateName: "Parts.Media.Edit", Model: part, Prefix: Prefix));
} }
protected override void Importing(MediaPart part, ContentManagement.Handlers.ImportContentContext context) { protected override void Importing(MediaPart part, ImportContentContext context) {
// Don't do anything if the tag is not specified. // Don't do anything if the tag is not specified.
if (context.Data.Element(part.PartDefinition.Name) == null) { if (context.Data.Element(part.PartDefinition.Name) == null) {
return; return;
@@ -76,12 +77,12 @@ namespace Orchard.MediaLibrary.Drivers {
} }
protected override void Cloning(MediaPart originalPart, MediaPart clonePart, CloneContentContext context) { protected override void Cloning(MediaPart originalPart, MediaPart clonePart, CloneContentContext context) {
clonePart.Caption = originalPart.Caption;
clonePart.FileName = originalPart.FileName;
clonePart.FolderPath = originalPart.FolderPath;
clonePart.LogicalType = originalPart.LogicalType;
clonePart.AlternateText = originalPart.AlternateText;
clonePart.MimeType = originalPart.MimeType; clonePart.MimeType = originalPart.MimeType;
clonePart.Caption = originalPart.Caption;
clonePart.AlternateText = originalPart.AlternateText;
clonePart.FolderPath = originalPart.FolderPath;
clonePart.FileName = originalPart.FileName;
clonePart.LogicalType = originalPart.LogicalType;
} }
} }
} }

View File

@@ -1,11 +1,10 @@
using Orchard.ContentManagement; using System.Xml;
using System.Xml.Linq;
using Orchard.ContentManagement;
using Orchard.ContentManagement.Drivers; using Orchard.ContentManagement.Drivers;
using Orchard.ContentManagement.FieldStorage.InfosetStorage; using Orchard.ContentManagement.FieldStorage.InfosetStorage;
using Orchard.MediaLibrary.Models;
using System.Xml;
using System.Xml.Linq;
using Orchard.ContentManagement.Handlers; using Orchard.ContentManagement.Handlers;
using System.Collections; using Orchard.MediaLibrary.Models;
namespace Orchard.MediaLibrary.Drivers { namespace Orchard.MediaLibrary.Drivers {
public class OEmbedPartDriver : ContentPartDriver<OEmbedPart> { public class OEmbedPartDriver : ContentPartDriver<OEmbedPart> {

View File

@@ -1,4 +1,5 @@
using System; using System;
using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Xml.Linq; using System.Xml.Linq;
using Orchard.ContentManagement; using Orchard.ContentManagement;
@@ -27,26 +28,26 @@ namespace Orchard.MediaProcessing.Drivers {
get { return "MediaProcessing"; } get { return "MediaProcessing"; }
} }
protected override DriverResult Display(ImageProfilePart part, string displayType, dynamic shapeHelper) { protected override DriverResult Display(ImageProfilePart part, string displayType, dynamic shapeHelper) =>
return ContentShape("Parts_MediaProcessing_ImageProfile", ContentShape("Parts_MediaProcessing_ImageProfile", () =>
() => shapeHelper.Parts_MediaProcessing_ImageProfile(Name: part.Name)); shapeHelper.Parts_MediaProcessing_ImageProfile(Name: part.Name));
}
protected override DriverResult Editor(ImageProfilePart part, dynamic shapeHelper) { protected override DriverResult Editor(ImageProfilePart part, dynamic shapeHelper) {
var viewModel = new ImageProfileViewModel { var viewModel = new ImageProfileViewModel {
Name = part.Name Name = part.Name
}; };
return ContentShape("Parts_MediaProcessing_ImageProfile_Edit",
() => shapeHelper.EditorTemplate(TemplateName: TemplateName, Model: viewModel, Prefix: Prefix)); return ContentShape("Parts_MediaProcessing_ImageProfile_Edit", () =>
shapeHelper.EditorTemplate(TemplateName: TemplateName, Model: viewModel, Prefix: Prefix));
} }
protected override DriverResult Editor(ImageProfilePart part, IUpdateModel updater, dynamic shapeHelper) { protected override DriverResult Editor(ImageProfilePart part, IUpdateModel updater, dynamic shapeHelper) {
var currentName = part.Name; var currentName = part.Name;
var viewModel = new ImageProfileViewModel(); var viewModel = new ImageProfileViewModel();
// It would be nice if IUpdateModel provided access to the IsValid property of the Controller, instead of having to track a local flag. // It would be nice if IUpdateModel provided access to the IsValid property of the Controller, instead of having to track a local flag.
var isValid = updater.TryUpdateModel(viewModel, Prefix, null, null); var isValid = updater.TryUpdateModel(viewModel, Prefix, null, null);
if (String.IsNullOrWhiteSpace(viewModel.Name)) { if (string.IsNullOrWhiteSpace(viewModel.Name)) {
updater.AddModelError("Name", T("The Name can't be empty.")); updater.AddModelError("Name", T("The Name can't be empty."));
isValid = false; isValid = false;
} }
@@ -71,17 +72,17 @@ namespace Orchard.MediaProcessing.Drivers {
element.Add( element.Add(
new XAttribute("Name", part.Name), new XAttribute("Name", part.Name),
new XElement("Filters", new XElement("Filters",
part.Filters.Select(filter => part.Filters.Select(filter =>
new XElement("Filter", new XElement("Filter",
new XAttribute("Description", filter.Description ?? ""), new XAttribute("Description", filter.Description ?? ""),
new XAttribute("Category", filter.Category ?? ""), new XAttribute("Category", filter.Category ?? ""),
new XAttribute("Type", filter.Type ?? ""), new XAttribute("Type", filter.Type ?? ""),
new XAttribute("Position", filter.Position), new XAttribute("Position", filter.Position),
new XAttribute("State", filter.State ?? "") new XAttribute("State", filter.State ?? "")
) )
)
) )
); )
);
} }
protected override void Importing(ImageProfilePart part, ImportContentContext context) { protected override void Importing(ImageProfilePart part, ImportContentContext context) {
@@ -106,5 +107,21 @@ namespace Orchard.MediaProcessing.Drivers {
part.Record.Filters.Add(result); part.Record.Filters.Add(result);
} }
} }
protected override void Cloning(ImageProfilePart originalPart, ImageProfilePart clonePart, CloneContentContext context) {
clonePart.Name = originalPart.Name;
clonePart.ModifiedUtc = originalPart.ModifiedUtc;
clonePart.Record.FileNames = new List<FileNameRecord>();
clonePart.Record.Filters = originalPart.Filters.Select(filter =>
new FilterRecord {
Description = filter.Description,
Category = filter.Category,
Type = filter.Type,
Position = filter.Position,
State = filter.State,
ImageProfilePartRecord = clonePart.Record
}).ToList(
);
}
} }
} }

View File

@@ -1,5 +1,4 @@
using System; using System.Linq;
using System.Linq;
using Orchard.ContentManagement; using Orchard.ContentManagement;
using Orchard.ContentManagement.Drivers; using Orchard.ContentManagement.Drivers;
using Orchard.ContentManagement.Handlers; using Orchard.ContentManagement.Handlers;
@@ -29,12 +28,12 @@ namespace Orchard.Projections.Drivers {
protected override DriverResult Editor(NavigationQueryPart part, dynamic shapeHelper) { protected override DriverResult Editor(NavigationQueryPart part, dynamic shapeHelper) {
return ContentShape("Parts_NavigationQueryPart_Edit", () => { return ContentShape("Parts_NavigationQueryPart_Edit", () => {
var model = new NavigationQueryPartEditViewModel { var model = new NavigationQueryPartEditViewModel {
Items = part.Items, Items = part.Items,
Skip = part.Skip, Skip = part.Skip,
QueryRecordId = part.QueryPartRecord == null ? "-1" : part.QueryPartRecord.Id.ToString(), QueryRecordId = part.QueryPartRecord == null ? "-1" : part.QueryPartRecord.Id.ToString(),
Queries = Services.ContentManager.Query<QueryPart, QueryPartRecord>().Join<TitlePartRecord>().OrderBy(x => x.Title).List(), Queries = Services.ContentManager.Query<QueryPart, QueryPartRecord>()
.Join<TitlePartRecord>().OrderBy(x => x.Title).List(),
}; };
return shapeHelper.EditorTemplate(TemplateName: TemplateName, Model: model, Prefix: Prefix); return shapeHelper.EditorTemplate(TemplateName: TemplateName, Model: model, Prefix: Prefix);
@@ -47,7 +46,7 @@ namespace Orchard.Projections.Drivers {
if (updater.TryUpdateModel(model, Prefix, null, null)) { if (updater.TryUpdateModel(model, Prefix, null, null)) {
part.Record.Items = model.Items; part.Record.Items = model.Items;
part.Record.Skip = model.Skip; part.Record.Skip = model.Skip;
part.Record.QueryPartRecord = _queryRepository.Get(Int32.Parse(model.QueryRecordId)); part.Record.QueryPartRecord = _queryRepository.Get(int.Parse(model.QueryRecordId));
} }
return Editor(part, shapeHelper); return Editor(part, shapeHelper);
@@ -59,8 +58,8 @@ namespace Orchard.Projections.Drivers {
return; return;
} }
context.ImportAttribute(part.PartDefinition.Name, "Items", x => part.Record.Items = Int32.Parse(x)); context.ImportAttribute(part.PartDefinition.Name, "Items", x => part.Record.Items = int.Parse(x));
context.ImportAttribute(part.PartDefinition.Name, "Offset", x => part.Record.Skip = Int32.Parse(x)); context.ImportAttribute(part.PartDefinition.Name, "Offset", x => part.Record.Skip = int.Parse(x));
} }
protected override void Imported(NavigationQueryPart part, ImportContentContext context) { protected override void Imported(NavigationQueryPart part, ImportContentContext context) {
@@ -70,18 +69,25 @@ namespace Orchard.Projections.Drivers {
part.Record.QueryPartRecord = context.GetItemFromSession(query).As<QueryPart>().Record; part.Record.QueryPartRecord = context.GetItemFromSession(query).As<QueryPart>().Record;
} }
} }
protected override void Exporting(NavigationQueryPart part, ExportContentContext context) { protected override void Exporting(NavigationQueryPart part, ExportContentContext context) {
context.Element(part.PartDefinition.Name).SetAttributeValue("Items", part.Record.Items); context.Element(part.PartDefinition.Name).SetAttributeValue("Items", part.Record.Items);
context.Element(part.PartDefinition.Name).SetAttributeValue("Offset", part.Record.Skip); context.Element(part.PartDefinition.Name).SetAttributeValue("Offset", part.Record.Skip);
if (part.Record.QueryPartRecord != null) { if (part.Record.QueryPartRecord != null) {
var queryPart = Services.ContentManager.Query<QueryPart, QueryPartRecord>("Query").Where(x => x.Id == part.Record.QueryPartRecord.Id).List().FirstOrDefault(); var queryPart = Services.ContentManager.Query<QueryPart, QueryPartRecord>("Query")
.Where(x => x.Id == part.Record.QueryPartRecord.Id).List().FirstOrDefault();
if (queryPart != null) { if (queryPart != null) {
var queryIdentity = Services.ContentManager.GetItemMetadata(queryPart).Identity; var queryIdentity = Services.ContentManager.GetItemMetadata(queryPart).Identity;
context.Element(part.PartDefinition.Name).SetAttributeValue("Query", queryIdentity.ToString()); context.Element(part.PartDefinition.Name).SetAttributeValue("Query", queryIdentity.ToString());
} }
} }
} }
protected override void Cloning(NavigationQueryPart originalPart, NavigationQueryPart clonePart, CloneContentContext context) {
clonePart.Items = originalPart.Items;
clonePart.Skip = originalPart.Skip;
clonePart.QueryPartRecord = originalPart.QueryPartRecord;
}
} }
} }

View File

@@ -10,7 +10,6 @@ using Orchard.Projections.Services;
using Orchard.Projections.ViewModels; using Orchard.Projections.ViewModels;
namespace Orchard.Projections.Drivers { namespace Orchard.Projections.Drivers {
public class QueryPartDriver : ContentPartDriver<QueryPart> { public class QueryPartDriver : ContentPartDriver<QueryPart> {
private readonly IProjectionManager _projectionManager; private readonly IProjectionManager _projectionManager;
private readonly IFormManager _formManager; private readonly IFormManager _formManager;
@@ -126,7 +125,8 @@ namespace Orchard.Projections.Drivers {
return; return;
} }
context.ImportAttribute(part.PartDefinition.Name, "VersionScope", scope => part.VersionScope = (QueryVersionScopeOptions)Enum.Parse(typeof(QueryVersionScopeOptions), scope)); context.ImportAttribute(part.PartDefinition.Name, "VersionScope", scope =>
part.VersionScope = (QueryVersionScopeOptions)Enum.Parse(typeof(QueryVersionScopeOptions), scope));
var queryElement = context.Data.Element(part.PartDefinition.Name); var queryElement = context.Data.Element(part.PartDefinition.Name);
@@ -197,7 +197,9 @@ namespace Orchard.Projections.Drivers {
DisplayType = layout.Attribute("DisplayType").Value, DisplayType = layout.Attribute("DisplayType").Value,
State = state, State = state,
Type = type, Type = type,
GUIdentifier = string.IsNullOrWhiteSpace(layout.Attribute("GUIdentifier").Value) ? Guid.NewGuid().ToString() : layout.Attribute("GUIdentifier").Value, GUIdentifier = string.IsNullOrWhiteSpace(layout.Attribute("GUIdentifier").Value)
? Guid.NewGuid().ToString()
: layout.Attribute("GUIdentifier").Value,
Properties = layout.Element("Properties").Elements("Property").Select(GetProperty).ToList(), Properties = layout.Element("Properties").Elements("Property").Select(GetProperty).ToList(),
GroupProperty = GetProperty(layout.Element("Group").Element("Property")) GroupProperty = GetProperty(layout.Element("Group").Element("Property"))
}; };
@@ -287,5 +289,92 @@ namespace Orchard.Projections.Drivers {
ZeroIsEmpty = Convert.ToBoolean(property.Attribute("ZeroIsEmpty").Value), ZeroIsEmpty = Convert.ToBoolean(property.Attribute("ZeroIsEmpty").Value),
}; };
} }
protected override void Cloning(QueryPart originalPart, QueryPart clonePart, CloneContentContext context) {
clonePart.VersionScope = originalPart.VersionScope;
clonePart.Record.FilterGroups = originalPart.FilterGroups.Select(originalGroup => {
var cloneGroup = new FilterGroupRecord {
QueryPartRecord = clonePart.Record
};
cloneGroup.Filters = originalGroup.Filters.Select(filter => new FilterRecord {
Category = filter.Category,
Description = filter.Description,
Position = filter.Position,
State = filter.State,
Type = filter.Type,
FilterGroupRecord = cloneGroup
}).ToList();
return cloneGroup;
}).ToList();
clonePart.Record.SortCriteria = originalPart.SortCriteria.Select(sortCriterion => new SortCriterionRecord {
Category = sortCriterion.Category,
Description = sortCriterion.Description,
Position = sortCriterion.Position,
State = sortCriterion.State,
Type = sortCriterion.Type,
QueryPartRecord = clonePart.Record
}).ToList();
clonePart.Record.Layouts = originalPart.Layouts.Select(layout => {
var cloneLayout = new LayoutRecord {
Category = layout.Category,
Description = layout.Description,
Display = layout.Display,
DisplayType = layout.DisplayType,
GUIdentifier = Guid.NewGuid().ToString(),
State = layout.State,
Type = layout.Type,
QueryPartRecord = clonePart.Record
};
cloneLayout.Properties = layout.Properties.Select(property => {
var cloneProperty = new PropertyRecord {
AddEllipsis = property.AddEllipsis,
Category = property.Category,
CreateLabel = property.CreateLabel,
CustomLabelCss = property.CustomLabelCss,
Description = property.Description,
CustomLabelTag = property.CustomLabelTag,
CustomPropertyCss = property.CustomPropertyCss,
CustomPropertyTag = property.CustomPropertyTag,
CustomWrapperCss = property.CustomWrapperCss,
CustomWrapperTag = property.CustomWrapperTag,
CustomizeLabelHtml = property.CustomizeLabelHtml,
CustomizePropertyHtml = property.CustomizePropertyHtml,
CustomizeWrapperHtml = property.CustomizeWrapperHtml,
ExcludeFromDisplay = property.ExcludeFromDisplay,
HideEmpty = property.HideEmpty,
Label = property.Label,
LinkToContent = property.LinkToContent,
MaxLength = property.MaxLength,
NoResultText = property.NoResultText,
Position = property.Position,
PreserveLines = property.PreserveLines,
RewriteOutputCondition = property.RewriteOutputCondition,
RewriteText = property.RewriteText,
State = property.State,
StripHtmlTags = property.StripHtmlTags,
TrimLength = property.TrimLength,
TrimOnWordBoundary = property.TrimOnWordBoundary,
TrimWhiteSpace = property.TrimWhiteSpace,
Type = property.Type,
ZeroIsEmpty = property.ZeroIsEmpty,
LayoutRecord = cloneLayout
};
if (cloneLayout.GroupProperty == null && layout.GroupProperty == property) {
cloneLayout.GroupProperty = cloneProperty;
}
return cloneProperty;
}).ToList();
return cloneLayout;
}).ToList();
}
} }
} }

View File

@@ -56,12 +56,12 @@ namespace Orchard.PublishLater.Drivers {
protected override DriverResult Display(PublishLaterPart part, string displayType, dynamic shapeHelper) { protected override DriverResult Display(PublishLaterPart part, string displayType, dynamic shapeHelper) {
return Combined( return Combined(
ContentShape("Parts_PublishLater_Metadata", ContentShape("Parts_PublishLater_Metadata",
() => shapeHelper.Parts_PublishLater_Metadata(ScheduledPublishUtc: part.ScheduledPublishUtc.Value)), () => shapeHelper.Parts_PublishLater_Metadata(ScheduledPublishUtc: part.ScheduledPublishUtc.Value)),
ContentShape("Parts_PublishLater_Metadata_Summary", ContentShape("Parts_PublishLater_Metadata_Summary",
() => shapeHelper.Parts_PublishLater_Metadata_Summary(ScheduledPublishUtc: part.ScheduledPublishUtc.Value)), () => shapeHelper.Parts_PublishLater_Metadata_Summary(ScheduledPublishUtc: part.ScheduledPublishUtc.Value)),
ContentShape("Parts_PublishLater_Metadata_SummaryAdmin", ContentShape("Parts_PublishLater_Metadata_SummaryAdmin",
() => shapeHelper.Parts_PublishLater_Metadata_SummaryAdmin(ScheduledPublishUtc: part.ScheduledPublishUtc.Value)) () => shapeHelper.Parts_PublishLater_Metadata_SummaryAdmin(ScheduledPublishUtc: part.ScheduledPublishUtc.Value))
); );
} }
private PublishLaterViewModel BuildViewModelFromPart(PublishLaterPart part) { private PublishLaterViewModel BuildViewModelFromPart(PublishLaterPart part) {
@@ -79,7 +79,7 @@ namespace Orchard.PublishLater.Drivers {
var model = BuildViewModelFromPart(part); var model = BuildViewModelFromPart(part);
return ContentShape("Parts_PublishLater_Edit", return ContentShape("Parts_PublishLater_Edit",
() => shapeHelper.EditorTemplate(TemplateName: TemplateName, Model: model, Prefix: Prefix)); () => shapeHelper.EditorTemplate(TemplateName: TemplateName, Model: model, Prefix: Prefix));
} }
protected override DriverResult Editor(PublishLaterPart part, IUpdateModel updater, dynamic shapeHelper) { protected override DriverResult Editor(PublishLaterPart part, IUpdateModel updater, dynamic shapeHelper) {
@@ -101,7 +101,7 @@ namespace Orchard.PublishLater.Drivers {
} }
} }
catch (FormatException) { catch (FormatException) {
updater.AddModelError(Prefix, T("'{0} {1}' could not be parsed as a valid date and time.", model.Editor.Date, model.Editor.Time)); updater.AddModelError(Prefix, T("'{0} {1}' could not be parsed as a valid date and time.", model.Editor.Date, model.Editor.Time));
} }
} }
else { else {
@@ -134,5 +134,9 @@ namespace Orchard.PublishLater.Drivers {
.SetAttributeValue("ScheduledPublishUtc", XmlConvert.ToString(scheduled.Value, XmlDateTimeSerializationMode.Utc)); .SetAttributeValue("ScheduledPublishUtc", XmlConvert.ToString(scheduled.Value, XmlDateTimeSerializationMode.Utc));
} }
} }
protected override void Cloning(PublishLaterPart originalPart, PublishLaterPart clonePart, CloneContentContext context) {
clonePart.ScheduledPublishUtc.Value = originalPart.ScheduledPublishUtc.Value;
}
} }
} }

View File

@@ -1,8 +1,10 @@
using System; using System;
using System.Collections.Generic;
using System.Linq; using System.Linq;
using Orchard.ContentManagement.Drivers;
using Orchard.Data;
using Orchard.ContentManagement; using Orchard.ContentManagement;
using Orchard.ContentManagement.Drivers;
using Orchard.ContentManagement.Handlers;
using Orchard.Data;
using Orchard.Localization; using Orchard.Localization;
using Orchard.Roles.Events; using Orchard.Roles.Events;
using Orchard.Roles.Models; using Orchard.Roles.Models;
@@ -10,7 +12,6 @@ using Orchard.Roles.Services;
using Orchard.Roles.ViewModels; using Orchard.Roles.ViewModels;
using Orchard.Security; using Orchard.Security;
using Orchard.UI.Notify; using Orchard.UI.Notify;
using System.Collections.Generic;
namespace Orchard.Roles.Drivers { namespace Orchard.Roles.Drivers {
public class UserRolesPartDriver : ContentPartDriver<UserRolesPart> { public class UserRolesPartDriver : ContentPartDriver<UserRolesPart> {
@@ -49,42 +50,38 @@ namespace Orchard.Roles.Drivers {
public Localizer T { get; set; } public Localizer T { get; set; }
private Lazy<IEnumerable<RoleRecord>> _allRoles; private readonly Lazy<IEnumerable<RoleRecord>> _allRoles;
protected override DriverResult Editor(UserRolesPart userRolesPart, dynamic shapeHelper) { protected override DriverResult Editor(UserRolesPart userRolesPart, dynamic shapeHelper) =>
ContentShape("Parts_Roles_UserRoles_Edit", () => {
return ContentShape("Parts_Roles_UserRoles_Edit", var currentUser = _authenticationService.GetAuthenticatedUser();
() => { // Get the roles we are authorized to assign
var currentUser = _authenticationService.GetAuthenticatedUser(); var authorizedRoleIds = _allRoles.Value
// Get the roles we are authorized to assign .Where(rr => _authorizationService.TryCheckAccess(
var authorizedRoleIds = _allRoles.Value Permissions.CreatePermissionForAssignRole(rr.Name),
.Where(rr => _authorizationService.TryCheckAccess( currentUser,
Permissions.CreatePermissionForAssignRole(rr.Name), userRolesPart))
currentUser, .Select(rr => rr.Id).ToList();
userRolesPart)) // If the user has no roles they can assign, we will show nothing
.Select(rr => rr.Id).ToList(); if (!authorizedRoleIds.Any()) {
// If the user has no roles they can assign, we will show nothing return null;
if (!authorizedRoleIds.Any()) { }
return null; var allRoles = _allRoles.Value
} .Select(x => new UserRoleEntry {
var allRoles = _allRoles.Value RoleId = x.Id,
.Select(x => new UserRoleEntry { Name = x.Name,
RoleId = x.Id, Granted = userRolesPart.Roles.Contains(x.Name)
Name = x.Name, });
Granted = userRolesPart.Roles.Contains(x.Name) var model = new UserRolesViewModel {
}); User = userRolesPart.As<IUser>(),
var model = new UserRolesViewModel { UserRoles = userRolesPart,
User = userRolesPart.As<IUser>(), Roles = allRoles.ToList(),
UserRoles = userRolesPart, AuthorizedRoleIds = authorizedRoleIds
Roles = allRoles.ToList(), };
AuthorizedRoleIds = authorizedRoleIds return shapeHelper.EditorTemplate(TemplateName: TemplateName, Model: model, Prefix: Prefix);
}; });
return shapeHelper.EditorTemplate(TemplateName: TemplateName, Model: model, Prefix: Prefix);
});
}
protected override DriverResult Editor(UserRolesPart userRolesPart, IUpdateModel updater, dynamic shapeHelper) { protected override DriverResult Editor(UserRolesPart userRolesPart, IUpdateModel updater, dynamic shapeHelper) {
var currentUser = _authenticationService.GetAuthenticatedUser(); var currentUser = _authenticationService.GetAuthenticatedUser();
// Get the roles we are authorized to assign // Get the roles we are authorized to assign
var authorizedRoleIds = _allRoles.Value var authorizedRoleIds = _allRoles.Value
@@ -135,11 +132,10 @@ namespace Orchard.Roles.Drivers {
() => shapeHelper.EditorTemplate(TemplateName: TemplateName, Model: model, Prefix: Prefix)); () => shapeHelper.EditorTemplate(TemplateName: TemplateName, Model: model, Prefix: Prefix));
} }
private static UserRolesViewModel BuildEditorViewModel(UserRolesPart userRolesPart) { private static UserRolesViewModel BuildEditorViewModel(UserRolesPart userRolesPart) =>
return new UserRolesViewModel { User = userRolesPart.As<IUser>(), UserRoles = userRolesPart }; new UserRolesViewModel { User = userRolesPart.As<IUser>(), UserRoles = userRolesPart };
}
protected override void Importing(UserRolesPart part, ContentManagement.Handlers.ImportContentContext context) { protected override void Importing(UserRolesPart part, ImportContentContext context) {
// Don't do anything if the tag is not specified. // Don't do anything if the tag is not specified.
if (context.Data.Element(part.PartDefinition.Name) == null) { if (context.Data.Element(part.PartDefinition.Name) == null) {
return; return;
@@ -168,8 +164,8 @@ namespace Orchard.Roles.Drivers {
}); });
} }
protected override void Exporting(UserRolesPart part, ContentManagement.Handlers.ExportContentContext context) { protected override void Exporting(UserRolesPart part, ExportContentContext context) {
context.Element(part.PartDefinition.Name).SetAttributeValue("Roles", string.Join(",", part.Roles)); context.Element(part.PartDefinition.Name).SetAttributeValue("Roles", string.Join(",", part.Roles));
} }
} }
} }

View File

@@ -37,7 +37,7 @@ namespace Orchard.Search.Drivers {
}; };
if (updater != null) { if (updater != null) {
if (updater.TryUpdateModel(viewModel, Prefix, null, new[] {"AvailableIndexes"})) { if (updater.TryUpdateModel(viewModel, Prefix, null, new[] { "AvailableIndexes" })) {
part.OverrideIndex = viewModel.OverrideIndex; part.OverrideIndex = viewModel.OverrideIndex;
part.SelectedIndex = viewModel.SelectedIndex; part.SelectedIndex = viewModel.SelectedIndex;
} }
@@ -56,5 +56,10 @@ namespace Orchard.Search.Drivers {
context.ImportAttribute(part.PartDefinition.Name, "OverrideIndex", x => part.OverrideIndex = XmlHelper.Parse<bool>(x)); context.ImportAttribute(part.PartDefinition.Name, "OverrideIndex", x => part.OverrideIndex = XmlHelper.Parse<bool>(x));
context.ImportAttribute(part.PartDefinition.Name, "SelectedIndex", x => part.SelectedIndex = x); context.ImportAttribute(part.PartDefinition.Name, "SelectedIndex", x => part.SelectedIndex = x);
} }
protected override void Cloning(SearchFormPart originalPart, SearchFormPart clonePart, CloneContentContext context) {
clonePart.OverrideIndex = originalPart.OverrideIndex;
clonePart.SelectedIndex = originalPart.SelectedIndex;
}
} }
} }

View File

@@ -9,7 +9,6 @@ using Orchard.Search.Models;
using Orchard.Search.ViewModels; using Orchard.Search.ViewModels;
namespace Orchard.Search.Drivers { namespace Orchard.Search.Drivers {
public class SearchSettingsPartDriver : ContentPartDriver<SearchSettingsPart> { public class SearchSettingsPartDriver : ContentPartDriver<SearchSettingsPart> {
private readonly IIndexManager _indexManager; private readonly IIndexManager _indexManager;
@@ -22,10 +21,8 @@ namespace Orchard.Search.Drivers {
protected override string Prefix { get { return "SearchSettings"; } } protected override string Prefix { get { return "SearchSettings"; } }
protected override DriverResult Editor(SearchSettingsPart part, dynamic shapeHelper) { protected override DriverResult Editor(SearchSettingsPart part, dynamic shapeHelper) =>
return Editor(part, null, shapeHelper); Editor(part, null, shapeHelper);
}
protected override DriverResult Editor(SearchSettingsPart part, IUpdateModel updater, dynamic shapeHelper) { protected override DriverResult Editor(SearchSettingsPart part, IUpdateModel updater, dynamic shapeHelper) {
return Combined( return Combined(
@@ -90,4 +87,4 @@ namespace Orchard.Search.Drivers {
}); });
} }
} }
} }

View File

@@ -8,30 +8,21 @@ using Orchard.Tags.Models;
namespace Orchard.Tags.Drivers { namespace Orchard.Tags.Drivers {
[OrchardFeature("Orchard.Tags.TagCloud")] [OrchardFeature("Orchard.Tags.TagCloud")]
public class TagCloudDriver : ContentPartDriver<TagCloudPart> { public class TagCloudDriver : ContentPartDriver<TagCloudPart> {
protected override string Prefix => "tagcloud";
protected override string Prefix {
get {
return "tagcloud";
}
}
protected override DriverResult Display(TagCloudPart part, string displayType, dynamic shapeHelper) { protected override DriverResult Display(TagCloudPart part, string displayType, dynamic shapeHelper) {
return ContentShape("Parts_TagCloud", return ContentShape("Parts_TagCloud", () => shapeHelper.Parts_TagCloud(
() => shapeHelper.Parts_TagCloud( TagCounts: part.TagCounts,
TagCounts: part.TagCounts, ContentPart: part,
ContentPart: part, ContentItem: part.ContentItem));
ContentItem: part.ContentItem));
} }
protected override DriverResult Editor(TagCloudPart part, dynamic shapeHelper) { protected override DriverResult Editor(TagCloudPart part, dynamic shapeHelper) =>
ContentShape("Parts_TagCloud_Edit", () => shapeHelper.EditorTemplate(
TemplateName: "Parts/TagCloud",
Model: part,
Prefix: Prefix));
return ContentShape("Parts_TagCloud_Edit",
() => shapeHelper.EditorTemplate(
TemplateName: "Parts/TagCloud",
Model: part,
Prefix: Prefix));
}
protected override DriverResult Editor(TagCloudPart part, IUpdateModel updater, dynamic shapeHelper) { protected override DriverResult Editor(TagCloudPart part, IUpdateModel updater, dynamic shapeHelper) {
updater.TryUpdateModel(part, Prefix, null, null); updater.TryUpdateModel(part, Prefix, null, null);
return Editor(part, shapeHelper); return Editor(part, shapeHelper);
@@ -51,5 +42,10 @@ namespace Orchard.Tags.Drivers {
part.Slug = context.Attribute(part.PartDefinition.Name, "Slug"); part.Slug = context.Attribute(part.PartDefinition.Name, "Slug");
part.Buckets = Convert.ToInt32(context.Attribute(part.PartDefinition.Name, "Buckets")); part.Buckets = Convert.ToInt32(context.Attribute(part.PartDefinition.Name, "Buckets"));
} }
protected override void Cloning(TagCloudPart originalPart, TagCloudPart clonePart, CloneContentContext context) {
clonePart.Slug = originalPart.Slug;
clonePart.Buckets = originalPart.Buckets;
}
} }
} }

View File

@@ -23,9 +23,8 @@ namespace Orchard.Taxonomies.Drivers {
protected override string Prefix { get { return "TaxonomyNavigationPart"; } } protected override string Prefix { get { return "TaxonomyNavigationPart"; } }
protected override DriverResult Editor(TaxonomyNavigationPart part, dynamic shapeHelper) { protected override DriverResult Editor(TaxonomyNavigationPart part, dynamic shapeHelper) =>
return Editor(part, null, shapeHelper); Editor(part, null, shapeHelper);
}
protected override DriverResult Editor(TaxonomyNavigationPart part, IUpdateModel updater, dynamic shapeHelper) { protected override DriverResult Editor(TaxonomyNavigationPart part, IUpdateModel updater, dynamic shapeHelper) {
return ContentShape( return ContentShape(
@@ -112,24 +111,27 @@ namespace Orchard.Taxonomies.Drivers {
part.LevelsToDisplay = Int32.Parse(context.Attribute(part.PartDefinition.Name, "LevelsToDisplay")); part.LevelsToDisplay = Int32.Parse(context.Attribute(part.PartDefinition.Name, "LevelsToDisplay"));
var taxonomyId = context.Attribute(part.PartDefinition.Name, "TaxonomyId"); var taxonomyId = context.Attribute(part.PartDefinition.Name, "TaxonomyId");
var taxonomy = context.GetItemFromSession(taxonomyId); var taxonomy = context.GetItemFromSession(taxonomyId)
?? throw new OrchardException(T("Unknown taxonomy: {0}", taxonomyId));
if (taxonomy == null) {
throw new OrchardException(T("Unknown taxonomy: {0}", taxonomyId));
}
part.TaxonomyId = taxonomy.Id; part.TaxonomyId = taxonomy.Id;
var termId = context.Attribute(part.PartDefinition.Name, "TermId"); var termId = context.Attribute(part.PartDefinition.Name, "TermId");
if (!String.IsNullOrEmpty(termId)) {
var term = context.GetItemFromSession(termId);
if (term == null) { if (!String.IsNullOrEmpty(termId)) {
throw new OrchardException(T("Unknown term: {0}", termId)); var term = context.GetItemFromSession(termId)
} ?? throw new OrchardException(T("Unknown term: {0}", termId));
part.TermId = term.Id; part.TermId = term.Id;
} }
} }
protected override void Cloning(TaxonomyNavigationPart originalPart, TaxonomyNavigationPart clonePart, CloneContentContext context) {
clonePart.DisplayContentCount = originalPart.DisplayContentCount;
clonePart.DisplayRootTerm = originalPart.DisplayRootTerm;
clonePart.HideEmptyTerms = originalPart.HideEmptyTerms;
clonePart.LevelsToDisplay = originalPart.LevelsToDisplay;
clonePart.TaxonomyId = originalPart.TaxonomyId;
clonePart.TermId = originalPart.TermId;
}
} }
} }

View File

@@ -5,13 +5,13 @@ using System.Xml.Linq;
using Orchard.ContentManagement; using Orchard.ContentManagement;
using Orchard.ContentManagement.Drivers; using Orchard.ContentManagement.Drivers;
using Orchard.ContentManagement.Handlers; using Orchard.ContentManagement.Handlers;
using Orchard.Core.Title.Models;
using Orchard.Data; using Orchard.Data;
using Orchard.Localization; using Orchard.Localization;
using Orchard.Templates.Models; using Orchard.Templates.Models;
using Orchard.Templates.Services; using Orchard.Templates.Services;
using Orchard.Templates.ViewModels; using Orchard.Templates.ViewModels;
using Orchard.Utility.Extensions; using Orchard.Utility.Extensions;
using Orchard.Core.Title.Models;
namespace Orchard.Templates.Drivers { namespace Orchard.Templates.Drivers {
public class ShapePartDriver : ContentPartDriver<ShapePart> { public class ShapePartDriver : ContentPartDriver<ShapePart> {
@@ -31,13 +31,11 @@ namespace Orchard.Templates.Drivers {
Localizer T { get; set; } Localizer T { get; set; }
protected override DriverResult Display(ShapePart part, string displayType, dynamic shapeHelper) { protected override DriverResult Display(ShapePart part, string displayType, dynamic shapeHelper) =>
return ContentShape("Parts_Shape_SummaryAdmin", () => shapeHelper.Parts_Shape_SummaryAdmin()); ContentShape("Parts_Shape_SummaryAdmin", () => shapeHelper.Parts_Shape_SummaryAdmin());
}
protected override DriverResult Editor(ShapePart part, dynamic shapeHelper) { protected override DriverResult Editor(ShapePart part, dynamic shapeHelper) =>
return Editor(part, null, shapeHelper); Editor(part, null, shapeHelper);
}
protected override DriverResult Editor(ShapePart part, IUpdateModel updater, dynamic shapeHelper) { protected override DriverResult Editor(ShapePart part, IUpdateModel updater, dynamic shapeHelper) {
var viewModel = new ShapePartViewModel { var viewModel = new ShapePartViewModel {
@@ -101,6 +99,11 @@ namespace Orchard.Templates.Drivers {
} }
} }
protected override void Cloning(ShapePart originalPart, ShapePart clonePart, CloneContentContext context) {
clonePart.Template = originalPart.Template;
clonePart.RenderingMode = originalPart.RenderingMode;
}
private bool ValidateShapeName(ShapePart part, IUpdateModel updater) { private bool ValidateShapeName(ShapePart part, IUpdateModel updater) {
var titleViewModel = new TitleViewModel(); var titleViewModel = new TitleViewModel();
if (!updater.TryUpdateModel(titleViewModel, "Title", null, null)) if (!updater.TryUpdateModel(titleViewModel, "Title", null, null))

View File

@@ -1,5 +1,4 @@
using System; using System;
using System.Collections.Generic;
using System.Linq; using System.Linq;
using Orchard.Conditions.Services; using Orchard.Conditions.Services;
using Orchard.ContentManagement; using Orchard.ContentManagement;
@@ -10,7 +9,6 @@ using Orchard.Widgets.Models;
using Orchard.Widgets.Services; using Orchard.Widgets.Services;
namespace Orchard.Widgets.Drivers { namespace Orchard.Widgets.Drivers {
public class LayerPartDriver : ContentPartDriver<LayerPart> { public class LayerPartDriver : ContentPartDriver<LayerPart> {
private readonly IConditionManager _conditionManager; private readonly IConditionManager _conditionManager;
private readonly IWidgetsService _widgetsService; private readonly IWidgetsService _widgetsService;
@@ -18,7 +16,6 @@ namespace Orchard.Widgets.Drivers {
public LayerPartDriver( public LayerPartDriver(
IConditionManager conditionManager, IConditionManager conditionManager,
IWidgetsService widgetsService) { IWidgetsService widgetsService) {
_conditionManager = conditionManager; _conditionManager = conditionManager;
_widgetsService = widgetsService; _widgetsService = widgetsService;
@@ -27,14 +24,9 @@ namespace Orchard.Widgets.Drivers {
public Localizer T { get; set; } public Localizer T { get; set; }
protected override DriverResult Editor(LayerPart layerPart, dynamic shapeHelper) { protected override DriverResult Editor(LayerPart layerPart, dynamic shapeHelper) =>
var results = new List<DriverResult> { ContentShape("Parts_Widgets_LayerPart",
ContentShape("Parts_Widgets_LayerPart", () => shapeHelper.EditorTemplate(TemplateName: "Parts.Widgets.LayerPart", Model: layerPart, Prefix: Prefix));
() => shapeHelper.EditorTemplate(TemplateName: "Parts.Widgets.LayerPart", Model: layerPart, Prefix: Prefix))
};
return Combined(results.ToArray());
}
protected override DriverResult Editor(LayerPart layerPart, IUpdateModel updater, dynamic shapeHelper) { protected override DriverResult Editor(LayerPart layerPart, IUpdateModel updater, dynamic shapeHelper) {
if (updater.TryUpdateModel(layerPart, Prefix, null, null)) { if (updater.TryUpdateModel(layerPart, Prefix, null, null)) {
@@ -87,5 +79,11 @@ namespace Orchard.Widgets.Drivers {
context.Element(part.PartDefinition.Name).SetAttributeValue("Description", part.Description); context.Element(part.PartDefinition.Name).SetAttributeValue("Description", part.Description);
context.Element(part.PartDefinition.Name).SetAttributeValue("LayerRule", part.LayerRule); context.Element(part.PartDefinition.Name).SetAttributeValue("LayerRule", part.LayerRule);
} }
protected override void Cloning(LayerPart originalPart, LayerPart clonePart, CloneContentContext context) {
clonePart.Name = originalPart.Name;
clonePart.Description = originalPart.Description;
clonePart.LayerRule = originalPart.LayerRule;
}
} }
} }

View File

@@ -1,14 +1,13 @@
using System; using System;
using System.Collections.Generic;
using Orchard.ContentManagement; using Orchard.ContentManagement;
using Orchard.ContentManagement.Drivers; using Orchard.ContentManagement.Drivers;
using Orchard.ContentManagement.Handlers;
using Orchard.Localization; using Orchard.Localization;
using Orchard.Utility.Extensions; using Orchard.Utility.Extensions;
using Orchard.Widgets.Models; using Orchard.Widgets.Models;
using Orchard.Widgets.Services; using Orchard.Widgets.Services;
namespace Orchard.Widgets.Drivers { namespace Orchard.Widgets.Drivers {
public class WidgetPartDriver : ContentPartDriver<WidgetPart> { public class WidgetPartDriver : ContentPartDriver<WidgetPart> {
private readonly IWidgetsService _widgetsService; private readonly IWidgetsService _widgetsService;
private readonly IContentManager _contentManager; private readonly IContentManager _contentManager;
@@ -16,7 +15,6 @@ namespace Orchard.Widgets.Drivers {
public WidgetPartDriver(IWidgetsService widgetsService, IContentManager contentManager) { public WidgetPartDriver(IWidgetsService widgetsService, IContentManager contentManager) {
_widgetsService = widgetsService; _widgetsService = widgetsService;
_contentManager = contentManager; _contentManager = contentManager;
T = NullLocalizer.Instance; T = NullLocalizer.Instance;
} }
@@ -30,12 +28,8 @@ namespace Orchard.Widgets.Drivers {
widgetPart.AvailableZones = _widgetsService.GetZones(); widgetPart.AvailableZones = _widgetsService.GetZones();
widgetPart.AvailableLayers = _widgetsService.GetLayers(); widgetPart.AvailableLayers = _widgetsService.GetLayers();
var results = new List<DriverResult> { return ContentShape("Parts_Widgets_WidgetPart",
ContentShape("Parts_Widgets_WidgetPart", () => shapeHelper.EditorTemplate(TemplateName: "Parts.Widgets.WidgetPart", Model: widgetPart, Prefix: Prefix));
() => shapeHelper.EditorTemplate(TemplateName: "Parts.Widgets.WidgetPart", Model: widgetPart, Prefix: Prefix))
};
return Combined(results.ToArray());
} }
protected override DriverResult Editor(WidgetPart widgetPart, IUpdateModel updater, dynamic shapeHelper) { protected override DriverResult Editor(WidgetPart widgetPart, IUpdateModel updater, dynamic shapeHelper) {
@@ -100,5 +94,14 @@ namespace Orchard.Widgets.Drivers {
context.Element(part.PartDefinition.Name).SetAttributeValue("Name", part.Name); context.Element(part.PartDefinition.Name).SetAttributeValue("Name", part.Name);
context.Element(part.PartDefinition.Name).SetAttributeValue("CssClasses", part.CssClasses); context.Element(part.PartDefinition.Name).SetAttributeValue("CssClasses", part.CssClasses);
} }
protected override void Cloning(WidgetPart originalPart, WidgetPart clonePart, CloneContentContext context) {
clonePart.Title = originalPart.Title;
clonePart.Position = originalPart.Position;
clonePart.Zone = originalPart.Zone;
clonePart.RenderTitle = originalPart.RenderTitle;
clonePart.Name = originalPart.Name;
clonePart.CssClasses = originalPart.CssClasses;
}
} }
} }

View File

@@ -31,8 +31,8 @@ namespace Orchard.ContentManagement.Drivers.Coordinators {
foreach (var typePartDefinition in contentTypeDefinition.Parts) { foreach (var typePartDefinition in contentTypeDefinition.Parts) {
var partName = typePartDefinition.PartDefinition.Name; var partName = typePartDefinition.PartDefinition.Name;
var partInfo = partInfos.FirstOrDefault(pi => pi.PartName == partName); var partInfo = partInfos.FirstOrDefault(pi => pi.PartName == partName);
var part = partInfo != null var part = partInfo != null
? partInfo.Factory(typePartDefinition) ? partInfo.Factory(typePartDefinition)
: new ContentPart { TypePartDefinition = typePartDefinition }; : new ContentPart { TypePartDefinition = typePartDefinition };
context.Builder.Weld(part); context.Builder.Weld(part);
} }
@@ -45,24 +45,21 @@ namespace Orchard.ContentManagement.Drivers.Coordinators {
public override void BuildDisplay(BuildDisplayContext context) { public override void BuildDisplay(BuildDisplayContext context) {
_drivers.Invoke(driver => { _drivers.Invoke(driver => {
var result = driver.BuildDisplay(context); var result = driver.BuildDisplay(context);
if (result != null) result?.Apply(context);
result.Apply(context);
}, Logger); }, Logger);
} }
public override void BuildEditor(BuildEditorContext context) { public override void BuildEditor(BuildEditorContext context) {
_drivers.Invoke(driver => { _drivers.Invoke(driver => {
var result = driver.BuildEditor(context); var result = driver.BuildEditor(context);
if (result != null) result?.Apply(context);
result.Apply(context);
}, Logger); }, Logger);
} }
public override void UpdateEditor(UpdateEditorContext context) { public override void UpdateEditor(UpdateEditorContext context) {
_drivers.Invoke(driver => { _drivers.Invoke(driver => {
var result = driver.UpdateEditor(context); var result = driver.UpdateEditor(context);
if (result != null) result?.Apply(context);
result.Apply(context);
}, Logger); }, Logger);
} }
@@ -97,12 +94,14 @@ namespace Orchard.ContentManagement.Drivers.Coordinators {
} }
public override void Cloning(CloneContentContext context) { public override void Cloning(CloneContentContext context) {
context.Logger = Logger;
foreach (var contentPartDriver in _drivers) { foreach (var contentPartDriver in _drivers) {
contentPartDriver.Cloning(context); contentPartDriver.Cloning(context);
} }
} }
public override void Cloned(CloneContentContext context) { public override void Cloned(CloneContentContext context) {
context.Logger = Logger;
foreach (var contentPartDriver in _drivers) { foreach (var contentPartDriver in _drivers) {
contentPartDriver.Cloned(context); contentPartDriver.Cloned(context);
} }