10

I am building a small POC website using the Tridion Reference Implementation.

In my site, i have a custom multimedia schema, where I define a number of metadata values for an image.

In my model, I defined a property for a Multimedia link to this schema

[SemanticProperty("s:product")]
public ProductImage Product { get; set; }

and my ProductImage class inherits from the Image class

public class ProductImage : Image
{

    //define custom metadata properties here
}

Unfortunately, this doesn't seem to work out of the box. The TRI mapper class does map all the component fields to the appropriate model properties, but my Product property always gets a null value (when I change the class of product to Image, it does work.

I looked in the TRI source code, and searched for the DD4TModelBuilder class, which is responsible for mapping these component fields to my model properties. It looks like currently, this mapper only supports mapping multimedia link fields to models of type Image, Download or YouTubeVideo (which are included in the core module of the TRI).

I tried to extend the DD4TModelBuilder class, but the functions responsible for generating Image classes can't be overridden.

I'm wondering what my best option would be, should i create my own ModelBuilder class, copying all functionality from the DD4TModelBuilder, or is there another way (or am I doing something wrong) ?

  • Did you annotate your ProductImage class? If I remember correctly you need to do that.. – Quirijn Feb 13 '15 at 14:08
  • I tried, but that didn't help. – Harald Hoffelinck Feb 13 '15 at 14:51
7

There is indeed some limitations in mapping Multimedia Link fields in the TRI codebase. If I remember correctly there was an item on the backlog to make this more generic, but it didnt make the cut for TRI 1.0. You could try making the link field a component link field rather than a multimedia link field to see if this helps - it should be possible to map to arbitrary models from a component link field, although you will probably need the fix mentioned here.

There are probably good reasons to have a multimedia rather than component link field, so if this is the cause of your issues, let me know and I will see if I can "hotfix" the code to get it working with Multimedia link fields also - mapping MM Components/Links only to Image, YouTubeVideo and Download is not a workable restriction.

By the way its not necessary to annotate your ProductImage class, as when this is mapped as part of a component link field, the model property determines the mapped class, so it will just try to map whatever linked component it finds to this.

UPDATE - this issue is fixed in this pull request.

  • thanks for this suggestion. Changing from a multimedia link to a regular component link does seem to work. It is a good workaround for now. – Harald Hoffelinck Feb 17 '15 at 16:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.