https://discord.umbraco.com logo
Hello, I would like to ask here, as no
# umbraco-chat
h
Hello, I would like to ask here, as no documentation for Umbraco 18 is uploaded yet. I would like to create elements programmatically in the new Library section, including folder structure. I saw that there are multiple services available: IElementEditingService, IElementContainerService, IElementPublishingService, and ElementService. At the moment, I am having problems with caching — specifically, elements created via IElementEditingService and then published via IElementPublishingService aren't found in the same session by IElementNavigationQueryService. What I'm wondering is: what is the planned/best-practice approach for querying and creating elements in the new Library section?
k
Yes, i saw similar issues during the development of element support for uSync ( https://github.com/umbraco/Umbraco-CMS/issues/22911 ) -*and i wouldn't be surprised if there is still a cacheing issue. * IMO The element service(s) are a little inconsistent - they don't follow the same pattern as the media and content services, some of the methods and the caching isn't in a consistent location for example the you need to use the element editing service to move things in and out of the trash, while the element contain service does this as opposed to the editing service (in the content and media service this is in the main services not the editing ones). as a result (and the thing i noticed in that issue) where the caching is cleared isn't consistent, and that's probibly what you are seeing 😞 in terms of management // creation this is what we have for uSync at the moment, https://github.com/KevinJump/uSync/blob/v18/main/uSync.Core/Serialization/Serializers/ElementSerializer.cs it seems to work, it might have a caching issue like you have noticed, but during testing i only observed the deleting one.
other thing that is worth noting (its in the usync code but not easy to spot) is elements require all the names and variant names to be set before they can be saved, if you have code creating content or media, you can create the content with its default name first and add the variant names later. very subtle but important difference, when dealing with variant elements.
l
To be honest, I'm a little surprised how different the elements are to actual content. I would have expected that elements were practically content with only a few limitations
s
Not completely related. But I notice elements in the library are given a ‘name’ which you can get via ipublishedelement. However this ‘name’ isn’t exposed in the deliveryapi. As traditionally normal elements don’t have name.
4 Views