TickTackk
Well-known member
- Affected version
- XF 2.0
In file
xf2\src\XF\Repository\Attachment.php
method addAttachmentsToContent()
expects the the key to be always the content id. Think the fixed version could be this:
PHP:
public function addAttachmentsToContent($content, $contentType, $countKey = 'attach_count', $relationKey = 'Attachments')
{
/** @var ArrayCollection $content */
$ids = [];
/** @var \XF\Mvc\Entity\Entity $item */
foreach ($content AS $id => $item)
{
if ($item->{$countKey})
{
if ($item instanceof \XF\Mvc\Entity\Entity)
{
$ids[] = $item->getEntityId();
}
else
{
$ids[] = $id;
}
}
}
if ($ids)
{
$attachments = $this->finder('XF:Attachment')
->where([
'content_type' => $contentType,
'content_id' => $ids
])
->order('attach_date')
->fetch()
->groupBy('content_id');
foreach ($content AS &$item)
{
$contentId = $item->getEntityId();
$contentAttachments = isset($attachments[$contentId]) ? $this->em->getBasicCollection($attachments[$contentId]) : $this->em->getEmptyCollection();
if ($item instanceof \XF\Mvc\Entity\Entity)
{
$item->hydrateRelation($relationKey, $contentAttachments);
}
else
{
$item[$relationKey] = $contentAttachments->toArray();
}
}
}
return $content;
}
Last edited: