Ejemplo n.º 1
0
    // Umbraco.Code.MapAll -AllowPreview -Errors -PersistedContent
    private void Map <TVariant>(IContent source, ContentItemDisplay <TVariant> target, MapperContext context)
        where TVariant : ContentVariantDisplay
    {
        // Both GetActions and DetermineIsChildOfListView use parent, so get it once here
        // Parent might already be in context, so check there before using content service
        IContent?parent;

        if (context.Items.TryGetValue("Parent", out var parentObj) &&
            parentObj is IContent typedParent)
        {
            parent = typedParent;
        }
        else
        {
            parent = _contentService.GetParent(source);
        }

        target.AllowedActions   = GetActions(source, parent, context);
        target.AllowedTemplates = GetAllowedTemplates(source);
        target.ContentApps      = _commonMapper.GetContentAppsForEntity(source);
        target.ContentTypeId    = source.ContentType.Id;
        target.ContentTypeKey   = source.ContentType.Key;
        target.ContentTypeAlias = source.ContentType.Alias;
        target.ContentTypeName  =
            _localizedTextService.UmbracoDictionaryTranslate(_cultureDictionary, source.ContentType.Name);
        target.DocumentType      = _commonMapper.GetContentType(source, context);
        target.Icon              = source.ContentType.Icon;
        target.Id                = source.Id;
        target.IsBlueprint       = source.Blueprint;
        target.IsChildOfListView = DetermineIsChildOfListView(source, parent, context);
        target.IsContainer       = source.ContentType.IsContainer;
        target.IsElement         = source.ContentType.IsElement;
        target.Key               = source.Key;
        target.Owner             = _commonMapper.GetOwner(source, context);
        target.ParentId          = source.ParentId;
        target.Path              = source.Path;
        target.SortOrder         = source.SortOrder;
        target.TemplateAlias     = GetDefaultTemplate(source);
        target.TemplateId        = source.TemplateId ?? default;
        target.Trashed           = source.Trashed;
        target.TreeNodeUrl       = _commonTreeNodeMapper.GetTreeNodeUrl <ContentTreeController>(source);
        target.Udi               =
            Udi.Create(source.Blueprint ? Constants.UdiEntityType.DocumentBlueprint : Constants.UdiEntityType.Document, source.Key);
        target.UpdateDate = source.UpdateDate;
        target.Updater    = _commonMapper.GetCreator(source, context);
        target.Urls       = GetUrls(source);
        target.Variants   = _contentVariantMapper.Map <TVariant>(source, context);

        target.ContentDto = new ContentPropertyCollectionDto
        {
            Properties = context.MapEnumerable <IProperty, ContentPropertyDto>(source.Properties).WhereNotNull()
        };
    }