Skip to content
This repository was archived by the owner on Feb 10, 2024. It is now read-only.

Commit e7574f8

Browse files
committed
Adds Key to grid-cell's IPublishedContent model
Since we've increased the Umbraco dependency to v7.6.0, we can now use `PublishedContentWithKeyBase`. This isn't considered a breaking-change, since our `DetachedPublishedContent` has been marked as internal. Fixes #131
1 parent 626e553 commit e7574f8

File tree

2 files changed

+35
-99
lines changed

2 files changed

+35
-99
lines changed

src/Our.Umbraco.DocTypeGridEditor/Helpers/DocTypeGridEditorHelper.cs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -103,18 +103,17 @@ private static IPublishedContent ConvertValue(string id, string contentTypeAlias
103103
}
104104
}
105105

106-
// Parse out the name manually
107-
if (propValues.TryGetValue("name", out object nameObj))
108-
{
109-
// Do nothing, we just want to parse out the name if we can
110-
}
106+
// Manually parse out the special properties
107+
propValues.TryGetValue("name", out object nameObj);
108+
Guid.TryParse(id, out Guid key);
111109

112110
// Get the current request node we are embedded in
113111
var pcr = UmbracoContext.Current?.PublishedContentRequest;
114112
var containerNode = pcr != null && pcr.HasPublishedContent ? pcr.PublishedContent : null;
115113

116114
// Create the model based on our implementation of IPublishedContent
117115
IPublishedContent content = new DetachedPublishedContent(
116+
key,
118117
nameObj?.ToString(),
119118
contentTypes.PublishedContentType,
120119
properties.ToArray(),

src/Our.Umbraco.DocTypeGridEditor/Models/DetachedPublishedContent.cs

Lines changed: 31 additions & 94 deletions
Original file line numberDiff line numberDiff line change
@@ -8,71 +8,50 @@
88

99
namespace Our.Umbraco.DocTypeGridEditor.Models
1010
{
11-
internal class DetachedPublishedContent : PublishedContentBase
11+
internal class DetachedPublishedContent : PublishedContentWithKeyBase
1212
{
13+
private readonly Guid _key;
1314
private readonly string _name;
1415
private readonly PublishedContentType _contentType;
1516
private readonly IEnumerable<IPublishedProperty> _properties;
1617
private readonly bool _isPreviewing;
1718
private readonly IPublishedContent _containerNode;
1819

19-
public DetachedPublishedContent(string name,
20+
public DetachedPublishedContent(
21+
Guid key,
22+
string name,
2023
PublishedContentType contentType,
2124
IEnumerable<IPublishedProperty> properties,
2225
IPublishedContent containerNode = null,
2326
bool isPreviewing = false)
2427
{
28+
_key = key;
2529
_name = name;
2630
_contentType = contentType;
2731
_properties = properties;
2832
_containerNode = containerNode;
2933
_isPreviewing = isPreviewing;
3034
}
3135

32-
public override int Id
33-
{
34-
get { return 0; }
35-
}
36+
public override Guid Key => _key;
3637

37-
public override string Name
38-
{
39-
get { return _name; }
40-
}
38+
public override int Id => 0;
4139

42-
public override bool IsDraft
43-
{
44-
get { return _isPreviewing; }
45-
}
40+
public override string Name => _name;
4641

47-
public override PublishedItemType ItemType
48-
{
49-
get { return PublishedItemType.Content; }
50-
}
42+
public override bool IsDraft => _isPreviewing;
5143

52-
public override PublishedContentType ContentType
53-
{
54-
get { return _contentType; }
55-
}
44+
public override PublishedItemType ItemType => PublishedItemType.Content;
5645

57-
public override string DocumentTypeAlias
58-
{
59-
get { return _contentType.Alias; }
60-
}
46+
public override PublishedContentType ContentType => _contentType;
6147

62-
public override int DocumentTypeId
63-
{
64-
get { return _contentType.Id; }
65-
}
48+
public override string DocumentTypeAlias => _contentType.Alias;
6649

67-
public override ICollection<IPublishedProperty> Properties
68-
{
69-
get { return _properties.ToArray(); }
70-
}
50+
public override int DocumentTypeId => _contentType.Id;
7151

72-
public override IPublishedProperty GetProperty(string alias)
73-
{
74-
return _properties.FirstOrDefault(x => x.PropertyTypeAlias.InvariantEquals(alias));
75-
}
52+
public override ICollection<IPublishedProperty> Properties => _properties.ToArray();
53+
54+
public override IPublishedProperty GetProperty(string alias) => _properties.FirstOrDefault(x => x.PropertyTypeAlias.InvariantEquals(alias));
7655

7756
public override IPublishedProperty GetProperty(string alias, bool recurse)
7857
{
@@ -82,74 +61,32 @@ public override IPublishedProperty GetProperty(string alias, bool recurse)
8261
return GetProperty(alias);
8362
}
8463

85-
public override IPublishedContent Parent
86-
{
87-
get { return null; }
88-
}
64+
public override IPublishedContent Parent => null;
8965

90-
public override IEnumerable<IPublishedContent> Children
91-
{
92-
get { return Enumerable.Empty<IPublishedContent>(); }
93-
}
66+
public override IEnumerable<IPublishedContent> Children => Enumerable.Empty<IPublishedContent>();
9467

95-
public override int TemplateId
96-
{
97-
get { return 0; }
98-
}
68+
public override int TemplateId => 0;
9969

100-
public override int SortOrder
101-
{
102-
get { return 0; }
103-
}
70+
public override int SortOrder => 0;
10471

105-
public override string UrlName
106-
{
107-
get { return null; }
108-
}
72+
public override string UrlName => null;
10973

110-
public override string WriterName
111-
{
112-
get { return _containerNode != null ? _containerNode.WriterName : null; }
113-
}
74+
public override string WriterName => _containerNode?.WriterName;
11475

115-
public override string CreatorName
116-
{
117-
get { return _containerNode != null ? _containerNode.CreatorName : null; }
118-
}
76+
public override string CreatorName => _containerNode?.CreatorName;
11977

120-
public override int WriterId
121-
{
122-
get { return _containerNode != null ? _containerNode.WriterId : 0; }
123-
}
78+
public override int WriterId => _containerNode?.WriterId ?? 0;
12479

125-
public override int CreatorId
126-
{
127-
get { return _containerNode != null ? _containerNode.CreatorId : 0; }
128-
}
80+
public override int CreatorId => _containerNode?.CreatorId ?? 0;
12981

130-
public override string Path
131-
{
132-
get { return null; }
133-
}
82+
public override string Path => null;
13483

135-
public override DateTime CreateDate
136-
{
137-
get { return _containerNode != null ? _containerNode.CreateDate : DateTime.MinValue; }
138-
}
84+
public override DateTime CreateDate => _containerNode?.CreateDate ?? DateTime.MinValue;
13985

140-
public override DateTime UpdateDate
141-
{
142-
get { return _containerNode != null ? _containerNode.UpdateDate : DateTime.MinValue; }
143-
}
86+
public override DateTime UpdateDate => _containerNode?.UpdateDate ?? DateTime.MinValue;
14487

145-
public override Guid Version
146-
{
147-
get { return _containerNode != null ? _containerNode.Version : Guid.Empty; }
148-
}
88+
public override Guid Version => _containerNode?.Version ?? Guid.Empty;
14989

150-
public override int Level
151-
{
152-
get { return 0; }
153-
}
90+
public override int Level => 0;
15491
}
15592
}

0 commit comments

Comments
 (0)