XF 2.2 ->with('embed')

Robert9

Well-known member
Where can I find more information about that, please?


PHP:
            $attachments = $this->finder('XF:Attachment')
                ->where([
                    'content_type' => $contentType,
                    'content_id' => $ids
                ])
                ->order('attach_date')
                ->with('embed')
                ->fetch()
                ->groupBy('content_id');


In entity/attachment i found

PHP:
        $structure->withAliases = [
            'api' => [],
            'embed' => []
        ];

but where is the translation to

left join $item.embed_metadata

?

I guess this information should be done here:

PHP:
        $structure->relations['Images2'] = [
        'entity' => 'XF:Attachment',
        'type' => self::TO_MANY,
        'conditions' => [
            ['content_type', '=', 'xf_lala_item_image2'],
            ['content_id', '=', '$item_id']
        ],
        'with' => 'Data',
        'order' => 'attach_date'

===> 'embed_field' = 'embed_metadata2' <===

        ];


For my problem i see four solutions:

1) accept that xf can handle only one field with attachments
2) find a way to tell the finder, when he should use embed = embed_metadata and when he should use embed = embed_metadata2
3) Use the one embed_metadata for two text_fields, then i have to change the function that overwrites my values from the other field and vice versa.

or 4) add a new table for just one more field with attachments

Somehow I prefer 3) but i stuck.
With 2) i have the problem that the finder will not work; maybe I need a new addAttachmentsToContent2 ...

or and that is my question: Where can I manipulate ->with('embed')
 
Some tricky, but possible:
I have
item.Images
item.Images2
embed_metadata
and the saved embed attachement_ids

When saving Images:

embed_metadata= saved embed attachement_ids - item.Images + saved embed attachement_ids

When saving Images2:

embed_metadata= saved embed attachement_ids - item.Images2 + saved embed attachement_ids


Now I have one more problem to solve:

the bbCode-function cares for all attachment_ids in embed_metadata and content_type1 = relation Images;
but not about and content_type2 and relation Images2 ...
 
PHP:
    public function getBbCodeRenderOptions($context, $type)
    {
        return [
            'entity' => $this,
            'user' => $this->User,
            'attachments' => $this->attach_count ? $this->Images : [],
            'viewAttachments' => $this->canViewProductImages()
        ];
    }

Finally found this also, but I have no idea how to merge my two array_collections

$this->Images and $this->Images2 or make a difference when calling template one where I need $this->Images and template2 where I need $this->Images2.
 
finally i have two fields both with attachments ...

Code:
    public function getBbCodeRenderOptions($context, $type)
    {

        $array = $this->Images->toArray();
        $array2 = $this->Images2->toArray();
        $array3 = $array + $array2;
        
        return [
            'entity' => $this,
            'user' => $this->User,
            'attachments' => $this->attach_count ? $array3 : [],
            'viewAttachments' => $this->canViewProductImages()
        ];
    }
 
Back
Top Bottom