How to manage attachments through the attachment editor template?

Renegade

Well-known member
How do I add the attachment editor? Seems the following is the code to add an attachment editor and it works fine while uploading images.

However when I edit the page I am not able to see (or manage) the previously added attachments. What am I doing wrong?

Code:
        <dl class="ctrlUnit submitUnit center">
            <dt>Product image:</dt>
            <dd>
                          <xen:include template="attachment_upload_button" />
            </dd>
        </dl>

    <xen:if is="{$attachmentParams}">
        <dl class="ctrlUnit AttachedFilesUnit">
            <dt><label for="ctrl_uploader">{xen:phrase attached_files}:</label></dt>
            <dd><xen:include template="attachment_editor" /></dd>
        </dl>
    </xen:if>
 
I am not really sound with any coding so I use common sense wherever applicable, so please bear with me. :P

Now I see that even edit post template uses the same block of code as mentioned above in my first post. So the point you both have made about passing the key to the template should be applicable to the post_edit template too. But I don't see any additional parameters being passed in that block.

In which template do I have to pass these parameters?
 
I have another problem with this. All the uploaded images through this code in the add-on disappear after a day or two. Is there some parameter which expires with time?

This is a sample attachment IMG SRC -
HTML:
attachments/flight 01-JPG.12/?temp_hash=2c40411eb1f95d4ae6bf3de5bc5fe729
 
You must associate the attachments using a datawriter. Take a look at _associateAttachments() in library/XenForo/DataWriter/DiscussionMessage/Post.php
 
Are you using it for an own content type?
If yes, you need a own attachment handler and associate your attachments it in the datawriter/controller

Jeremy P means XenForo_DataWriter_DiscussionMessage and not /XenForo/DataWriter/DiscussionMessage/Post.php ;)

PHP:
    /**
    * Associates attachments with this message.
    *
    * @param string $attachmentHash
    */
    protected function _associateAttachments($attachmentHash)
    {
        $rows = $this->_db->update('xf_attachment', array(
            'content_type' => $this->getContentType(),
            'content_id' => $this->getDiscussionMessageId(),
            'temp_hash' => '',
            'unassociated' => 0
        ), 'temp_hash = ' . $this->_db->quote($attachmentHash));
        if ($rows)
        {
            // TODO: ideally, this can be consolidated with other post-save message updates (see updateIpData)
            $this->set('attach_count', $this->get('attach_count') + $rows, '', array('setAfterPreSave' => true));

            $this->_db->update($this->getDiscussionMessageTableName(), array(
                'attach_count' => $this->get('attach_count')
            ), $this->getDiscussionMessageKeyName() . ' = ' .  $this->_db->quote($this->getDiscussionMessageId()));
        }
    }

For example here my custom:
PHP:
    /**
    * save article attachments
    * @param  $attachmentHash
    * @return void
    */
    protected function _associateAttachments($attachmentHash)
    {
        $rows = $this->_db->update('xf_attachment', array(
                                                        'content_type' => Ragtek_AS_Constants::CONTENT_TYPE,
                                                        'content_id' => $this->get('article_id'),
                                                        'temp_hash' => '',
                                                        'unassociated' => 0,
                                                    ), 'temp_hash =' . $this->_db->quote($attachmentHash)
        );

        if ($rows) {
            $newAttachCount = $this->get('attach_count') + $rows;

            $this->set('attach_count', $newAttachCount, '', array('setAfterPreSave' => true));
            $this->_db->update('ragtek_article', array(
                                                      'attach_count' => $newAttachCount),
                            'article_id = ' . $this->get('article_id')
            );
        }
    }
 
Are you using it for an own content type?
If yes, you need a own attachment handler and associate it in the datawriter...

Jeremy P means XenForo_DataWriter_DiscussionMessage and not /XenForo/DataWriter/DiscussionMessage/Post.php ;)
If you mean a new content type then no. It is being used for only image files. If you mean a 3rd party add-on template then yes.
 
Top Bottom