Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#7412: Verified and added several Cloning overrides in many drivers #7592

Open
wants to merge 2 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -96,5 +96,9 @@ protected override void Importing(ContainablePart part, ImportContentContext con
protected override void Exporting(ContainablePart part, ExportContentContext context) {
context.Element(part.PartDefinition.Name).SetAttributeValue("Position", part.Position);
}

protected override void Cloning(ContainablePart originalPart, ContainablePart clonePart, CloneContentContext context) {
clonePart.Position = originalPart.Position;
}
}
}
12 changes: 12 additions & 0 deletions src/Orchard.Web/Core/Containers/Drivers/ContainerPartDriver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -179,5 +179,17 @@ protected override void Exporting(ContainerPart part, ExportContentContext conte
context.Element(part.PartDefinition.Name).SetAttributeValue("AdminMenuImageSet", part.AdminMenuImageSet);
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;
}
}
}
11 changes: 8 additions & 3 deletions src/Orchard.Web/Core/Contents/Controllers/AdminController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,7 @@ private ActionResult EditPOST(int id, string returnUrl, Action<ContentItem> cond
}

[HttpPost]
public ActionResult Clone(int id) {
public ActionResult Clone(int id, string returnUrl) {
var originalContentItem = _contentManager.GetLatest(id);

if (!Services.Authorizer.Authorize(Permissions.ViewContent, originalContentItem, T("Couldn't open original content")))
Expand All @@ -404,8 +404,13 @@ public ActionResult Clone(int id) {

Services.Notifier.Success(T("Successfully cloned. The clone was saved as a draft."));

var adminRouteValues = _contentManager.GetItemMetadata(cloneContentItem).AdminRouteValues;
return RedirectToRoute(adminRouteValues);
if (string.IsNullOrWhiteSpace(returnUrl)) {
var adminRouteValues = _contentManager.GetItemMetadata(cloneContentItem).AdminRouteValues;
return RedirectToRoute(adminRouteValues);
}
else {
return this.RedirectLocal(returnUrl, () => RedirectToAction("List"));
}
}

[HttpPost]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
}
@Html.ItemEditLink(T("Edit").Text, contentItem);
@T(" | ")
@Html.ActionLink(T(" Clone").Text, "Clone", "Admin", new { Id = contentItem.Id, ReturnUrl = Request.ToUrlString(), Area = "Contents" }, new { itemprop = "UnsafeUrl" });
@Html.ActionLink(T(" Clone").Text, "Clone", "Admin", new { Id = contentItem.Id, Area = "Contents" }, new { itemprop = "UnsafeUrl" });
}

@if (hasPublished && authorizedToPublish) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using Orchard.ContentManagement;
using Orchard.ContentManagement.Drivers;
using Orchard.ContentManagement.Handlers;
using Orchard.Core.Navigation.Models;
using Orchard.Core.Navigation.Settings;
using Orchard.Localization;
Expand Down Expand Up @@ -94,5 +95,11 @@ protected override void Exporting(AdminMenuPart part, ContentManagement.Handlers
context.Element(part.PartDefinition.Name).SetAttributeValue("AdminMenuPosition", part.AdminMenuPosition);
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;
}
}
}
5 changes: 5 additions & 0 deletions src/Orchard.Web/Core/Navigation/Drivers/MenuItemPartDriver.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using Orchard.ContentManagement;
using Orchard.ContentManagement.Drivers;
using Orchard.ContentManagement.Handlers;
using Orchard.Core.Navigation.Models;
using Orchard.Security;

