XF 2.1 Attachments issue (images)

Lawrence

Well-known member
Good day all. I'm currently working on a new add-on that supports attachments and have an issue with images. Attachments that are not images display properly and are downloadable, however, images display just as View attachment xxx links (no thumbnails, and they open in a new window when clicked).

The image attachment data is stored in xf_attachment_data with the file hash, and the content type is set correctly in the xf_attachment table. When I look at the saved messages in my add-ons table, images are saved in the correct format as expected, but for some reason when viewing them they do not get processed, and display as links mentioned above.

If I set this function in my entity isAttachmentEmbedded to always return false, the images are displayed as thumbnails, and when clicked opens the lightbox (though the image links are still displayed above them), so I know all the image data is there. The question is, what am I overlooking to get {{ bb_code($myArray.message, 'mycontent_type', $myArray) }} to render images correctly? This is driving me mad, and I figure it is something simple I'm overlooking.

Thanks for any assistance,
Lawrence
 
Last edited:
Do you have an embed_metadata column on your entity? And when you set the message, are you using the preparer service to set the value appropriately (by way of calling $preparer->getEmbedMetaData() after preparing the message)?
 
@Jeremy P thank-you for taking the time to reply.

Do you have an embed_metadata column on your entity?

I do, :)

And when you set the message, are you using the preparer service to set the value appropriately (by way of calling $preparer->getEmbedMetaData() after preparing the message)?

It's done through my messageManager, when I call setMesage($message, $format = true, $checkValidity = true).

I compared the embed_metadata for my add-on to the embed_metadata of a test conversation:
My data: {"attachments":{"129":129,"130":130}}
Test conversation data: {"attachments":{"127":127,"128":128}}

For my add-on the data is rendered as View Attachment link, while the conversation renders the images as thumbnails. So, I thought the problem must be template related, however; I re-did the template code about three different ways and the results are the same. I am at a loss, and normally that means I'm overlooking something simple. It's frustrating, :unsure:
 
And you're sure the attachments are being associated with the content correctly? You mention the content_type is set correctly in the xf_attachment table, but the content_id must be set properly as well.
 
Got it to work. It was a little act of forgetfulness on my part: I forgot to have my entity implement RenderableContentInterface, :oops:.

Thanks for taking the time to help @Jeremy P, well appreciated.
 
Glad you got it sorted :) I distinctly remember running into this issue myself a long time ago but couldn't remember for the life of me what the issue was.
 
Back
Top Bottom