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 - umbraco-contentment/docs/editors/data-list.md at develop · leekelleher/umbraco-contentment · GitHub

Any help would be greatly appreciated. Thanks.


This is a companion discussion topic for the original entry at https://our.umbraco.com/forum/111290-contentment-icontentmentcontentcontext-not-returning-node-when-used-within-block-list-editor

Hi, I have the same issue. I use my data list in a block element, but the context returns the IPublishedContent where the block is used. I would expect it should return the block IPublishedElement where the property is used, not the top content model.

I upgraded to 5.1.0, but it did not change anything. @leekelleher

Is there a way to get get the contextof the type where the property is used?

@ewuski Unfortunately not, it’s beyond the capabilities of the Data List editor.

This is due to how the Block List data can be accessed programmatically, it’s effectively blobs of JSON in property data, not queryable on the server-side.

My recommendation would be to roll your own custom property editor that could try to access the Block data, and use it however you need to.