Make ModelsBuilder Great (Again) #11854
Replies: 3 comments 6 replies
-
I'm a bit surprised that no one has replied to this discussion yet. Maybe there aren't that many having complex requirements like the ones you describe? But we do 🖐️ Pretty much all our Umbraco 8 sites are headless sites, and we return the generated models via our API. So we rely on the legacy ModelsBuilder to allow us changing the models a bit more to our needs, add a custom base class, constructor etc. I'm not entirely sure what you mean by type converters. Maybe it's similar to what we've been doing. For the individual property values, we have updated some of our packages to tailor the output:
This gives us a lot more flexibility. For one, serializing ModelsBuilder models as-is can be quite dangerous in terms of circular references - even though we have a custom JSON contract resolver to handle the properties from Umbraco's models. We've had some issues with page A having references to page B, which again has reference to page A - which would lead to these circular references when serializing to JSON. Besides also helping us minify the API output, this was one of the reasons I build the custom MNTP package. We can then have a minimalized item model which then don't expose those references. Even if we look past the circular references, which you might not experience if you're doing regular MVC sites, I think it would be awesome to have the concept of type converters introduced for many of the build-in property editors in Umbraco. As the legacy ModelsBuilder no longer seems to be in active development (even for Umbraco 8), I started dabbling a bit with my own ModelsBuilder-style package, but with some additional features to fit our needs as well. I never really finished it for Umbraco 8, but as we have gotten used to working with the features of the legacy ModelsBuilder, I've picked up my package again, this time for Umbraco 9. My work so far can be found on GitHub in the Limbo.Umbraco.ModelsBuilder repository (still very much work in progress). With models for regular pages, compositions and models for each block type element, we usually end up with a long list of models. Having these in the same folder quickly gets messy, so one feature in my package is to to place the models in relevant sub directories. By default, this means that member types are placed in a Members sub directory, media types in a Media sub directory, regular content types in a Content sub directory, and then element types in an Elements sub directory. Ideally there would also be an option to follow the folder structure from the backoffice. This would especially come in handy when doing multiple sites in the same installation, as they may have individual models specific to each site. The package also features an event / notifications system. For instance, there is a Although it's still a bit buggy for now, the package will also support decorating custom partial classes with an Besides re-using the build-in ModelsBuilder's section in Like I mentioned, this package mostly started as a hobby project in my spare time for Umbraco 8, but as we now need this functionality for Umbraco 9, I'm now also using company time to work on it. So at the very least, we'll have this as an internal package. I don't really have a clue how many people have needs beyond what is supported by the build-in ModelsBuilder. And I probably don't have the time to support this is a package also used by the Umbraco community, so I would very much appreciate if similar logic could be added to Umbraco. So perhaps it would be helpful to hear what HQ's plans are for the build-in ModelsBuilder (if they have any). |
Beta Was this translation helpful? Give feedback.
-
I missed this one. But I agree some extra flexibility would be nice. One is to ignore properties and another to implement your own in a custom class. Renaming would be nice, but not always needed in our case. But like @JasonElkin mentioned I got to hear a while back Umbraco is happy with the current state of modelsbuilder and does not plan to add extra features. |
Beta Was this translation helpful? Give feedback.
-
I'm going to start by saying I love models builder. It's a brilliant tool for the Umbraco CMS, both the full version and the embedded version. I have 2 wish list ideas for the embedded one.
For example:
I hope that makes some sort of sense. Then dictionary items can be a) Compile time safe, and b) runtime exception caught. They can be accessed like this: |
Beta Was this translation helpful? Give feedback.
-
N.B. This is not really about bringing back features that were present in "Full" ModelsBuilder
This is about making the ModelsBuilder we have in v9+ better.
The problem
ModelsBuilder is a bit of a blunt instrument and, I find, can result in cruft in larger or more complex projects.
Some examples...
Essentially, models often end up with just too much in them1.
The start of a solution
Most of the unwanted properties can be removed simply with the ability to ignore certain properties when the model is generated, allowing us to provide our own implementation in a partial class.
Though it might nice to have a bit more control over model generation including the ability to:
In the long term, this could be controlled in any number of ways - dashboard, config, feature flags etc., and these could all be packages, but initially I'd just like to have an API that makes these options possible.
I'm currently thinking that this would be best achieved by adding a notification here, to be able to override the type models sent to the builder.
Does this make sense?
Does anyone else want this feature?
Does the approach make sense?
Will a PR that does this get approved 😉?
Footnotes
🤓 This is really because ModelsBuilder models have more than one responsibility - they're both models for a published document (IPublishedContent) and viewmodels (they apply PropertyValueConverters that modify content for display). ↩
Beta Was this translation helpful? Give feedback.
All reactions