![]() |
|
csDoctrineActAsAttachablePlugin - 1.0.1Attach custom and preset filetypes to your modules |
|
![]() |
29
users
Sign-in
to change your status |
This plugin allows you to associate various uploads with multiple modules. |
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.
Sponsored By Centre{source} interactive agency
| Name | Status | |
|---|---|---|
|
|
lead | moc.ecruosertnec <<ta>> reffahsb |
Copyright (c) 2009 Brent Shaffer
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.
| Version | License | API | Released |
|---|---|---|---|
| 1.0.1stable | MIT license | 1.0.0stable | 05/05/2009 |
| Version | License | API | Released |
|---|---|---|---|
| 1.0.0stable | MIT license | 1.0.0stable | 25/04/2009 |
This behavior permits to attach files to Doctrine objects.
Supported filetypes are the following:
The type "other" represents the base filetype, and is not validated by mimetype.
Others can be set accordingly.
add the following code to your module's schema file:
MyModel:
actAs: [Attachable]
To use csAttachable module, add csAttachable to your settings.yml under "enabled_modules" and add the following code to your template:
<?php include_component('csAttachable', 'attachments', array('form' => $form)) ?>
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:
<?php if ($form->getObject()->getId()): ?> <?php include_component('csAttachable', 'attachments', array('form' => $form)) ?> <?php endif; ?>
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:
<?php include_component('csAttachable', 'attachments_list', array('object' => $object)) ?>
Where $object is an item acting as Attachable
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:
<?php include_stylesheets_for_form($form) ?> <?php include_javascripts_for_form($form) ?> <div class="sf_admin_form"> <?php echo form_tag_for($form, '@mymodel') ?> <?php echo $form->renderHiddenFields() ?> <?php if ($form->hasGlobalErrors()): ?> <?php echo $form->renderGlobalErrors() ?> <?php endif; ?> <?php foreach ($configuration->getFormFields($form, $form->isNew() ? 'new' : 'edit') as $fieldset => $fields): ?> <?php include_partial('mymodel/form_fieldset', array('mymodel' => $mymodel, 'form' => $form, 'fields' => $fields, 'fieldset' => $fieldset)) ?> <?php endforeach; ?> <?php include_partial('mymodel/form_actions', array('mymodel' => $mymodel, 'form' => $form, 'configuration' => $configuration, 'helper' => $helper)) ?> </form> <?php if ($form->getObject()->getId()): ?> <?php include_component('csAttachable', 'attachments', array('form' => $form)) ?> <?php endif; ?> </div>
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
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.
