-
Notifications
You must be signed in to change notification settings - Fork 2.4k
/
ContentsDriver.cs
80 lines (67 loc) · 3.31 KB
/
ContentsDriver.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
using System;
using System.Collections.Generic;
using OrchardCore.ContentManagement;
using OrchardCore.ContentManagement.Display.ContentDisplay;
using OrchardCore.ContentManagement.Display.ViewModels;
using OrchardCore.ContentManagement.Metadata;
using OrchardCore.ContentManagement.Metadata.Settings;
using OrchardCore.DisplayManagement.ModelBinding;
using OrchardCore.DisplayManagement.Views;
namespace OrchardCore.Contents.Drivers
{
public class ContentsDriver : ContentDisplayDriver
{
private readonly IContentDefinitionManager _contentDefinitionManager;
public ContentsDriver(IContentDefinitionManager contentDefinitionManager)
{
_contentDefinitionManager = contentDefinitionManager;
}
public override IDisplayResult Display(ContentItem model, IUpdateModel updater)
{
// We add custom alternates. This could be done generically to all shapes coming from ContentDisplayDriver but right now it's
// only necessary on this shape. Otherwise c.f. ContentPartDisplayDriver
var contentsMetadataShape = Shape("ContentsMetadata", new ContentItemViewModel(model)).Location("Detail", "Content:before");
var contentTypeDefinition = _contentDefinitionManager.GetTypeDefinition(model.ContentType);
if (contentTypeDefinition != null)
{
contentsMetadataShape.Displaying(ctx =>
{
var stereotype = "";
var settings = contentTypeDefinition?.GetSettings<ContentTypeSettings>();
if (settings != null)
{
stereotype = settings.Stereotype;
}
if (!String.IsNullOrEmpty(stereotype) && !String.Equals("Content", stereotype, StringComparison.OrdinalIgnoreCase))
{
ctx.Shape.Metadata.Alternates.Add($"{stereotype}__ContentsMetadata");
}
});
}
return Combine(
contentsMetadataShape,
Shape("Contents_SummaryAdmin__Tags", new ContentItemViewModel(model)).Location("SummaryAdmin", "Tags:10"),
Shape("Contents_SummaryAdmin__Meta", new ContentItemViewModel(model)).Location("SummaryAdmin", "Meta:20"),
Shape("Contents_SummaryAdmin__Button__Edit", new ContentItemViewModel(model)).Location("SummaryAdmin", "Actions:10"),
Shape("Contents_SummaryAdmin__Button__Actions", new ContentItemViewModel(model)).Location("SummaryAdmin", "ActionsMenu:10")
);
}
public override IDisplayResult Edit(ContentItem contentItem, IUpdateModel updater)
{
var contentTypeDefinition = _contentDefinitionManager.GetTypeDefinition(contentItem.ContentType);
if (contentTypeDefinition == null)
{
return null;
}
var results = new List<IDisplayResult>
{
Dynamic("Content_PublishButton").Location("Actions:10"),
};
if (contentTypeDefinition.GetSettings<ContentTypeSettings>().Draftable)
{
results.Add(Dynamic("Content_SaveDraftButton").Location("Actions:20"));
}
return Combine(results.ToArray());
}
}
}