9

We're using DD4T version 1.31 as the foundation for our MVC5 project and I've run into an awkward situation: When links in a rich text fields get resolved this works perfectly for component links but not for binary links (links to multimedia components). The binary links are always resolved to "null".

I have verified that the binary is published to the database, is accessible using its respective URL through the Binary Distribution Module and is present in the broker database.

I've made the code as simple as possible but perhaps that is the problem?

LinkFactory dd4tLinkFactory = new LinkFactory();
string url = dd4tLinkFactory.ResolveLink(componentUri);

Do i need to setup any properties of the LinkFactory to allow it to resolve binary links?

8

The problem here is that the DD4T LinkFactory class only looks for regular component links. It only queries the link_info broker table, which does not contain links to binaries. When we had to implement a similar functionality, we had to customize the DD4T code.

What you could do is something like this

  • create a custom LinkFactory class, inheriting from the standard dd4t linkfactory class
  • in the LinkFactory.ResolveLink function, add the following logic

    • use the regular linkprovider to see if you can resolve the link. If the link resolves, you have a regular component link, so return this
    • if you don't find a link, use the binaryfactory to fetch the MM component from the broker, using the tcm uri that you are linking to. If you get a result, you can use the 'URL' property of the binary object as a link, otherwise the link can't be resolved.

    • Then, configure ninject, unity or any other Dependency Injection library that you use so it uses your custom class, instead of the default LinkFactory class

If you want to see the code of the default LinkFactory, you can find that here : https://code.google.com/p/dynamic-delivery-4-tridion/source/browse/trunk/dotnet/DD4T.Factories/LinkFactory.cs?r=367

The advantage of overriding the LinkFactory class is that your new code will also be used to resolve links in rich text fields, as the RichTextHelper functionality also uses this linkfactory.

| improve this answer | |
  • I'll go with this solution as I already have a custom LinkFactory that injects the CDN prefix for the binary URL (when configured in web.config) so this is the nicest fit in my situation. – Bjørn van Dommelen Dec 16 '14 at 14:45
4

Binary links aren't resolved at the application side since their URL is known at publish time. They should be resolved there.

I think linking to Binaries in Rich Text should be in the next version of DD4T (which I think will be called 2.0)

In the meantime you could write a C# TBB which parsed the output from the DD4T TBBs and checked whether the links were to Binaries yourself and do a publish for that Binary, updating the href with the URL.

| improve this answer | |
  • The challenge is that only part of the binary URL is known at pubblish time as Tridion isn't aware of the presence of a CDN on the CD environment. Only implementing binary RTF link resolving in a TBB would not be sufficient in our case. – Bjørn van Dommelen Dec 16 '14 at 14:32

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.