mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-04-05 21:01:35 +08:00
Fixing that when content fields were updated it wasn't checked whether previously they were displayed or not (as it happens for parts), fixes #6287
This commit is contained in:
parent
8daad7f7a9
commit
110e5c1154
src/Orchard
@ -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);
|
||||
}
|
||||
|
||||
|
@ -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) {
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
@ -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 };
|
||||
}
|
||||
}
|
||||
}
|
@ -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" />
|
||||
|
Loading…
Reference in New Issue
Block a user