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

Expose ContentItem props - Data and Elements #15923

Open
MikeKry opened this issue Apr 30, 2024 · 0 comments
Open

Expose ContentItem props - Data and Elements #15923

MikeKry opened this issue Apr 30, 2024 · 0 comments

Comments

@MikeKry
Copy link
Contributor

MikeKry commented Apr 30, 2024

Is your feature request related to a problem? Please describe.

This feature request aims to provide easier custom implementations on project side without modifying core. Application can be in custom importers, typed fetching of elements on project side etc. Right now I have problems with creating custom implementations that work with elements.

Example on Elements property:
I have a blog post type defined in CMS (so it is a dynamic content type). It has some fields that I want to fetch, but I do not want to register it in code. So I have concrete class, that inherits ContentPart and exposes some fields (dont want to use deserialize/reflection/..).

But there is a problem - when I use contentItem.Get("BlogPost") in controller, it works okay. But when I call it at indexprovider level, it throws exception.

Exception is thrown because at IndexProvider, Elements array is already filled up. And it contains "BlogPost" entry with a different type (ContentPart) that can not be casted to my type (BlogProps). So what I can do now is to clear Elements array and it will work again. But I cannot do that from project level, so my only way to clear it, is to call self referencing merge - "contentItem.Merge(contentItem, replacesettings..);" because it contains this Elements.Clear().

Example on data property:
I have created a custom importer that transforms CSV data from old solutions like Joomla and I am using contentManager to handle data operations. But that means I need to transform data to ContentItems.

Currently, there is no option to customize data from project. So I need to do this:
var json = JsonConvert.SerializeObject(importModel);
var model = JsonConvert.DeserializeObject(json);

This approach uses predefined JsonConvertor from OC that will transform data to form I need, but it is not very elegant.

Describe the solution you'd like

In my opinion, properties on ContentItem should be public, so it is possible to play with them as needed. It is well designed for usecase that currently OrchardCore needs, but for customization, it becomes very challenging when I do not want to customize core packages.

Basically it is about making ContentElement.Data and ContentElement.Elements public

Describe alternatives you've considered

Dont know any, feel free to suggest something else. I know many other people did their importers, so maybe there is other way.

For elements, solution might be also some parameter "UseCache" that allows to ignore fetching from elements.

Related also to #15530 (reply in thread)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant