Copied to clipboard

Flag this post as spam?

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


  • Jeroen Breuer 4909 posts 12266 karma points MVP 5x admin c-trib
    May 18, 2016 @ 09:15
    Jeroen Breuer
    0

    Convert IContent to IPublishedContent

    Hello,

    We need to work with some unpublished content, but we want to get this data as an IPublishedContent because the API is much easier to use. For example for an IPublishedContent we can use Property Value Converters.

    The unpublished content doesn't need to be edited so there is no need to use IContent, but for now that is the only way to get unpublished content.

    Is there a way to get convert an IContent to IPublishedContent? I know Nested Content and Archetype can also return their data as an IPublishedContent.

    Jeroen

  • Stephen 767 posts 2273 karma points c-trib
    May 18, 2016 @ 09:20
    Stephen
    0

    Nothing built-in that I can remember of, in v7. So you'd have to implement your own IPublishedContent implementation. Works.

    (hint: Umbraco.Web.PublishedCache.PublishedNoCache.PublishedContent in 7cc)

  • Jeroen Breuer 4909 posts 12266 karma points MVP 5x admin c-trib
    May 18, 2016 @ 09:24
  • Jeroen Breuer 4909 posts 12266 karma points MVP 5x admin c-trib
    May 18, 2016 @ 09:36
    Jeroen Breuer
    0

    Found the Umbraco.Web.PublishedCache.PublishedNoCache.PublishedContent. That also looks like a nice example :-) https://github.com/umbraco/Umbraco-CMS/blob/dev-v7-contentcache/src/Umbraco.Web/PublishedCache/PublishedNoCache/PublishedContent.cs

  • Jeroen Breuer 4909 posts 12266 karma points MVP 5x admin c-trib
    May 18, 2016 @ 15:10
    Jeroen Breuer
    106

    I've looked at the examples and I've created an experimental extension method that can convert an IContent to an IPublishedContent. I'm not really sure if I've implemented everything correct, but I did some some tests and everything seems to work.

    Most of the code is copied from the PublishedContent example. It had a lot of internal methods which I had to copy to get it work.

    The extension method can be found here: https://gist.github.com/jbreuer/dde3605035179c34b7287850c45cb8c9

    Now it's possible to do this:

    // Get the unpublished version of the current node.
    var content = this.Services.ContentService.GetById(nodeid);
    
    // Convert it to an IPublishedContent. So this IPublishedContent has the unpublished version.
    var publishedContent = content.ToPublishedContent();
    

    I've tried things like publishedContent.DescendantsOrSelf() and that seems to be working.

    Jeroen

  • Jeroen Breuer 4909 posts 12266 karma points MVP 5x admin c-trib
    Dec 16, 2016 @ 08:23
    Jeroen Breuer
    0

    I blogged about how you can convert IContent to IPublishedContent. It also has a working example: http://24days.in/umbraco-cms/2016/umbraco-edge-case-stories/#convert

    Jeroen

  • Amalie Wowern 145 posts 274 karma points MVP c-trib
    Apr 24, 2020 @ 08:17
    Amalie Wowern
    0

    Do anyone have an extensions that works with Umbraco 8

  • Gurumurthy 56 posts 129 karma points
    Sep 03, 2020 @ 12:16
    Gurumurthy
    0

    Hi Jeroen,

    Just to get clarification that, the package Enum Lists will work with v8 ? or is their any plans to upgrade to Latest.

    https://our.umbraco.com/packages/backoffice-extensions/enum-lists

    Thanks,

    Gurumurthy J V

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies