Fixed an issue with copy/paste.

This commit is contained in:
Sipke Schoorstra
2015-11-12 20:25:35 +01:00
parent 391459d273
commit 978408765b
3 changed files with 23 additions and 3 deletions

View File

@@ -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; }
}
}

View File

@@ -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)

View File

@@ -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);
}