title: Symfony Check if at least one of two fields isn't empty on form validation
body: <p>I've been turning this around in my head for quite a while now and still wasn't able to find a solution to my problem. Using Symfony 4 forms and constraints I'm unable to setup a check to say that at least one of two fields must not be empty when submitting form that contains a sub-form.</p>
  
  <p>I have a Booking entity which contains a Visitor entity which has a phoneNumber property and a email property. I'd like to be able to create a Booking which has a "visitors" CollectionType (where I'm allowed to add visitors from the BookingType form).</p>
  
  <p>My BookingType form (a bit simplified):</p>
  
  <pre class="lang-php prettyprint-override"><code>class BookingType extends AbstractType
  {
      private $router;
      private $translator;
  
      public function __construct(UrlGeneratorInterface $router, TranslatorInterface $translator)
      {
          $this-&gt;router = $router;
          $this-&gt;translator = $translator;
      }
  
      public function buildForm(FormBuilderInterface $builder, array $options)
      {
          $builder
              -&gt;add('bookableTimeSlot', EntityType::class, [
                  'label' =&gt; 'entity.booking.bookable-time-slot',
                  'class' =&gt; BookableTimeSlot::class,
                  'choice_label' =&gt; function ($bookableTimeSlot) {
                      return $bookableTimeSlot-&gt;getStartDateTime()-&gt;format('d.m.Y h\hi');
                  }
              ])
              -&gt;add('visitors', CollectionType::class, [
                  'entry_type' =&gt; VisitorType::class,
                  'label' =&gt; 'entity.booking.visitors',
                  'allow_add' =&gt; true,
                  'by_reference' =&gt; false,
                  'entry_options' =&gt; ['label' =&gt; false]
              ])
          ;
      }
  
      public function configureOptions(OptionsResolver $resolver)
      {
          $resolver-&gt;setDefaults([
              'data_class' =&gt; Booking::class,
              'user' =&gt; User::class,
          ]);
      }
  }
  </code></pre>
  
  <p>My Visitor entity (a bit simplified):</p>
  
  <pre class="lang-php prettyprint-override"><code>&lt;?php
  
  namespace App\Entity;
  
  use Doctrine\ORM\Mapping as ORM;
  use Symfony\Component\Validator\Constraints as Assert;
  use Symfony\Component\Validator\Context\ExecutionContextInterface;
  
  /**
   * @ORM\Entity(repositoryClass="App\Repository\VisitorRepository")
   */
  class Visitor
  {
      /**
       * @ORM\Id()
       * @ORM\GeneratedValue()
       * @ORM\Column(type="integer")
       */
      private $id;
  
      /**
       * @ORM\Column(type="string", length=255)
       */
      private $firstName;
  
      /**
       * @ORM\Column(type="string", length=255)
       */
      private $lastName;
  
      /**
       * @ORM\Column(type="string", length=45, nullable=true)
       */
      private $phone;
  
      /**
       * @ORM\ManyToOne(targetEntity="App\Entity\Booking", inversedBy="visitors")
       * @ORM\JoinColumn(nullable=false)
       */
      private $booking;
  
      /**
       * @ORM\Column(type="string", length=255, nullable=true)
       */
      private $email;
  
      public function getId(): ?int
      {
          return $this-&gt;id;
      }
  
      public function getFirstName(): ?string
      {
          return $this-&gt;firstName;
      }
  
      public function setFirstName(string $firstName): self
      {
          $this-&gt;firstName = $firstName;
  
          return $this;
      }
  
      public function getLastName(): ?string
      {
          return $this-&gt;lastName;
      }
  
      public function setLastName(string $lastName): self
      {
          $this-&gt;lastName = $lastName;
  
          return $this;
      }
  
      public function getPhone(): ?string
      {
          return $this-&gt;phone;
      }
  
      public function setPhone(string $phone): self
      {
          $this-&gt;phone = $phone;
  
          return $this;
      }
  
      public function getBooking(): ?Booking
      {
          return $this-&gt;booking;
      }
  
      public function setBooking(?Booking $booking): self
      {
          $this-&gt;booking = $booking;
  
          return $this;
      }
  
      public function getEmail(): ?string
      {
          return $this-&gt;email;
      }
  
      public function setEmail(?string $email): self
      {
          $this-&gt;email = $email;
  
          return $this;
      }
  }
  </code></pre>
  
  <p>And finaly my VisitorType form (a bit simplified):</p>
  
  <pre class="lang-php prettyprint-override"><code>class VisitorType extends AbstractType
  {
      public function buildForm(FormBuilderInterface $builder, array $options)
      {
          $builder
              -&gt;add('firstName', TextType::class, [
                  'label' =&gt; 'entity.visitor.first-name',
              ])
              -&gt;add('lastName', TextType::class, [
                  'label' =&gt; 'entity.visitor.last-name',
              ])
              -&gt;add('phone', TextType::class, [
                  'label' =&gt; 'entity.visitor.phone-number',
                  'required' =&gt; false,
              ])
              -&gt;add('email', TextType::class, [
                  'label' =&gt; 'entity.visitor.email',
                  'required' =&gt; false,
                  'constraints' =&gt; [
                      new Email()
                  ]
              ])
          ;
      }
  
      public function configureOptions(OptionsResolver $resolver)
      {
          $resolver-&gt;setDefaults([
              'data_class' =&gt; Visitor::class,
          ]);
      }
  }
  </code></pre>
  
  <p>I've tried to add an Expression constraint to the email and phone field which looked something like this:</p>
  
  <pre><code>new Expression([
      'expression' =&gt; 'this.getPhone() == null &amp;&amp; this.getEmail() == null'
  ])
  </code></pre>
  
  <p>Also tried to add constraint directly to the entity, but nothing seems to work correctly for me.</p>
  
  <p>Any help would be greatly appreciated.</p>
  
  <p>UPDATE
  I haven't specified this, but my problem comes from the fact that I would like to validate the VisitorType form from another form which adds the VisitorType as a CollectionType.</p>