This plugin allows you to associate various uploads with multiple modules. Include the attachable module to allow for inline uploading in your application. You can customize by type, add custom validation, etc. Attach anything from uploads to links to other modules.

Developers

License

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

where $this->form represents the Doctrine Form for whatever class is acting as attachable. It is important to note
the plugin does not work if the passed $this->form does not carry an object already saved to the database.
For this reason, the component should not be included unless the form object exists, for example:

Also supported is the csAttachable attachments_list component, which receives an object variable and outputs
a UL of attachments and their links. This is handy for frontend development / archive reasons, and also
serves as an example for how attachments should be accessed / displayed. Use the following code to access
this component:

Integrating with the backend

After completing the steps above, you will want to override the _form.php partial in your backend module.
Copy all of the code from the same generated module in your project cache. Then, add the form code above after the tag.
At the end, your _form.php partial should look something like this:

Make sure your upload directory has proper permissions set. If you need to debug, unhide the iframe to see the errors being thrown.
Also, be sure to publish your assets ./symfony plugin:publish-assets to pull in the default attachable styles

Other available methods include

$model->addAttachment($attachment) where $attachment is an Attachment object

$model->addAttachments($attachments) where $attachments is an array or collection of Attachment objects.

$attachment->getObject(); where $attachment is the attachment object returning its related model

Other Notes

Using the included partial, Attachment objects are hashed and placed in uploads/(model)/(file) where (model) is
the model acting as Attachable. The Attachment object is then assigned the previous filename to it's [name] property.

Array accessors are not yet available for ActAsAttachable. For example, $model['Attachments'] will return an error.

To Do

Add automated mimetype validation for specified types

Allow relationships specified in schema.yml to validate for specific types