/** * @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 addDefaultValueField(FieldTypeInterface $data, $type, FormInterface $form) { if ($form->has('default_value')) { $form->remove('default_value'); } if (is_null($type) || !array_key_exists($type, $this->options)) { return; } if ($data->getType() !== $type) { $data->setDefaultValue(null); } if (isset($this->options[$type]['default_value'])) { $defaultValueField = $this->options[$type]['default_value']; $defaultOption = isset($defaultValueField['options']) ? $defaultValueField['options'] : array(); $form->add('default_value', $defaultValueField['type'], $defaultOption); } }
/** * Get $contentTypeField options from conf and complete it with $contentTypeField setted values * * @param FieldTypeInterface $contentTypeField * * @return array */ protected function getFieldOptions(FieldTypeInterface $contentTypeField) { $contentTypeOptions = $contentTypeField->getFormOptions(); $options = array(); $field = $this->fieldTypesConfiguration[$contentTypeField->getType()]; if (isset($field['options'])) { $configuratedOptions = $field['options']; foreach ($configuratedOptions as $optionName => $optionConfiguration) { $options[$optionName] = isset($contentTypeOptions[$optionName]) ? $contentTypeOptions[$optionName] : $optionConfiguration['default_value']; } } return $options; }