Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I did exactly the same. My <code>InternalMessage</code> entity is your <code>Notification</code>. In the form, <code>users</code> field is not mapped (<code>property_path</code> is <code>false</code>) and it's validated using a subscriber:</p> <pre class="lang-php prettyprint-override"><code>public function buildForm(FormBuilder $builder, array $options) { $builder -&gt;add('title', 'text', array( 'label' =&gt; 'Titolo *' )) -&gt;add('content', 'textarea', array( 'label' =&gt; 'Contenuto *' )) -&gt;add('priority', new PriorityType(), array( 'label' =&gt; 'Priorità *' )) -&gt;add('users', 'entity', array( 'label' =&gt; 'Destinatari *', 'class' =&gt; 'Acme\HelloBundle\Entity\User', 'property' =&gt; 'select_label', 'multiple' =&gt; true, 'expanded' =&gt; true, 'property_path' =&gt; false, )); ; $builder-&gt;addEventSubscriber(new AddUsersValidationSubscriber()); } </code></pre> <p>While in my controller, the only thing i have to do (assuming that form is valid) is to create one <code>InternalMessageFeedback</code> entity (the same as your <code>UserNotification</code>) fore each user in form model:</p> <pre class="lang-php prettyprint-override"><code>$message = new InternalMessage(); $form = $this-&gt;createForm(new InternalMessageType(), $message); // ... // The sender $message-&gt;setUser($this-&gt;getSecurityContext()-&gt;getToken()-&gt;getUser()); // Persist the inverse side $em = $this-&gt;getEntityManager(); $em-&gt;persist($message); // One feedback for each user /** @var $user \Acme\HelloBundle\Entity\User */ foreach($form-&gt;get('users')-&gt;getData() as $user) { $feedback = new InternalMessageFeedback(); // Se the message and user for current feedback $feedback-&gt;setInternalMessage($message); $feedback-&gt;setUser($user); // Persist the owning side $em-&gt;persist($feedback); // Sync the inverse side $message-&gt;addInternalMessageFeedback($feedback); } $em-&gt;flush(); </code></pre> <p>Hope this helps :)</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. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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