-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Tracking Meganav item references as relations
- Loading branch information
1 parent
cad98b1
commit 50152c2
Showing
4 changed files
with
48 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
src/Our.Umbraco.Meganav/ValueReferences/MeganavValueReferenceFactory.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
using System.Collections.Generic; | ||
using Newtonsoft.Json; | ||
using Our.Umbraco.Meganav.Models; | ||
using Umbraco.Core.Models.Editors; | ||
using Umbraco.Core.PropertyEditors; | ||
|
||
namespace Our.Umbraco.Meganav.ValueReferences | ||
{ | ||
internal class MeganavValueReferenceFactory : IDataValueReferenceFactory, IDataValueReference | ||
{ | ||
public bool IsForEditor(IDataEditor dataEditor) => dataEditor.Alias.Equals(Constants.PropertyEditorAlias); | ||
|
||
public IDataValueReference GetDataValueReference() => this; | ||
|
||
public IEnumerable<UmbracoEntityReference> GetReferences(object value) | ||
{ | ||
var entities = JsonConvert.DeserializeObject<IEnumerable<MeganavEntity>>(value?.ToString()); | ||
|
||
return GetReferences(entities); | ||
} | ||
|
||
private IEnumerable<UmbracoEntityReference> GetReferences(IEnumerable<MeganavEntity> entities) | ||
{ | ||
foreach (var entity in entities) | ||
{ | ||
if (entity.Children != null) | ||
{ | ||
var references = GetReferences(entity.Children); | ||
|
||
foreach (var reference in references) | ||
{ | ||
yield return reference; | ||
} | ||
} | ||
|
||
if (entity.Udi != null) | ||
{ | ||
yield return new UmbracoEntityReference(entity.Udi); | ||
} | ||
} | ||
} | ||
} | ||
} |