Files
Umbraco-CMS/src/Umbraco.Web/Models/Mapping/ContentChildOfListViewResolver.cs
2018-03-27 10:04:07 +02:00

26 lines
1.0 KiB
C#

using AutoMapper;
using Umbraco.Core.Models;
using Umbraco.Core.Services;
using Umbraco.Web.Models.ContentEditing;
namespace Umbraco.Web.Models.Mapping
{
internal class ContentChildOfListViewResolver : IValueResolver<IContent, ContentItemDisplay, bool>
{
private readonly IContentService _contentService;
private readonly IContentTypeService _contentTypeService;
public ContentChildOfListViewResolver(IContentService contentService, IContentTypeService contentTypeService)
{
_contentService = contentService;
_contentTypeService = contentTypeService;
}
public bool Resolve(IContent source, ContentItemDisplay destination, bool destMember, ResolutionContext context)
{
// map the IsChildOfListView (this is actually if it is a descendant of a list view!)
var parent = _contentService.GetParent(source);
return parent != null && (parent.ContentType.IsContainer || _contentTypeService.HasContainerInPath(parent.Path));
}
}
}