Expand Down Expand Up @@ -48,5 +49,9 @@ protected override void Importing(MenuItemPart part, ContentManagement.Handlers.
protected override void Exporting(MenuItemPart part, ContentManagement.Handlers.ExportContentContext context) {
context.Element(part.PartDefinition.Name).SetAttributeValue("Url", part.Url);
}

protected override void Cloning(MenuItemPart originalPart, MenuItemPart clonePart, CloneContentContext context) {
clonePart.Url = originalPart.Url;
}
}
}
7 changes: 7 additions & 0 deletions src/Orchard.Web/Core/Navigation/Drivers/MenuPartDriver.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System.Linq;
using Orchard.ContentManagement;
using Orchard.ContentManagement.Drivers;
using Orchard.ContentManagement.Handlers;
using Orchard.Core.Navigation.Models;
using Orchard.Core.Navigation.Services;
using Orchard.Core.Navigation.ViewModels;
Expand Down Expand Up @@ -114,5 +115,11 @@ protected override void Exporting(MenuPart part, ContentManagement.Handlers.Expo
context.Element(part.PartDefinition.Name).SetAttributeValue("MenuText", part.MenuText);
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 = context.CloneContentItem;
}
}
}
10 changes: 10 additions & 0 deletions src/Orchard.Web/Core/Navigation/Drivers/MenuWidgetPartDriver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -223,5 +223,15 @@ protected override void Exporting(MenuWidgetPart part, ExportContentContext cont
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;
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,5 +48,9 @@ protected override void Importing(ShapeMenuItemPart part, ImportContentContext c
protected override void Exporting(ShapeMenuItemPart part, ExportContentContext context) {
context.Element(part.PartDefinition.Name).SetAttributeValue("ShapeType", part.ShapeType);
}

protected override void Cloning(ShapeMenuItemPart originalPart, ShapeMenuItemPart clonePart, CloneContentContext context) {
clonePart.ShapeType = originalPart.ShapeType;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,5 +55,10 @@ protected override void Importing(SpamFilterPart part, ImportContentContext cont
protected override void Exporting(SpamFilterPart part, ExportContentContext context) {
context.Element(part.PartDefinition.Name).SetAttributeValue("Status", part.Status.ToString());
}

protected override void Cloning(SpamFilterPart originalPart, SpamFilterPart clonePart, CloneContentContext context) {
clonePart.Status = originalPart.Status;
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -109,5 +109,10 @@ protected override void Exporting(ArchiveLaterPart part, ExportContentContext co
.SetAttributeValue("ScheduledArchiveUtc", XmlConvert.ToString(scheduled.Value, XmlDateTimeSerializationMode.Utc));
}
}

protected override void Cloning(ArchiveLaterPart originalPart, ArchiveLaterPart clonePart, CloneContentContext context) {
clonePart.ScheduledArchiveUtc.Value = originalPart.ScheduledArchiveUtc.Value;
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -177,5 +177,11 @@ protected override void Exporting(AutoroutePart part, ExportContentContext conte
context.Element(part.PartDefinition.Name).SetAttributeValue("UseCulturePattern", part.Record.UseCulturePattern);
context.Element(part.PartDefinition.Name).SetAttributeValue("PromoteToHomePage", part.PromoteToHomePage);
}

protected override void Cloning(AutoroutePart originalPart, AutoroutePart clonePart, CloneContentContext context) {
clonePart.CustomPattern = originalPart.CustomPattern;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it the actual slug? If so it should be altered.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No. That would be the DisplayAlias property.

clonePart.UseCustomPattern = originalPart.UseCustomPattern;
clonePart.UseCulturePattern = originalPart.UseCulturePattern;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public class BlogArchivesPartDriver : ContentPartDriver<BlogArchivesPart> {
private readonly IContentManager _contentManager;

public BlogArchivesPartDriver(
IBlogService blogService,
IBlogService blogService,
IBlogPostService blogPostService,
IContentManager contentManager) {
_blogService = blogService;
Expand All @@ -37,7 +37,7 @@ protected override DriverResult Editor(BlogArchivesPart part, dynamic shapeHelpe
var viewModel = new BlogArchivesViewModel {
BlogId = part.BlogId,
Blogs = _blogService.Get().ToList().OrderBy(b => _contentManager.GetItemMetadata(b).DisplayText)
};
};

return ContentShape("Parts_Blogs_BlogArchives_Edit",
() => shapeHelper.EditorTemplate(TemplateName: "Parts.Blogs.BlogArchives", Model: viewModel, Prefix: Prefix));
Expand Down Expand Up @@ -69,5 +69,8 @@ protected override void Exporting(BlogArchivesPart part, ExportContentContext co
context.Element(part.PartDefinition.Name).SetAttributeValue("Blog", blogIdentity);
}

protected override void Cloning(BlogArchivesPart originalPart, BlogArchivesPart clonePart, CloneContentContext context) {
clonePart.BlogId = originalPart.BlogId;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using Orchard.Blogs.Models;
using Orchard.ContentManagement;
using Orchard.ContentManagement.Drivers;
using Orchard.ContentManagement.Handlers;

namespace Orchard.Blogs.Drivers {
public class BlogPartDriver : ContentPartDriver<BlogPart> {
Expand Down Expand Up @@ -66,5 +67,11 @@ protected override void Exporting(BlogPart part, ContentManagement.Handlers.Expo
context.Element(part.PartDefinition.Name).SetAttributeValue("PostCount", part.PostCount);
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;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -87,5 +87,10 @@ protected override void Exporting(RecentBlogPostsPart part, ExportContentContext
context.Element(part.PartDefinition.Name).SetAttributeValue("Blog", blogIdentity);
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;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using Orchard.Localization;
using Orchard.Comments.Services;
using Orchard.UI.Notify;
using Orchard.ContentManagement.Handlers;

namespace Orchard.Comments.Drivers {
public class CommentPartDriver : ContentPartDriver<CommentPart> {
Expand Down Expand Up @@ -227,5 +228,33 @@ protected override void Exporting(CommentPart part, ContentManagement.Handlers.E
}
}
}

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;
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,20 @@ protected override void Importing(ContentPermissionsPart part, ImportContentCont
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) {
// reset permissions the user can't change
if (!_authorizer.Authorize(Core.Contents.Permissions.ViewContent, part.ContentItem)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,5 +83,9 @@ protected override void Exporting(ContentMenuItemPart part, ExportContentContext
}
}
}

protected override void Cloning(ContentMenuItemPart originalPart, ContentMenuItemPart clonePart, CloneContentContext context) {
clonePart.Content = originalPart.Content;
}
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Orchard.ContentManagement.Drivers;
using Orchard.ContentManagement.Handlers;
using Orchard.MediaLibrary.Models;

namespace Orchard.MediaLibrary.Drivers {
Expand Down Expand Up @@ -26,5 +27,9 @@ protected override void Importing(AudioPart part, ContentManagement.Handlers.Imp
part.Length = int.Parse(length)
);
}

protected override void Cloning(AudioPart originalPart, AudioPart clonePart, CloneContentContext context) {
clonePart.Length = originalPart.Length;
}
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Orchard.ContentManagement.Drivers;
using Orchard.ContentManagement.Handlers;
using Orchard.MediaLibrary.Models;

namespace Orchard.MediaLibrary.Drivers {
Expand Down Expand Up @@ -26,5 +27,9 @@ protected override void Importing(DocumentPart part, ContentManagement.Handlers.
part.Length = int.Parse(length)
);
}

protected override void Cloning(DocumentPart originalPart, DocumentPart clonePart, CloneContentContext context) {
clonePart.Length = originalPart.Length;
}
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using Orchard.ContentManagement;
using Orchard.ContentManagement.Drivers;
using Orchard.ContentManagement.Handlers;
using Orchard.MediaLibrary.Models;

namespace Orchard.MediaLibrary.Drivers {
Expand Down Expand Up @@ -33,5 +34,10 @@ protected override void Importing(ImagePart part, ContentManagement.Handlers.Imp
part.Width = int.Parse(width)
);
}

protected override void Cloning(ImagePart originalPart, ImagePart clonePart, CloneContentContext context) {
clonePart.Height = originalPart.Height;
clonePart.Width = originalPart.Width;
}
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using Orchard.ContentManagement;
using Orchard.ContentManagement.Drivers;
using Orchard.ContentManagement.Handlers;
using Orchard.Localization;
using Orchard.MediaLibrary.Models;

Expand Down Expand Up @@ -74,5 +75,14 @@ protected override void Exporting(MediaPart part, ContentManagement.Handlers.Exp
context.Element(part.PartDefinition.Name).SetAttributeValue("FileName", part.FileName);
context.Element(part.PartDefinition.Name).SetAttributeValue("LogicalType", part.LogicalType);
}

protected override void Cloning(MediaPart originalPart, MediaPart clonePart, CloneContentContext context) {
clonePart.MimeType = originalPart.MimeType;
clonePart.Caption = originalPart.Caption;
clonePart.AlternateText = originalPart.AlternateText;
clonePart.FolderPath = originalPart.FolderPath;
clonePart.FileName = originalPart.FileName;
clonePart.LogicalType = originalPart.LogicalType;
}
}
}
Loading