Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Well, looks like the form is generated in the second condition and <code>$entity-&gt;getHistory()</code> returns null. </p> <p>Edit your controller code as below</p> <pre><code>$historyValue = 'Digite o Historico aqui'; // Default history value if($appointment-&gt;getAnamnese()){ $entity = $appointment-&gt;getAnamnese(); // Checks whether the history is not empty (null or equals '' in this case) if (!empty($entity-&gt;getHistory())) { $historyValue = $entity-&gt;getHistory(); } } $form = $this-&gt;createForm(new AnamneseType(),null,array('history' =&gt; $historyValue)); </code></pre> <p>I'd highly recommend you to read the official documentation.</p> <p><a href="http://symfony.com/doc/current/book/forms.html" rel="nofollow">Symfony Forms</a></p> <hr> <p>Form data is supposed to be passed from a controller.</p> <p>Replace</p> <pre><code>$form = $this-&gt;createForm(new AnamneseType($entity-&gt;getHistory())); </code></pre> <p>With</p> <pre><code>$form = $this-&gt;createForm(new AnamneseType(), array( 'history' =&gt; null === $entity-&gt;getHistory() ? 'Digite o Historico aqui' : $entity-&gt;getHistory, )); </code></pre> <p>Remove constructor from the form class and replace</p> <pre><code>if($this-&gt;history != NULL){ $builder-&gt;add('history', 'ckeditor', array( 'data' =&gt; $this-&gt;history , 'toolbar' =&gt; $toolbar)); }else{ $builder-&gt;add('history', 'ckeditor', array( 'data' =&gt; "Digite o Historico aqui" , 'toolbar' =&gt; $toolbar)); } </code></pre> <p>With</p> <pre><code>$builder-&gt;add('history', 'ckeditor', array('toolbar' =&gt; $toolbar)); </code></pre> <p>If you are going to map the data back to the entity check <a href="http://symfony.com/doc/current/book/forms.html" rel="nofollow">Forms official documentation</a></p> <p><strong>UPD:</strong></p> <p>To pass some value to a template from the history field edit its definition like:</p> <pre><code>$builder-&gt;add('history', 'ckeditor', array( 'attr' =&gt; array( 'toolbar' =&gt; $toolbar, ), )); </code></pre> <p>You can access the <code>toolbar</code> option by:</p> <pre><code>{{ form.history.get('attr').toolbar }} </code></pre> <p>There is better solution: <a href="http://symfony.com/doc/current/cookbook/form/create_custom_field_type.html" rel="nofollow">Create Custom Form Type</a></p>
 

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