flaithbheartaigh / dynamic-delivery-4-tridion

Automatically exported from code.google.com/p/dynamic-delivery-4-tridion
Other
0 stars 0 forks source link

Binaries referenced as a link in a rich text field don't get published. #37

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
When you reference a pdf for example in a rich text field, it doesn't get 
published.

Please update the BinaryPublisher to do so.

Source code to fix it:

foreach (XmlElement img in 
xml.SelectNodes("//xhtml:a[@xlink:href[starts-with(string(.),'tcm:')]]", 
xml.NamespaceManager))
            {
                log.Debug("found link node " + img.OuterXml);
                XmlAttribute link = (XmlAttribute)img.SelectSingleNode("@xlink:href", xml.NamespaceManager);
                Component component = (Component)engine.GetObject(link.Value);
                if (component.ComponentType == ComponentType.Multimedia)
                {
                    log.Debug("about to publish binary with uri " + link.Value);
                    string path = PublishMultimediaComponent(link.Value);
                    log.Debug("binary will be published to path " + path);
                    img.SetAttribute("src", path);
                }
                else
                {
                    log.Debug("Component is not a multimedia component.");
                }

            }

Original issue reported on code.google.com by thijs.bo...@incentro.com on 10 Feb 2014 at 11:08

GoogleCodeExporter commented 8 years ago
Fixed and checked in (trunk). Must be tested asap.

Original comment by quirijn....@gmail.com on 2 Apr 2014 at 9:18

GoogleCodeExporter commented 8 years ago
This change needs to be amended so that the a tag uses href not src

The line : img.SetAttribute("src", path);

Should be chnaged to be : img.SetAttribute("href", path);

foreach (XmlElement img in 
xml.SelectNodes("//xhtml:a[@xlink:href[starts-with(string(.),'tcm:')]]", 
xml.NamespaceManager))
            {
                log.Debug("found link node " + img.OuterXml);
                XmlAttribute link = (XmlAttribute)img.SelectSingleNode("@xlink:href", xml.NamespaceManager);
                Component component = (Component)engine.GetObject(link.Value);
                if (component.ComponentType == ComponentType.Multimedia)
                {
                    log.Debug("about to publish binary with uri " + link.Value);
                    string path = PublishMultimediaComponent(link.Value);
                    log.Debug("binary will be published to path " + path);
                    img.SetAttribute("href", path);
                }
                else
                {
                    log.Debug("Component is not a multimedia component.");
                }

            }

Original comment by c.ecc...@building-blocks.com on 14 Apr 2014 at 12:16

GoogleCodeExporter commented 8 years ago
Yes you are right. My bad... Too quick of an edit ;)

Original comment by mg.bo...@innercore.eu on 15 Apr 2014 at 9:27

GoogleCodeExporter commented 8 years ago
Marking this as not fixed as the implemented fix adds the wrong attribute (src 
instead of href).

Original comment by a.pl...@building-blocks.com on 27 May 2014 at 2:29

GoogleCodeExporter commented 8 years ago
I think the problem lies in line 86 of the BinaryPublisher. I would change it 
only I don't have time today to test what happens if there is an href attribute 
already (without the xlink namespace prefix perhaps). If anyone else feels like 
it, please go ahead. 

Original comment by quirijn....@gmail.com on 28 May 2014 at 12:30

GoogleCodeExporter commented 8 years ago
Hi Quirijn - we've made the change Chris mentions above in an internal copy of 
the DD4T TBBs - it does fix the linking. I'll try and commit back when I get 
the chance.

There is still an issue with the RichTextHelper though - it picks up the 
xlink:href attribute, tries to resolve the binary as a Component link, fails 
and strips the anchor out.

I think the following XPath expression (RichTextHelper.cs line 46) needs to be 
modified to also exclude "href" attributes with no prefix.

"//xhtml:a[@xlink:href[starts-with(string(.),'tcm:')]][@xhtml:href='' or 
not(@xhtml:href)]"

Original comment by a.pl...@building-blocks.com on 28 May 2014 at 2:32