Attachments in custom add-ons?

dmnkhhn

Active member
Hey,

Has anyone found out how the attachment system works?

An attachment requires a content_type and a content_id - from my understanding I have to create a custom content_type and the content_id refers to the unique id of the content with that custom type.

There are two tables in the database related to the content_type

xf_content_type_field has the name, field name and field value.
content_type = whatever you want, seems to be lowercase, one word only
field_name = no idea
field_value = XenForo_AttachmentHandler_Post which means Post.php in the directory XenForo/AttachmentHandler/

The tricky parts seems to be xf_content_type
content_type = same as above
addon_id = id of the add-on that uses this content type
fields = this field is a mediumblob and I have no idea what it is and what it contains


AFAIK there is no way to create a new content type without doing it in the database so I am wondering if it is even possible to use the XenForo 1 beta 1 attachment system in a custom add-on. :)



Edit:
Please change the thread title to: Attachments in custom add-ons?
 
fields = this field is a mediumblob and I have no idea what it is and what it contains
It contains serialized array of handlers as they are defined in xf_content_type_fields table (see XenForo_Model_ContentType class, rebuildContentTypeCache() method).
AFAIK there is no way to create a new content type without doing it in the database
Yes, I think you have to manually insert all needed things to the db.
I am wondering if it is even possible to use the XenForo 1 beta 1 attachment system in a custom add-on.
I can't see any problems: create new content_type, assign attachment handler to it, create attachment handler class and define methods like _canViewAttachment and then use XenForo_Model_Attachment model to get your attachments, upload them etc.
 
Oh well, not complicated at all. ;)

I just did a quick test, filled the fields in the database table and left 'fields' blank.

Then, I added this to my model
PHP:
$this->getModelFromCache('XenForo_Model_ContentType')->rebuildContentTypeCache();
and (drum roll please)... 'fields' is not empty anymore. :)

I guess the rebuilding needs to be done after the install process of an add-on created the database entries.
 
Got it working. ;)

It is a bit cobbled at the moment (I have removed all the permission stuff) but I can pick a file (any file, I am going to limit it to certain file extensions) and upload it.
Next step: Use the DataWriter to save and attach the attachment to my custom content_type

Edit:
The uploading works, I can edit a car and attach/remove images.
One important thing was missing in my DataWriter: A _postSave() method that calls the function responsible for the association of the attachment(s).
The upload still works but the attachment does not know where it belongs to.

Next step: Display the attachment on the detail page of the car.

After that: Write a small guide about the stuff I am currently doing. ;)
 
Got it working. ;)

It is a bit cobbled at the moment (I have removed all the permission stuff) but I can pick a file (any file, I am going to limit it to certain file extensions) and upload it.
Next step: Use the DataWriter to save and attach the attachment to my custom content_type

Edit:
The uploading works, I can edit a car and attach/remove images.
One important thing was missing in my DataWriter: A _postSave() method that calls the function responsible for the association of the attachment(s).
The upload still works but the attachment does not know where it belongs to.

Next step: Display the attachment on the detail page of the car.

After that: Write a small guide about the stuff I am currently doing. ;)

Hey, did you write this guide? I'm very interested about it!
 
Top Bottom