Single File-Form

Add File-Upload in „foreign“ Entities:

A. Define the Entity-Connection

 * @ORM\OneToOne(targetEntity="tpoint\FileBundle\Entity\File", cascade={"persist"}, orphanRemoval=true)
 * @ORM\JoinColumn(name="file_id", referencedColumnName="id", nullable=false)
private $file;

B. Add Method to Entity setFile(File $file = null)

C. Add Form-Field to FormType

use tpoint\FileBundle\Form\EventListener\FileFieldSubscriber;


$builder->addEventSubscriber(new FileFieldSubscriber());

D. Add the JS-Formatting to the Template


<link rel="stylesheet" type="text/css" href="{{ asset("/lib/jasny-bootstrap/jasny-bootstrap.min.css") }}" />
<script src="{{ asset("/lib/jasny-bootstrap/jasny-bootstrap.min.js") }}" type="text/javascript"></script>
    $('#tpoint_invoicemanagementbundle_invoice_file').attr({'style':'display: none'});
        button_text: '{{ 'upload.field.button-text'|trans({}, 'tpointFileBundle') }}',
        button_change_text: '{{ 'upload.field.button-text-change'|trans({}, 'tpointFileBundle') }}',
        feedback_text: '{{ ''|trans({}, 'tpointFileBundle') }}',

The Source-Files (js+css) are not required, if you use the default-config for tpoint-standard (e.g. with grunt and minify/uglify).

E. Show the File-Link in the Form, if there is a Document

This ist checked via “required”, because the field must not be empty, when there isn’t a file uploaded

{% if form.file.vars.required == false %}
<div class="form-group">
    <div class="col-sm-offset-3 col-sm-6">
    <a class="openInvoice" target="_blank" href="{{ path('tpoint_invoicemanagement_invoice_download', {'id':, 'label': entity.file.label, 'mode': 'view' }) }}" title="{{ 'document.view'|trans}}">
        <i class="fa fa-download"></i>
        {{ entity.file.label }}
{% endif %}

Multiple-Upload Action