/** * @param FormEvent $event */ public function postSubmitData(FormEvent $event) { $form = $event->getForm(); $data = $event->getData(); /** @var FieldConfigModel $configModel */ $configModel = $form->getRoot()->getConfig()->getOptions()['config_model']; if (count($data)) { $em = $this->configManager->getEntityManager(); $optionValues = $oldOptions = $configModel->getOptions()->getValues(); $newOptions = []; array_walk_recursive($oldOptions, function (&$oldOption) { $oldOption = $oldOption->getId(); }); foreach ($data as $option) { if (is_array($option)) { $optionSet = new OptionSet(); $optionSet->setField($configModel); $optionSet->setData($option['id'], $option['priority'], $option['label'], (bool) $option['default']); } elseif (!$option->getId()) { $optionSet = $option; $optionSet->setField($configModel); } else { $optionSet = $option; } if ($optionSet->getLabel() != null) { $newOptions[] = $optionSet->getId(); } if (!in_array($optionSet, $optionValues) && $optionSet->getLabel() != null) { $em->persist($optionSet); } } $delOptions = array_diff($oldOptions, $newOptions); foreach ($delOptions as $key => $delOption) { $em->remove($configModel->getOptions()->getValues()[$key]); } $em->flush(); } }
public function testOptionSetData() { $this->optionSet->setData(null, 10, 'test', false); $this->checkAssertsSet($this->optionSet); }