Copied to clipboard

Flag this post as spam?

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


  • Andrew Murray 1 post 71 karma points
    Feb 23, 2023 @ 17:02
    Andrew Murray
    0

    Contentment - IContentmentContentContext not returning node when used within Block List Editor

    I have an issue where I am using Contentment [V4.4.1], in an Umbraco [v10.4.0] solution, and I am trying to set up a Contentment Data List property editor.

    To do this, I am defining a class inheriting from IDataListSource to create a custom data source that I can access from within the CMS.

    The issue comes when using the IContentmentContentContext within the GetItems method of that class, which I am injecting to the constructor.

    The Umbraco solution is multi-tenant (2 sites in 1 CMS), and there are some shared content elements within the two sites. So, I wanted to create a content element, and have a "Background Colour" property, which when opened would detect the context of where it is being used within the content tree(s) and return different brand colours depending on which site it is being used on.

    The issue I am experiencing is that when I try to access the context method like this:

    IPublishedContent? currentNode = contentmentContentContext.GetCurrentContent(out bool isParent);
    

    If the Background Colour property is being used within an element type (IPublishedElement?), then the above line of code is always returned as null. It works as expected if I put the background colour property on the Content Type (IPublishedContent) - At the page level, rather than the element level.

    There seems to be a bool out property for checking whether the item returned is a parent item or not. I would presume if I called this method from an IPublishedElement type, that it would return its parent IPublishContent type and out the isParent bool as true.

    It just returns as null, and I can't figure out a way to get the context from Block List Editor content blocks.

    Has anyone experienced this issue?

    Does anyone have a solution for context injection that works at the element level?

    The docs seem to suggest that you can access context from the element level - https://github.com/leekelleher/umbraco-contentment/blob/develop/docs/editors/data-list.md#accessing-contextual-content

    Any help would be greatly appreciated. Thanks.

  • Didier Marin 17 posts 89 karma points
    Aug 22, 2024 @ 14:04
    Didier Marin
    0

    if you upgrade to latest version (5.0.2), it works fine

Please Sign in or register to post replies

Write your reply to:

Draft