Fixing that when content fields were updated it wasn't checked whether previously they were displayed or not (as it happens for parts), fixes

This commit is contained in:
Lombiq 2016-01-28 00:13:30 +01:00
parent 8daad7f7a9
commit 110e5c1154
5 changed files with 70 additions and 43 deletions

View File

@ -44,14 +44,23 @@ namespace Orchard.ContentManagement.Drivers {
DriverResult IContentFieldDriver.UpdateEditorShape(UpdateEditorContext context) {
return Process(context.ContentItem, (part, field) => {
DriverResult result = Editor(part, field, context.Updater, context.New);
// Checking if the editor needs to be updated (e.g. if any of the shapes were not hidden).
DriverResult editor = Editor(part, field, context.New);
IEnumerable<ContentShapeResult> contentShapeResults = editor.GetShapeResults();
if (result != null) {
result.ContentPart = part;
result.ContentField = field;
if (contentShapeResults.Any(contentShapeResult =>
contentShapeResult == null || contentShapeResult.WasDisplayed(context))) {
DriverResult result = Editor(part, field, context.Updater, context.New);
if (result != null) {
result.ContentPart = part;
result.ContentField = field;
}
return result;
}
return result;
return editor;
}, context.Logger);
}

View File

@ -6,7 +6,6 @@ using Orchard.ContentManagement.FieldStorage.InfosetStorage;
using Orchard.ContentManagement.Handlers;
using Orchard.ContentManagement.MetaData;
using Orchard.DisplayManagement;
using Orchard.DisplayManagement.Descriptors;
using Orchard.DisplayManagement.Shapes;
using System.Linq;
@ -59,44 +58,12 @@ namespace Orchard.ContentManagement.Drivers {
return null;
}
// checking if the editor needs to be updated (e.g. if any of the shapes were not hidden)
// Checking if the editor needs to be updated (e.g. if any of the shapes were not hidden).
DriverResult editor = Editor(part, context.New);
IEnumerable<ContentShapeResult> contentShapeResults = GetShapeResults(editor);
IEnumerable<ContentShapeResult> contentShapeResults = editor.GetShapeResults();
if (contentShapeResults.Any(contentShapeResult => {
if (contentShapeResult == null) return true;
ShapeDescriptor descriptor;
if (context.ShapeTable.Descriptors.TryGetValue(contentShapeResult.GetShapeType(), out descriptor)) {
var placementContext = new ShapePlacementContext {
Content = part.ContentItem,
ContentType = part.ContentItem.ContentType,
Differentiator = contentShapeResult.GetDifferentiator(),
DisplayType = null,
Path = context.Path
};
var placementInfo = descriptor.Placement(placementContext);
var location = placementInfo.Location;
if (String.IsNullOrEmpty(location) || location == "-") {
return false;
}
var editorGroup = contentShapeResult.GetGroup();
if (string.IsNullOrEmpty(editorGroup)) {
editorGroup = placementInfo.GetGroup() ?? "";
}
var contextGroup = context.GroupId ?? "";
if (!String.Equals(editorGroup, contextGroup, StringComparison.OrdinalIgnoreCase)) {
return false;
}
}
return true;
})) {
if (contentShapeResults.Any(contentShapeResult =>
contentShapeResult == null || contentShapeResult.WasDisplayed(context))) {
DriverResult result = Editor(part, context.Updater, context.New);
if (result != null) {

View File

@ -2,6 +2,7 @@
using System.Collections.Generic;
using Orchard.ContentManagement.Handlers;
using Orchard.DisplayManagement.Shapes;
using Orchard.DisplayManagement.Descriptors;
namespace Orchard.ContentManagement.Drivers {
public class ContentShapeResult : DriverResult {
@ -127,5 +128,39 @@ namespace Orchard.ContentManagement.Drivers {
public string GetShapeType() {
return _shapeType;
}
public bool WasDisplayed(UpdateEditorContext context) {
ShapeDescriptor descriptor;
if (context.ShapeTable.Descriptors.TryGetValue(_shapeType, out descriptor)) {
var placementContext = new ShapePlacementContext {
Content = context.ContentItem,
ContentType = context.ContentItem.ContentType,
Differentiator = _differentiator,
DisplayType = null,
Path = context.Path
};
var placementInfo = descriptor.Placement(placementContext);
var location = placementInfo.Location;
if (String.IsNullOrEmpty(location) || location == "-") {
return false;
}
var editorGroup = _groupId;
if (String.IsNullOrEmpty(editorGroup)) {
editorGroup = placementInfo.GetGroup() ?? "";
}
var contextGroup = context.GroupId ?? "";
if (!String.Equals(editorGroup, contextGroup, StringComparison.OrdinalIgnoreCase)) {
return false;
}
}
return true;
}
}
}

View File

@ -0,0 +1,15 @@
using System.Collections.Generic;
using System.Linq;
namespace Orchard.ContentManagement.Drivers
{
internal static class DriverResultExtensions {
public static IEnumerable<ContentShapeResult> GetShapeResults(this DriverResult driverResult) {
if (driverResult is CombinedResult) {
return ((CombinedResult)driverResult).GetResults().Select(result => result as ContentShapeResult);
}
return new[] { driverResult as ContentShapeResult };
}
}
}

View File

@ -169,6 +169,7 @@
</ItemGroup>
<ItemGroup>
<Compile Include="BackgroundHttpContextFactory.cs" />
<Compile Include="ContentManagement\Extensions\DriverResultExtensions.cs" />
<Compile Include="ContentManagement\Handlers\CloneContentContext.cs" />
<Compile Include="Environment\Configuration\ExtensionLocations.cs" />
<Compile Include="DisplayManagement\IPositioned.cs" />