-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathShapes.cs
66 lines (55 loc) · 2.63 KB
/
Shapes.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
using Orchard.Autoroute.Models;
using Orchard.ContentManagement;
using Orchard.DisplayManagement.Descriptors;
using Orchard.DisplayManagement.Implementation;
using Orchard.Disqus.Models;
namespace Orchard.Disqus
{
public class DisqusShapes : IShapeTableProvider
{
private readonly IOrchardServices _orchardServices;
public DisqusShapes(IOrchardServices services)
{
_orchardServices = services;
}
public void Discover(ShapeTableBuilder builder)
{
// After orchard v1.7 Parts_Comments doesnt seem to be used in the CommentsPartDriver in the comments Module.
// As a result Disqus module is not replacing OOTB comments.
// Globally hide the OOTB ListOfComments Part. Hiding it here means themes can remain clean
builder.Describe("Parts_ListOfComments")
.Placement(shapeDisplayingContext =>
new PlacementInfo { Location = "-" });
// Replaces OOTB Parts_CommentForm with the Disqux Wrapper.
builder.Describe("Parts_CommentForm")
.OnDisplaying(shapeDisplayingContext =>
AddShapeWrapper(shapeDisplayingContext, "Parts_Comments_Wrapper"));
builder.Describe("Parts_Comments_Count")
.OnDisplaying(shapeDisplayingContext =>
AddShapeWrapper(shapeDisplayingContext, "Parts_Comments_Count_Wrapper"));
builder.Describe("Parts_Blogs_BlogPost_List")
.OnDisplaying(shapeDisplayingContext =>
AddShapeWrapper(shapeDisplayingContext, "Parts_BlogPost_List_Wrapper", includeUniqueIndentifier: false));
}
private void AddShapeWrapper(ShapeDisplayingContext shapeDisplayingContext, string wrapperName, bool includeUniqueIndentifier = true)
{
var settings = _orchardServices.WorkContext.CurrentSite.As<DisqusSettingsPart>();
shapeDisplayingContext.Shape.DisqusSettings = settings;
shapeDisplayingContext.ShapeMetadata.Wrappers.Add(wrapperName);
if (includeUniqueIndentifier)
{
shapeDisplayingContext.Shape.DisqusUniqueId = GetUniqueIdentifier(shapeDisplayingContext.Shape.ContentPart.ContentItem);
}
}
private static string GetUniqueIdentifier(ContentItem item)
{
string slug = null;
if (item.Has<AutoroutePart>())
{
var route = item.Get<AutoroutePart>();
slug = route.Path;
}
return string.Format("{0} {1}", item.Id, slug);
}
}
}