/** * {@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; }
/** * {@inheritDoc} */ public function addRewardOption(RewardOption\RewardOptionInterface $rewardOption) { if (!in_array($rewardOption->getName(), $this->_type->validRewardOptions())) { throw new \LogicException('Reward options of type `' . $rewardOption->getName() . '` cannot be set on rewards with a type of `' . $this->_type->getName() . '`'); } if (null === $this->_rewardOptions) { $this->_rewardOptions = new RewardOption\Collection(); } $this->_rewardOptions->add($rewardOption); }
/** * Loop through reward options and create fields for the form * * @param Form\FormBuilderInterface $builder * @param TypeInterface $rewardType */ private function _addRewardOptionFields(Form\FormBuilderInterface $builder, TypeInterface $rewardType) { if (count($rewardType->validRewardOptions()) <= 0) { return; } $rewardOptionsForm = $builder->create('reward_options', null, ['label' => 'ms.refer.form.reward_options.label', 'compound' => true]); $rewardOptions = $this->_rewardOptionCollectionBuilder->getCollectionFromType($rewardType); foreach ($rewardOptions as $rewardOption) { $options = ['label' => $rewardOption->getDisplayName(), 'attr' => ['data-help-key' => $rewardOption->getDescription()]]; $options = $rewardOption->getFormOptions() + $options; $rewardOptionsForm->add($rewardOption->getName(), $rewardOption->getFormType(), $options); } $builder->add($rewardOptionsForm); }