|
1 | | -# Models Builder .Property Override |
| 1 | +# Umbraco.Community.ModelsBuilder.PropertyOverride |
2 | 2 |
|
3 | 3 | [](https://www.nuget.org/packages/Umbraco.Community.ModelsBuilder.PropertyOverride/) |
4 | 4 | [](https://www.nuget.org/packages/Umbraco.Community.ModelsBuilder.PropertyOverride) |
5 | 5 | [](../LICENSE) |
6 | 6 |
|
7 | | -TODO: describe your package |
| 7 | +This package re-introduces functionality for overriding ModelsBuilder property implementations that was lost in Umbraco 9+. |
8 | 8 |
|
9 | | -<!-- |
10 | | -Including screenshots is a really good idea! |
| 9 | +Umbraco versions 13.x - 15.x are supported. |
11 | 10 |
|
12 | | -If you put images into /docs/screenshots, then you would reference them in this readme as, for example: |
| 11 | +Properties can be marked up with a re-implemented `[ImplementPropertyType("alias")]` attribute, which causes them to be ignored when generating models through the default ModelsBuilder. |
13 | 12 |
|
14 | | -<img alt="..." src="https://github.com/Gibe/Umbraco.Community.ModelsBuilder.PropertyOverride/blob/develop/docs/screenshots/screenshot.png"> |
15 | | ---> |
| 13 | +In addition, classes can be marked up with `[ImplementAllPropertyTypes]`, which causes all properties on the class to be ignored, this is functionally equivalent to adding `[ImplementPropertyType("alias")]` to every property on the class. |
| 14 | + |
| 15 | +Legacy (Umbraco 8.x) documentation for the `[ImplementPropertyType("alias")]` attribute can be found [here](https://our.umbraco.com/Documentation/Reference/Templating/Modelsbuilder/Control-Generation-vpre8_5#implement-property-type). |
| 16 | + |
| 17 | +## Examples |
| 18 | + |
| 19 | +`[ImplementPropertyType("alias")]` to ignore properties on an individual basis: |
| 20 | + |
| 21 | +``` |
| 22 | +using Umbraco.Cms.Infrastructure.ModelsBuilder; |
| 23 | +
|
| 24 | +namespace ModelsBuilder.PropertyOverride.TestSite.Models |
| 25 | +{ |
| 26 | + public partial class Home |
| 27 | + { |
| 28 | + [ImplementPropertyType("content")] |
| 29 | + public global::Umbraco.Cms.Core.Models.Blocks.BlockListModel Content => this.Value<global::Umbraco.Cms.Core.Models.Blocks.BlockListModel>(_publishedValueFallback, "content"); |
| 30 | +
|
| 31 | + [ImplementPropertyType("title")] |
| 32 | + public virtual string Title => this.Value<string>(_publishedValueFallback, "title"); |
| 33 | + } |
| 34 | +} |
| 35 | +``` |
| 36 | + |
| 37 | +`[ImplementAllPropertyTypes]` to ignore all properties: |
| 38 | + |
| 39 | +``` |
| 40 | +using Umbraco.Cms.Infrastructure.ModelsBuilder; |
| 41 | +
|
| 42 | +namespace ModelsBuilder.PropertyOverride.TestSite.Models |
| 43 | +{ |
| 44 | + [ImplementAllPropertyTypes] |
| 45 | + public partial class HomePageBlock |
| 46 | + { |
| 47 | + public virtual global::Umbraco.Cms.Core.Models.MediaWithCrops Image { get; set; } |
| 48 | + public virtual string SubTitle { get; set; } |
| 49 | + public virtual string Title { get; set; } |
| 50 | + } |
| 51 | +} |
| 52 | +``` |
16 | 53 |
|
17 | 54 | ## Installation |
18 | 55 |
|
19 | | -Add the package to an existing Umbraco website (v13+) from nuget: |
| 56 | +Add the package to an existing Umbraco website (Umbraco 13+) from nuget: |
20 | 57 |
|
21 | 58 | `dotnet add package Umbraco.Community.ModelsBuilder.PropertyOverride` |
22 | 59 |
|
23 | | -TODO *provide any other instructions for someone using your package* |
24 | | - |
25 | 60 | ## Contributing |
26 | 61 |
|
27 | | -Contributions to this package are most welcome! Please read the [Contributing Guidelines](CONTRIBUTING.md). |
| 62 | +Contributions to this package are most welcome! |
28 | 63 |
|
29 | 64 | ## Acknowledgments |
30 | 65 |
|
31 | | -TODO |
| 66 | +[tristanjthompson](https://github.com/tristanjthompson) & [zade107](http://github/zade107) |
0 commit comments