Content app for dictionary items

This commit is contained in:
Patrick de Mooij
2021-10-07 20:40:47 +02:00
committed by Nathan Woulfe
parent e04efe6067
commit 1d2272f536
9 changed files with 230 additions and 178 deletions

View File

@@ -0,0 +1,32 @@
using System.Collections.Generic;
using Umbraco.Cms.Core.Models;
using Umbraco.Cms.Core.Models.ContentEditing;
using Umbraco.Cms.Core.Models.Membership;
namespace Umbraco.Cms.Core.ContentApps
{
internal class DictionaryContentAppFactory : IContentAppFactory
{
private const int Weight = -100;
private ContentApp _dictionaryApp;
public ContentApp GetContentAppFor(object source, IEnumerable<IReadOnlyUserGroup> userGroups)
{
switch (source)
{
case IDictionaryItem _:
return _dictionaryApp ??= new ContentApp
{
Alias = "dictionaryContent",
Name = "Content",
Icon = "icon-document",
View = "views/dictionary/views/content/content.html",
Weight = Weight
};
default:
return null;
}
}
}
}

View File

@@ -44,7 +44,8 @@ namespace Umbraco.Cms.Core.DependencyInjection
.Append<ContentTypeDesignContentAppFactory>()
.Append<ContentTypeListViewContentAppFactory>()
.Append<ContentTypePermissionsContentAppFactory>()
.Append<ContentTypeTemplatesContentAppFactory>();
.Append<ContentTypeTemplatesContentAppFactory>()
.Append<DictionaryContentAppFactory>();
// all built-in finders in the correct order,
// devs can then modify this list on application startup

View File

@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
@@ -70,6 +70,10 @@ namespace Umbraco.Cms.Core.Manifest
partA = "contentType";
partB = contentType.Alias;
break;
case IDictionaryItem _:
partA = "dictionary";
partB = "*"; //Not really a different type for dictionary items
break;
default:
return null;

View File

@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.Runtime.Serialization;
@@ -17,6 +17,7 @@ namespace Umbraco.Cms.Core.Models.ContentEditing
{
Notifications = new List<BackOfficeNotification>();
Translations = new List<DictionaryTranslationDisplay>();
ContentApps = new List<ContentApp>();
}
/// <inheritdoc />
@@ -37,5 +38,11 @@ namespace Umbraco.Cms.Core.Models.ContentEditing
/// </summary>
[DataMember(Name = "translations")]
public List<DictionaryTranslationDisplay> Translations { get; private set; }
/// <summary>
/// Apps for the dictionary item
/// </summary>
[DataMember(Name = "apps")]
public List<ContentApp> ContentApps { get; private set; }
}
}

View File

@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.Linq;
using Umbraco.Cms.Core.ContentApps;
@@ -47,7 +47,7 @@ namespace Umbraco.Cms.Core.Models.Mapping
return contentTypeBasic;
}
public IEnumerable<ContentApp> GetContentApps(IUmbracoEntity source)
public IEnumerable<ContentApp> GetContentApps(IEntity source)
{
var apps = _contentAppDefinitions.GetContentAppsFor(source).ToArray();

View File

@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.Linq;
using Umbraco.Cms.Core.Mapping;
@@ -14,10 +14,12 @@ namespace Umbraco.Cms.Core.Models.Mapping
public class DictionaryMapDefinition : IMapDefinition
{
private readonly ILocalizationService _localizationService;
private readonly CommonMapper _commonMapper;
public DictionaryMapDefinition(ILocalizationService localizationService)
public DictionaryMapDefinition(ILocalizationService localizationService, CommonMapper commonMapper)
{
_localizationService = localizationService;
_commonMapper = commonMapper;
}
public void DefineMaps(IUmbracoMapper mapper)
@@ -44,6 +46,7 @@ namespace Umbraco.Cms.Core.Models.Mapping
target.Name = source.ItemKey;
target.ParentId = source.ParentId ?? Guid.Empty;
target.Udi = Udi.Create(Constants.UdiEntityType.DictionaryItem, source.Key);
target.ContentApps.AddRange(_commonMapper.GetContentApps(source));
// build up the path to make it possible to set active item in tree
// TODO: check if there is a better way