Check if a node implements a composition (custom condition); easier way and bug?

Hi Luuk, fantastically interesting case.

Especially because this is regarding one of the things that are way different than the earlier version. The facts that its not the server handling the composing of Content Types, but the client. The server just stores the Content Type Model and knows nothing about how they merge.

This means the Client loads all Content Types needed for your Document.
All that is happening through the UmbContentTypeStructureManager, which is the one you need to talk to, no need to ask the server.

This one holds all the data of the current ContentTypes (The owner and the compositions).

The following example outputs all the Aliases and Uniques(key/GUIDs) of the Content Types for the current Content(Document/Media/member). Notice I made sure to make this generic enough to work for Documents, Media and Members, by using the CONTENT_WORKSPACE context token.

this.consumeContext(UMB_CONTENT_WORKSPACE_CONTEXT, (instance) => {
			console.log(instance.structure.getContentTypeUniques(), instance.structure.getContentTypeAliases());
		});

Because the composing is happening in the Client, it means that the Composition can happen on the fly, meaning it can also change reactively. So it is not ideal for your Condition to assume the Composition is static(Like asking the server or getting the Aliases initially). Instead we will observe the content type aliases, so your conditions approves once it is in place. And as well disapproves if it goes away again.

	this.consumeContext(UMB_CONTENT_WORKSPACE_CONTEXT, (instance) => {
		this.observe(instance.structure.contentTypeAliases, (aliases) => {
			if(aliases.includes('my-content-type-alias')) {
				this.permitted = true;
			} else {
				this.permitted = false;
			}
		});
	});

It may seem like overdoing things, but one reason that exists today is that you can edit Content Types while having a Document open. And in a not-so-far future we will implement Signal-R. Meaning Content Type Compositions could change across Tabs and Devices — So I will recommend always making reactive logic and assume things can change.

I hope this works for you and then I’m really looking forward to hear how it goes.

And maybe you will see new ways to go about things, cause these abilities opens op for a whole new way of building things. So please go read more about the Structure Manager here: UmbContentTypeStructureManager | @umbraco-cms/backoffice

Cause it could be that you rather wanted your Workspace View to appear when a Content Type contains a Property of a certain Data-Type. Cause that would also be right at hand.

Good luck.

1 Like