Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IContentmentContentContext not returning node when used within Block List Editor #306

Closed
1 task done
Mustachio1 opened this issue Feb 23, 2023 · 3 comments
Closed
1 task done
Assignees
Labels
cant-fix Unable to resolve this umbraco A concern for Umbraco

Comments

@Mustachio1
Copy link

Which Contentment version are you using?

4.4.1

Which Umbraco version are you using? For example: 8.14.1 - don't just write v8

10.4.0

Bug summary

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.

Steps to reproduce

  • Base install of Umbraco 10.4.0
  • Create a Page type in the CMS
  • Install Contentment 4.4.1
  • Configure a class that inherits from IDataListSource
  • Inject the IContentmentContentContext to that class
  • Create a Block List Editor property and add it to your page in the CMS.
  • Create a data type that uses your new IDataListSource class
  • Create a element type and add this new data type to it.
  • Add the new element type to the Block List Editor data type
  • Add the page to the root and add the new element type within it.

Expected result / actual result

I would expect to get the context IPublishedContent back from the line:

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

And would expect the isParent property to return true, indicating that it had gotten the context from the elements parent page.

But what actually happens is the above currentNode property is null.

Do you have Umbraco ModelsBuilder enabled?

  • Yes, it is enabled.

What browsers are you seeing the problem on?

Chrome

@Mustachio1 Mustachio1 added the bug-report Something isn't working label Feb 23, 2023
@leekelleher
Copy link
Owner

leekelleher commented Mar 1, 2023

@Mustachio1 Thanks for raising this.

Sorry to say, Block List (and Nested Content) doesn't work well with the IContentmentContentContext feature.
The reason being, when Block List makes the API call to get the element-type scaffolds, it passes through a parentId value of -20, (which is the recycle bin ID), so we can't get a contextual content node using that value.

ref: https://github.com/umbraco/Umbraco-CMS/blob/release-10.4.0/src/Umbraco.Web.UI.Client/src/common/services/blockeditormodelobject.service.js#L399

For reference, there have been previous discussions about potential workarounds here: #30 (comment)

@leekelleher leekelleher added umbraco A concern for Umbraco cant-fix Unable to resolve this and removed bug-report Something isn't working labels Mar 1, 2023
@Mustachio1
Copy link
Author

@leekelleher After I sent the bug report and did some more reading I was coming to the conclusion that it wasn't a Contentment issue at all, and rather an Umbraco one.

Thanks for taking the time to reply, and for the links to other possible solutions.

Love using Contentment and install it on most projects now, looking forward to seeing where you take it next!

Cheers

@leekelleher
Copy link
Owner

leekelleher commented Dec 3, 2023

Follow up on this issue; a patch to resolve this for the Block List editor has been merged in, umbraco/Umbraco-CMS#15063, due for release in Umbraco v13.1.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cant-fix Unable to resolve this umbraco A concern for Umbraco
Projects
None yet
Development

No branches or pull requests

2 participants