Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Let say you have a Form of type <strong>FileType</strong> as follow:</p> <pre><code>&lt;?php namespace EventFlowAnalyser\Form; use Symfony\Component\Form\AbstractType; use Symfony\Component\Form\FormBuilderInterface; class FileType extends AbstractType { public function buildForm(FormBuilderInterface $builder, array $options) { $builder-&gt;add('name', 'text', array('label' =&gt; 'Name')); } public function getName() { return 'file'; } } </code></pre> <p>You can use it in your controller like this:</p> <pre><code>$form = $this-&gt;createForm(new FileType(), $document); </code></pre> <p>Where <strong>$document</strong> is an object containing one field (<em>name</em>). Now, if you need to add a field to the form object in another function, you can extend the <strong>FileType</strong> to add the field you need; for example if you want to edit the name field but want still to keep track of the previous state lets add an <strong>original_name</strong> field.</p> <pre><code>&lt;?php namespace EventFlowAnalyser\Form; use Symfony\Component\Form\AbstractType; use Symfony\Component\Form\FormBuilderInterface; use EventFlowAnalyser\Form\EventListener\EditFileFieldSubscriber; class FileEditType extends FileType { public function buildForm(FormBuilderInterface $builder, array $options) { parent::buildForm($builder, $options); $builder-&gt;add('original_name', 'hidden', array('mapped' =&gt; false)); } } </code></pre> <p>Now, you can use the extended form like that:</p> <pre><code>$form = $this-&gt;createForm(new FileEditType(), $document); </code></pre> <p>And modify the value of the field like that:</p> <pre><code>$form-&gt;get('original_name')-&gt;setData($document-&gt;name); </code></pre> <p>I hope this will help somenone :o)</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload