Page 1 of 1

Media field in Custom Product Entity

Posted: Mon Nov 10, 2014 8:39 am
by waddle
Hi,

I created a custom Product entity (let's call it MyProduct) with a field "reward" of type Media.

Code: Select all

@ManyToOne(targetEntity = MediaImpl.class)
@JoinColumn(name = "REWARD_ID")
@AdminPresentation(friendlyName = "reward", fieldType = SupportedFieldType.MEDIA)
private Media reward;


Problem is in admin, when rendered, I got all the Media fields (url, title, altText).
What I want the admin to render in the product detail page, is a picker for the media without all the fields. So I tried to add :

Code: Select all

@AdminPresentationToOneLookup(lookupDisplayProperty = "url")


It then renders what I want (only one field with the media picker), but when a click on the button "Lookup" to choose an image, some are missing when I compare the list to the "Media Assets List".
There's also a difference in the button, when all the Media fields are rendered I got a "Select/Upload image" for the "url" field, but when a add the annotation the button near the field is called "Lookup".

I guess I could use the Media Map of SkuImpl but it means I will have to change its annotation @AdminPresentationMapFields and that's not that easy I think.

So my question is : How should I write a Media field in a custom Entity to render it like the primary media is rendered ? And please, don't tell me to create my own map just for one field :-)

Keep up the good work !

BR,

Re: Media field in Custom Product Entity

Posted: Tue Dec 02, 2014 8:45 pm
by phillipuniverse
Originally I thought you would be able to use an @AdminPresentationMergeOverride and override the @@AdminPresentationMapFields as they are displayed on defaultSku.skuMedia but it doesn't look like we have functionality for that. I opened an issue at https://github.com/BroadleafCommerce/Br ... ssues/1182 to track this.

You are actually in a tough spot of some functionality that we have not implemented. What you really want is similar functionality to an @AdminPresentationToOneLookup (with the association) but instead of actually looking up a pre-created instance you want to create a new one on the fly. This works pretty well with our map structure but we don't have this option implemented for the lookups. I am creating a new issue for this at https://github.com/BroadleafCommerce/Br ... ssues/1183.

If you can deal without the extra metadata that the MediaImpl object provides, you can make that property into just a string and give it a field type of SupportedFieldType.ASSET_LOOKUP.

Re: Media field in Custom Product Entity

Posted: Wed Dec 03, 2014 8:02 am
by waddle
Thanks for the answer. I finally choose to create a specific map in my custom product entity.