Quantcast
Channel: Developer to developer
Viewing all articles
Browse latest Browse all 9076

Content Delivery API: Exposing derived properties

$
0
0

Hi,

We have a page type with two properties: Heading and NavigationHeading, where NavigationHeading defaults to the value of Heading if NavigationHeading is empty (as seen below).

[ContentType(DisplayName = "MyPageType", GUID = "4c19e432-905d-46d7-bd16-ea8754a4e268", Description = "")]
    public class MyPageType : PageData
    {
        [CultureSpecific]
        [Display(
            Name = "Heading",
            Description = "",
            GroupName = SystemTabNames.Content,
            Order = 1)]
        public virtual string Heading { get; set; }
        [CultureSpecific]
        [Display(
            Name = "NavigationHeading",
            Description = "",
            GroupName = SystemTabNames.Content,
            Order = 2)]
        public virtual string NavigationHeading
        {
            get
            {
                var navigationHeading = this.GetPropertyValue(page => page.NavigationHeading);
                return string.IsNullOrWhiteSpace(navigationHeading) ? Heading : navigationHeading;
            }
            set
            {
                this.SetPropertyValue(page => page.NavigationHeading, value);
            }
        }
    }

When retrieving this page through the Content Delivery API, both properties are exposed. However, the logic expressed for NavigationHeading is not run when the page is serialized. 

The table below illustrates the behaviour of the Content Delivery API for the page type above.

value of Heading in databasevalue of NavigationHeading in databasevalue of Heading in API-responsevalue of NavigationHeading in API-response
<empty><empty><empty><empty>
Heading<empty>Heading<empty>
<empty>NavigationHeading<empty>NavigationHeading
HeadingNavigationHeadingHeadingNavigationHeading

However, we expect the behaviour to be like this (notice the difference in the second row)

value of Heading in databasevalue of NavigationHeading in databasevalue of Heading in API-responsevalue of NavigationHeading in API-response
<empty><empty><empty><empty>
Heading<empty>HeadingHeading
<empty>NavigationHeading<empty>NavigationHeading
HeadingNavigationHeadingHeadingNavigationHeading

Why isn't logic expressed in a page type's property "get"-body run when serializing objects through the Content Delivery API? What can we do to achieve this?

- Thomas


Viewing all articles
Browse latest Browse all 9076

Trending Articles