How to get the alias of the Property Editor type used from a published property?
Hey all. Is there an easy way to get the editor type of a published property from the IPublishedContent?
I need to iterate through the properties in the Properties collection and based on the type do different things. However I cant see how I can get the alias of the editor type for a property.
EG lets say I wanted to do the following.
@foreach(var prop in Model.Content.Properties){
if(prop.PropertyType.PropertyEditorAlias == "Umbraco.MediaPicker"){
//then do something here
}
}
However my problem is that even though I can see the PropertyType object on the IPublishedProperties base class it is internal and I cannot access it.
Also before anyone says just use propertyTypeAlias that will not return what I want as that just returns the Property alias as defined on the document type. I need to go one step deeper and get the Editor type for the defined property.
I have resolved my own issue. Heres how I did it in case someone else goes looking for a similar answer in the future (edge case but none the less)
@{
var contType = Model.Content.ContentType;
}
@foreach(var prop in Model.Content.Properties){
var propType = contType.GetPropertyType(prop.PropertyTypeAlias).PropertyEditorAlias;
if(propType == "Umbraco.MediaPicker"){
//then do something here
}
}
Good that you find a way to do it ;-) I thought I'd offer an alternative approach, as this seems like a scenario that could be handled by a simple naming convention. I assume that you want to check for the alias of the PropertyEditor because it can be used on many different property types, which are usually named differently. But if you are developing a site and not a package you could simply append something like "MediaPicker" to the alias of the PropertyTypes that use this specific PropertyEditor / DataType. And if you need to ensure this is done consistently by others you could create an event handler for ContentType.Saving that updates the alias for PropertyTypes that use this PropertyEditor. And then you could do this:
@foreach(var prop inModel.Content.Properties){
if(prop.PropertyTypeAlias.EndsWith("MediaPicker"){ //then do something here }
foreach (var propertyType in propertyTypes) { string propertyEditorAlias = propertyType.PropertyEditorAlias; // Do stuff here based on the property editor alias. }
How to get the alias of the Property Editor type used from a published property?
Hey all. Is there an easy way to get the editor type of a published property from the IPublishedContent?
I need to iterate through the properties in the Properties collection and based on the type do different things. However I cant see how I can get the alias of the editor type for a property.
EG lets say I wanted to do the following.
However my problem is that even though I can see the PropertyType object on the IPublishedProperties base class it is internal and I cannot access it.
Also before anyone says just use propertyTypeAlias that will not return what I want as that just returns the Property alias as defined on the document type. I need to go one step deeper and get the Editor type for the defined property.
I have resolved my own issue. Heres how I did it in case someone else goes looking for a similar answer in the future (edge case but none the less)
Good that you find a way to do it ;-) I thought I'd offer an alternative approach, as this seems like a scenario that could be handled by a simple naming convention. I assume that you want to check for the alias of the PropertyEditor because it can be used on many different property types, which are usually named differently. But if you are developing a site and not a package you could simply append something like "MediaPicker" to the alias of the PropertyTypes that use this specific PropertyEditor / DataType. And if you need to ensure this is done consistently by others you could create an event handler for ContentType.Saving that updates the alias for PropertyTypes that use this PropertyEditor. And then you could do this:
Another approach could be to use a "Property Editor Value Converter" (http://our.umbraco.org/documentation/Extending-Umbraco/Property-Editors/value-converters-v6) for your MediaPicker, so you can use / check the type of a Property's value. Pseudocode example:
Just something to think about,
- Morten
I had to get to the property editor alias in backend code and used the content type service:
is working on a reply...