mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-10-14 19:04:51 +08:00
Fixed an issue with copy/paste.
This commit is contained in:
@@ -1,13 +1,20 @@
|
||||
using Orchard.ContentManagement;
|
||||
using System.Collections.Generic;
|
||||
using Orchard.ContentManagement;
|
||||
|
||||
namespace Orchard.Layouts.Framework.Elements {
|
||||
public class ElementRemovingContext {
|
||||
public ElementRemovingContext(Element element, IContent content) {
|
||||
public ElementRemovingContext(Element element, IEnumerable<Element> elements, IEnumerable<Element> removedElements, IContent content) {
|
||||
Element = element;
|
||||
Elements = elements;
|
||||
RemovedElements = removedElements;
|
||||
Content = content;
|
||||
}
|
||||
|
||||
public IContent Content { get; private set; }
|
||||
// All the other elements on the canvas.
|
||||
public IEnumerable<Element> Elements { get; set; }
|
||||
// All the other removed elements from the canvas (including the current element).
|
||||
public IEnumerable<Element> RemovedElements { get; set; }
|
||||
public Element Element { get; private set; }
|
||||
}
|
||||
}
|
@@ -129,6 +129,19 @@ namespace Orchard.Layouts.Providers {
|
||||
private void RemoveContentItem(ElementRemovingContext context) {
|
||||
var element = (PlaceableContentItem) context.Element;
|
||||
var contentItemId = element.ContentItemId;
|
||||
|
||||
// Only remove the content item if no other elements are referencing this one.
|
||||
// This can happen if the user cut an element and then pasted it back.
|
||||
// That will delete the initial element and create a copy.
|
||||
var placeableElements =
|
||||
from e in context.Elements.Flatten()
|
||||
let p = e as PlaceableContentItem
|
||||
where p != null && p.ContentItemId == contentItemId
|
||||
select p;
|
||||
|
||||
if (placeableElements.Any())
|
||||
return;
|
||||
|
||||
var contentItem = contentItemId != null ? _contentManager.Value.Get(contentItemId.Value, VersionOptions.Latest) : default(ContentItem);
|
||||
|
||||
if(contentItem != null)
|
||||
|
@@ -153,7 +153,7 @@ namespace Orchard.Layouts.Services {
|
||||
var elements = context.RemovedElements.Flatten().ToList();
|
||||
|
||||
foreach (var element in elements) {
|
||||
var removingContext = new ElementRemovingContext(element, context.Content);
|
||||
var removingContext = new ElementRemovingContext(element, context.Elements, context.RemovedElements, context.Content);
|
||||
_elementEventHandler.Removing(removingContext);
|
||||
element.Descriptor.Removing(removingContext);
|
||||
}
|
||||
|
Reference in New Issue
Block a user