U4-2713 - Property Editor Value Converters don't get applied to Umbraco.TypedMedia

Created by Jeavon Leopold 24 Aug 2013, 08:03:21 Updated by Dirk 10 Sep 2013, 10:12:53

Relates to: U4-2824

When a property editor that has a PEVC is used on a media item and accessed using Umbraco.TypeMedia, it always returns null. e.g. var a = Umbraco.TypedMedia(1047); var c = a.GetPropertyValue("testContentPicker");

var c is always null (Umbraco Core Property Editor Converters installed)

Comments

Dirk 24 Aug 2013, 08:51:08

I like to use a custom '''''PEVC''''' for Media Type Image to get a strongly typed object like so: var mediaItem = Umbraco.TypedMedia(Model.Content.GetPropertyValue("myMediaPicker")); if (mediaItem != null) { cropList = mediaItem.GetPropertyValue("crops"); As far as I understand the place to add this would be in Umbraco.Core.PublishedContentHelper.GetDataType()and my proposal would be this internal static Guid GetDataType(ApplicationContext applicationContext, string docTypeAlias, string propertyAlias) { if (GetDataTypeCallback != null) return GetDataTypeCallback(docTypeAlias, propertyAlias);

var key = new Tuple<string, string>(docTypeAlias, propertyAlias);
return PropertyTypeCache.GetOrAdd(key, tuple =>
	{
		var result = applicationContext.Services.ContentTypeService.GetContentType(docTypeAlias);
		//start handle media
		if (result == null)
		{
			var mediaResult = applicationContext.Services.ContentTypeService.GetMediaType(docTypeAlias);
			if (mediaResult == null)
				return Guid.Empty;
			var mediaProperty = mediaResult.CompositionPropertyTypes.FirstOrDefault(x => x.Alias.InvariantEquals(propertyAlias));
			if (mediaProperty == null) return Guid.Empty;
			return mediaProperty.DataTypeId;
		}
		//end handle media
		if (result == null) return Guid.Empty;

	//SD: we need to check for 'any' here because the collection is backed by KeyValuePair which is a struct
	// and can never be null so FirstOrDefault doesn't actually work. Have told Seb and Morten about thsi 
	// issue.
	if (!result.CompositionPropertyTypes.Any(x => x.Alias.InvariantEquals(propertyAlias)))
	{
		return Guid.Empty;
	}
	var property = result.CompositionPropertyTypes.FirstOrDefault(x => x.Alias.InvariantEquals(propertyAlias));
	//as per above, this will never be null but we'll keep the check here anyways.
	if (property == null) return Guid.Empty;
	return property.DataTypeId;
});

} The extra cod is between {color:#990000}//start handle media and {color:#990000}//end handle media comment. This works in the above context, but I can not foresee all the implications this might have. Seems to be a quit complex topic.

I hope this helps.

Yours, Dirk


Stephan 28 Aug 2013, 15:23:20

Just to make sure I understand: you have created your own PEVC that should return an IPublishedContent but the PEVC is not used for media items, right?


Jeavon Leopold 28 Aug 2013, 15:39:31

Yes, it works fine on the Model and also with Umbraco.TypedContent (haven't tried Umbraco.Content) but doesn't work with Umbraco.TypedMedia. I just used a Content Picker from this package http://our.umbraco.org/projects/developer-tools/umbraco-core-property-editor-converters for test purpose.


Dirk 28 Aug 2013, 16:02:09

And I did the above listed changes, replaced the Umbraco.Core.dll in an regular v6.1.3 installation and the PEVC in the ImageCropperExtended v2.0.2 was correctly used from Umbarco.TypedMedia.


Shannon Deminick 29 Aug 2013, 01:43:54

The way this should work is that at the service level we should be able to retrieve the IContentTypeBase object regardless of content/media, will add this and fix up


Shannon Deminick 29 Aug 2013, 01:49:32

Hrm, I think we're gonna have to find a way to pass a boolean flag to this method to check if it is content or media because if a content type and media type have the same property type alias we'll have issues.


Shannon Deminick 29 Aug 2013, 01:59:30

Fixed in 9fc3efd73a7b6bb0fe7ccac36f900c6714734a39


Shannon Deminick 29 Aug 2013, 02:11:56

and in 232c81543a79d33d31932cb86519730b1486bb72


Jeavon Leopold 29 Aug 2013, 06:22:51

Awesome, thanks Shannon!


Stephan 29 Aug 2013, 16:06:58

Just a quick note: there's been a discussion some time ago about whether it was a good idea to let media and content share the same content type name space or not. I think the conclusion was that it was better to have one namespace, and that the back-end UI should ensure it, ie that it's not possible to have both media type "Image" and content type "Folder".

Because in many places in Umbraco, it causes issues. And because in the future media and content may become closer and closer.

I think we should make a final decision on that question. My vote, have 1 common namespace.


Priority: Normal

Type: Bug

State: Fixed

Assignee: Shannon Deminick

Difficulty: Normal

Category:

Backwards Compatible: True

Fix Submitted:

Affected versions:

Due in version: 6.2.0

Sprint:

Story Points:

Cycle: