Skip to content

Commit 40f2156

Browse files
author
Claus
committed
Merge branch 'ronaldbarendse-dev' into dev
2 parents 037aa0f + 1d5ad08 commit 40f2156

File tree

6 files changed

+141
-3
lines changed

6 files changed

+141
-3
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,7 @@ bower_components/
2525
node_modules/
2626
Umbraco.Deploy.UI.Client/build/
2727
build/Tools/nuget.exe
28+
29+
src/Umbraco.Deploy.Contrib.Connectors/App_Plugins/*
30+
src/Umbraco.Deploy.Contrib.Connectors/Config/*
31+
src/Umbraco.Deploy.Contrib.Connectors/app.config

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ This project offers Umbraco Deploy connectors for the following community packag
1616
- [Content List](https://our.umbraco.com/projects/backoffice-extensions/content-list/)
1717
- [DocType Grid Editor](https://our.umbraco.org/projects/backoffice-extensions/doc-type-grid-editor/)
1818
- [LeBlender](https://our.umbraco.org/projects/backoffice-extensions/leblender/)
19+
- [Meganav](https://our.umbraco.com/projects/website-utilities/meganav/)
1920
- [Multi Url Picker](https://our.umbraco.com/projects/backoffice-extensions/multi-url-picker/)
2021
- [Nested Content](https://our.umbraco.org/projects/backoffice-extensions/nested-content/)
2122
- [nuPickers](https://our.umbraco.org/projects/backoffice-extensions/nupickers/)

src/Umbraco.Deploy.Contrib.Connectors/Umbraco.Deploy.Contrib.Connectors.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@
7171
<Compile Include="Properties\AssemblyInfo.cs" />
7272
<Compile Include="Properties\VersionInfo.cs" />
7373
<Compile Include="ValueConnectors\ArchetypeValueConnector.cs" />
74+
<Compile Include="ValueConnectors\MeganavValueConnector.cs" />
7475
<Compile Include="ValueConnectors\MultiUrlPickerValueConnector.cs" />
7576
<Compile Include="ValueConnectors\NuPickersValueConnector.cs" />
7677
<Compile Include="ValueConnectors\PropertyListValueConnector.cs" />

src/Umbraco.Deploy.Contrib.Connectors/ValueConnectors/ArchetypeValueConnector.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -413,7 +413,8 @@ internal class ArchetypeFieldsetModel
413413
[JsonProperty("disabled")]
414414
public bool Disabled { get; set; }
415415

416-
[JsonProperty("properties")] public IEnumerable<ArchetypePropertyModel> Properties;
416+
[JsonProperty("properties")]
417+
public IEnumerable<ArchetypePropertyModel> Properties { get; set; }
417418

418419
[JsonProperty("id")]
419420
public Guid Id { get; set; }
@@ -457,7 +458,7 @@ internal class UmbracoEditorState
457458
{
458459
// container for the names of any files selected for a property in the Umbraco backend
459460
[JsonProperty("fileNames")]
460-
public IEnumerable<string> FileNames;
461+
public IEnumerable<string> FileNames { get; set; }
461462
}
462463
}
463464
}
Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using Newtonsoft.Json;
4+
using Newtonsoft.Json.Linq;
5+
using Umbraco.Core;
6+
using Umbraco.Core.Deploy;
7+
using Umbraco.Core.Models;
8+
using Umbraco.Core.Services;
9+
10+
namespace Umbraco.Deploy.Contrib.Connectors.ValueConnectors
11+
{
12+
/// <summary>
13+
/// Represents a value connector for the Cogworks.Meganav property editor.
14+
/// </summary>
15+
/// <seealso cref="Umbraco.Core.Deploy.IValueConnector" />
16+
public class MeganavValueConnector : IValueConnector
17+
{
18+
/// <summary>
19+
/// The entity service.
20+
/// </summary>
21+
private readonly IEntityService _entityService;
22+
23+
/// <summary>
24+
/// Gets the property editor aliases that the value converter supports by default.
25+
/// </summary>
26+
public IEnumerable<string> PropertyEditorAliases => new[] { "Cogworks.Meganav" };
27+
28+
/// <summary>
29+
/// Initializes a new instance of the <see cref="MeganavValueConnector"/> class.
30+
/// </summary>
31+
/// <param name="entityService">The entity service.</param>
32+
/// <exception cref="ArgumentNullException">entityService</exception>
33+
public MeganavValueConnector(IEntityService entityService)
34+
{
35+
_entityService = entityService ?? throw new ArgumentNullException("entityService");
36+
}
37+
38+
/// <summary>
39+
/// Gets the deploy property corresponding to a content property.
40+
/// </summary>
41+
/// <param name="property">The content property.</param>
42+
/// <param name="dependencies">The content dependencies.</param>
43+
/// <returns>
44+
/// The deploy property value.
45+
/// </returns>
46+
public string GetValue(Property property, ICollection<ArtifactDependency> dependencies)
47+
{
48+
var value = property.Value as string;
49+
if (String.IsNullOrWhiteSpace(value) || !StringExtensions.DetectIsJson(value))
50+
{
51+
return null;
52+
}
53+
54+
// Parse links and convert ID to UDI
55+
var rootLinks = ParseLinks(JArray.Parse(value), dependencies, Direction.ToArtifact);
56+
57+
return rootLinks.ToString(Formatting.None);
58+
}
59+
60+
/// <summary>
61+
/// Sets a content property value using a deploy property.
62+
/// </summary>
63+
/// <param name="content">The content item.</param>
64+
/// <param name="alias">The property alias.</param>
65+
/// <param name="value">The deploy property value.</param>
66+
public void SetValue(IContentBase content, string alias, string value)
67+
{
68+
if (String.IsNullOrWhiteSpace(value))
69+
{
70+
// Save empty value
71+
content.SetValue(alias, value);
72+
return;
73+
}
74+
75+
if (!StringExtensions.DetectIsJson(value))
76+
{
77+
// Skip invalid values
78+
return;
79+
}
80+
81+
// Parse links and convert UDI back to local ID
82+
var rootLinks = ParseLinks(JArray.Parse(value), null, Direction.FromArtifact);
83+
84+
content.SetValue(alias, rootLinks.ToString(Formatting.None));
85+
}
86+
87+
private JArray ParseLinks(JArray links, ICollection<ArtifactDependency> dependencies, Direction direction)
88+
{
89+
foreach (var link in links)
90+
{
91+
if (direction == Direction.ToArtifact)
92+
{
93+
GuidUdi guidUdi = null;
94+
var id = link.Value<int>("id");
95+
if (id != 0)
96+
{
97+
var keyForId = _entityService.GetKeyForId(id, UmbracoObjectTypes.Document);
98+
if (keyForId.Success)
99+
{
100+
guidUdi = new GuidUdi(Constants.UdiEntityType.Document, keyForId.Result);
101+
dependencies.Add(new ArtifactDependency(guidUdi, false, ArtifactDependencyMode.Exist));
102+
}
103+
}
104+
link["id"] = guidUdi?.ToString();
105+
}
106+
else
107+
{
108+
var id = 0;
109+
if (GuidUdi.TryParse(link.Value<string>("id"), out GuidUdi guidUdi))
110+
{
111+
var idForUdi = _entityService.GetIdForUdi(guidUdi);
112+
if (idForUdi.Success)
113+
{
114+
id = idForUdi.Result;
115+
}
116+
}
117+
link["id"] = id;
118+
}
119+
120+
// Parse children
121+
var children = link.Value<JArray>("children");
122+
if (children != null)
123+
{
124+
link["children"] = ParseLinks(children, dependencies, direction);
125+
}
126+
}
127+
128+
return links;
129+
}
130+
}
131+
}

src/Umbraco.Deploy.Contrib.Connectors/ValueConnectors/RelatedLinks2ValueConnector.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public string GetValue(Property property, ICollection<ArtifactDependency> depend
5656
{
5757
relatedLinks = JsonConvert.DeserializeObject<List<RelatedLinkUdiModel>>(value);
5858
}
59-
catch (JsonSerializationException ex)
59+
catch (JsonSerializationException)
6060
{
6161
// We might be transferring related links stored as int id, parse with ints instead.
6262

0 commit comments

Comments
 (0)