/**
  * {@inheritDoc}
  */
 public function addConstraint(Constraint\ConstraintInterface $constraint)
 {
     if (!in_array($constraint->getName(), $this->_type->validConstraints())) {
         throw new \LogicException('Constraints of type `' . $constraint->getName() . '` cannot be set on rewards with a type of `' . $this->_type->getName() . '`');
     }
     if (null === $this->_constraints) {
         $this->_constraints = new Constraint\Collection();
     }
     $this->_constraints->add($constraint);
 }
 /**
  * {@inheritDoc}
  */
 public function getCollectionFromType(Type\TypeInterface $type)
 {
     $collection = $this->getCollection();
     foreach ($this->_completeCollection as $entity) {
         if (!$entity instanceof ConstraintInterface) {
             throw new \LogicException('Entity must be an instance of ConstraintInterface!');
         }
         if (in_array($entity->getName(), $type->validConstraints())) {
             $collection->add($entity);
         }
     }
     return $collection;
 }
 /**
  * Loop through reward constraints and create fields for the form
  *
  * @param Form\FormBuilderInterface $builder
  * @param TypeInterface $rewardType
  */
 private function _addConstraintFields(Form\FormBuilderInterface $builder, TypeInterface $rewardType)
 {
     if (count($rewardType->validConstraints()) <= 0) {
         return;
     }
     $constraintsForm = $builder->create('constraints', null, ['label' => 'ms.refer.form.constraints.label', 'compound' => true]);
     $constraints = $this->_constraintCollectionBuilder->getCollectionFromType($rewardType);
     foreach ($constraints as $constraint) {
         $options = ['label' => $constraint->getDisplayName(), 'attr' => ['data-help-key' => $constraint->getDescription()]];
         $options = $constraint->getFormOptions() + $options;
         $constraintsForm->add($constraint->getName(), $constraint->getFormType(), $options);
     }
     $builder->add($constraintsForm);
 }