/** * @param FieldTypeInterface $fieldType * * @return FacadeInterface * * @throws TransformerParameterTypeException */ public function transform($fieldType) { if (!$fieldType instanceof FieldTypeInterface) { throw new TransformerParameterTypeException(); } $facade = $this->newFacade(); $facade->fieldId = $fieldType->getFieldId(); $facade->label = $this->multiLanguagesChoiceManagerInterface->choose($fieldType->getLabels()); $facade->defaultValue = $fieldType->getDefaultValue(); $facade->searchable = $fieldType->isSearchable(); $facade->listable = $fieldType->getListable(); $facade->type = $fieldType->getType(); foreach ($fieldType->getOptions() as $option) { $value = $option->getValue(); if (!is_string($value)) { $value = \serialize($value); } $facade->addOption($option->getKey(), $value); } return $facade; }
/** * @param FieldTypeInterface $data * @param string $type * @param FormInterface $form */ protected function checkFieldType(FieldTypeInterface $data, $type, FormInterface $form) { if (is_null($type) || !array_key_exists($type, $this->options)) { return; } if (array_key_exists('options', $this->options[$type])) { $keys = array(); foreach ($this->options[$type]['options'] as $key => $option) { if (!$data->hasOption($key)) { $fieldOptionClass = $this->fieldOptionClass; /** @var FieldOptionInterface $fieldOption */ $fieldOption = new $fieldOptionClass(); $fieldOption->setKey($key); $fieldOption->setValue($option['default_value']); $data->addOption($fieldOption); } $keys[] = $key; } foreach ($data->getOptions() as $option) { if (!in_array($option->getKey(), $keys)) { $data->removeOption($option); } } } else { $data->clearOptions(); } $form->add('options', 'collection', array('type' => 'oo_field_option', 'allow_add' => false, 'allow_delete' => false, 'label' => false, 'options' => array('label' => false))); }