Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Jakob Lithner 61 posts 264 karma points
    Jul 07, 2018 @ 12:46
    Jakob Lithner
    0

    DropDownList values displayed in content ListViews but not in member ListViews

    I followed suggestions from here: https://gist.github.com/tompipe/beaf44f29d416249dfdeaa9d1b24956a

    I found it to be an excellent solution to overcome a strange limitation. It works fine for content ListViews.

    Now I tried to extend it to cover member ListViews as well. I find the member content. The items collection is iterated. The prop.Value is detected, translated and set with new display text value. BUT the displayed view still holds the id arrays: ["38"] and not the generated texts.

    Why is that? Is there some hidden difference in how member list views are displayed compared to content list views? Is there a difference in event chain causing the updated values to be neglected?

    I am really confused.

    public class FixDropDownPreValueDisplayInListViewsHandler : DelegatingHandler
    {
        // Ensure we're only processing requests to getchildren - hopefully only listviews
        private static readonly string[] PathsWithTranslationNeeds = { "/umbraco/backoffice/UmbracoApi/Content/GetChildren", "/umbraco/backoffice/UmbracoApi/Member/GetPagedResults" };
    
        protected override async Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
        {
            // Wait for the request to be processed
            var response = await base.SendAsync(request, cancellationToken);
    
            var absolutePath = request?.RequestUri?.AbsolutePath;
            if (!absolutePath.IsNullOrWhiteSpace() && PathsWithTranslationNeeds.Contains(absolutePath))
            {
                var content = (ObjectContent)response.Content;
    
                // Swap individual properties with text representation where appropriate
                switch (content?.Value)
                {
                    case PagedResult<ContentItemBasic<ContentPropertyBasic, IContent>> contentResult:
                        if (contentResult.Items != null)
                        {
                            foreach (var item in contentResult.Items)
                            {
                                if (item != null)
                                {
                                    foreach (var prop in item.Properties.Where(p => DropListTranslator.IsTranslatedType(p.Editor)))
                                    {
                                        prop.Value = DropListTranslator.GetText(prop.Value);
                                    }
                                }
                            }
                        }
                        break;
    
                    case PagedResult<MemberBasic> memberResult:
                        if (memberResult.Items != null)
                        {
                            foreach (var item in memberResult.Items)
                            {
                                if (item != null)
                                {
                                    foreach (var prop in item.Properties.Where(p => DropListTranslator.IsTranslatedType(p.Editor)))
                                    {
                                        prop.Value = DropListTranslator.GetText(prop.Value);
                                    }
                                }
                            }
                        }
                        break;
                }
            }
    
            return response;
        }
    }
    
Please Sign in or register to post replies

Write your reply to:

Draft