diff --git a/bundle/Form/FieldTypeHandler/EnhancedSelection.php b/bundle/Form/FieldTypeHandler/EnhancedSelection.php deleted file mode 100644 index c2eeaea..0000000 --- a/bundle/Form/FieldTypeHandler/EnhancedSelection.php +++ /dev/null @@ -1,80 +0,0 @@ -getFieldSettings(); - $isMultiple = $fieldSettings['isMultiple']; - } - - if (!$isMultiple) { - if (empty($value->identifiers)) { - return ''; - } - - return $value->identifiers[0]; - } - - return $value->identifiers; - } - - public function convertFieldValueFromForm($data): EnhancedSelectionValue - { - if ($data === null) { - return new EnhancedSelectionValue(); - } - - return new EnhancedSelectionValue(is_array($data) ? $data : [$data]); - } - - protected function buildFieldForm( - FormBuilderInterface $formBuilder, - FieldDefinition $fieldDefinition, - string $languageCode, - ?Content $content = null - ): void { - $options = $this->getDefaultFieldOptions($fieldDefinition, $languageCode, $content); - - $fieldSettings = $fieldDefinition->getFieldSettings(); - $optionsValues = $fieldSettings['options']; - - $options['multiple'] = $fieldSettings['isMultiple']; - $options['expanded'] = $fieldSettings['isExpanded']; - $options['choices'] = $this->getValues($optionsValues); - - $formBuilder->add( - $fieldDefinition->identifier, - ChoiceType::class, - $options - ); - } - - private function getValues(array $options): array - { - $values = []; - - foreach ($options as $option) { - if (!empty($option['identifier']) && !empty($option['name'])) { - $values[$option['name']] = $option['identifier']; - } - } - - return $values; - } -} diff --git a/bundle/Resources/config/field_types.yaml b/bundle/Resources/config/field_types.yaml index 3b43372..1326170 100644 --- a/bundle/Resources/config/field_types.yaml +++ b/bundle/Resources/config/field_types.yaml @@ -27,11 +27,6 @@ services: tags: - { name: ibexa.field_type.indexable, alias: sckenhancedselection } - netgen.enhanced_selection.field_type.form.fieldtype_handler: - class: Netgen\Bundle\EnhancedSelectionBundle\Form\FieldTypeHandler\EnhancedSelection - tags: - - { name: netgen.ezforms.form.fieldtype_handler, alias: sckenhancedselection } - netgen.enhanced_selection.field_type.form_mapper: class: Netgen\Bundle\EnhancedSelectionBundle\Core\FieldType\EnhancedSelection\FormMapper tags: diff --git a/composer.json b/composer.json index 72733d8..1740acc 100644 --- a/composer.json +++ b/composer.json @@ -22,13 +22,11 @@ }, "require-dev": { "phpunit/phpunit": "^9.0", - "netgen/ez-forms-bundle": "^3.0", "friendsofphp/php-cs-fixer": "^2.16" }, "minimum-stability": "dev", "prefer-stable": true, "suggest": { - "netgen/ez-forms-bundle": "Allows use of enhanced selection field type with Symfony forms", "ibexa/solr": "Allows use of EnhancedSelection search criterion with Solr search engine" }, "autoload": { diff --git a/tests/Form/FieldTypeHandler/EnhancedSelectionTest.php b/tests/Form/FieldTypeHandler/EnhancedSelectionTest.php deleted file mode 100644 index 7eb7642..0000000 --- a/tests/Form/FieldTypeHandler/EnhancedSelectionTest.php +++ /dev/null @@ -1,140 +0,0 @@ -handler = new EnhancedSelection(); - } - - public function testInstanceOfFieldTypeHandler(): void - { - self::assertInstanceOf(FieldTypeHandler::class, $this->handler); - } - - public function testConvertFieldValueToForm(): void - { - $identifiers = ['identifier1', 'identifier2']; - $selection = new EnhancedSelectionValue($identifiers); - - $converted = $this->handler->convertFieldValueToForm($selection); - - self::assertSame($identifiers, $converted); - } - - public function testConvertFieldValueToFormWithIdentifiersArrayEmpty(): void - { - $identifiers = []; - $selection = new EnhancedSelectionValue($identifiers); - $fieldDefinition = new FieldDefinition( - [ - 'fieldSettings' => [ - 'isMultiple' => false, - ], - ] - ); - - $converted = $this->handler->convertFieldValueToForm($selection, $fieldDefinition); - - self::assertSame('', $converted); - } - - public function testConvertFieldValueToFormWithFieldDefinitionMultiple(): void - { - $identifiers = ['identifier1', 'identifier2']; - $selection = new EnhancedSelectionValue($identifiers); - $fieldDefinition = new FieldDefinition( - [ - 'fieldSettings' => [ - 'isMultiple' => true, - ], - ] - ); - - $converted = $this->handler->convertFieldValueToForm($selection, $fieldDefinition); - - self::assertSame($identifiers, $converted); - } - - public function testConvertFieldValueToFormWithFieldDefinitionSingle(): void - { - $identifiers = ['identifier1', 'identifier2']; - $selection = new EnhancedSelectionValue($identifiers); - $fieldDefinition = new FieldDefinition( - [ - 'fieldSettings' => [ - 'isMultiple' => false, - ], - ] - ); - - $converted = $this->handler->convertFieldValueToForm($selection, $fieldDefinition); - - self::assertSame($identifiers[0], $converted); - } - - public function testConvertFieldValueFromForm(): void - { - $identifiers = ['identifier1', 'identifier2']; - $selection = new EnhancedSelectionValue($identifiers); - - $converted = $this->handler->convertFieldValueFromForm($identifiers); - - self::assertSame($selection->identifiers, $converted->identifiers); - } - - public function testBuildFieldCreateForm(): void - { - $formBuilder = $this->getMockBuilder(FormBuilder::class) - ->disableOriginalConstructor() - ->onlyMethods(['add']) - ->getMock(); - - $formBuilder->expects(self::once()) - ->method('add'); - - $fieldDefinition = new FieldDefinition( - [ - 'id' => 'id', - 'identifier' => 'identifier', - 'isRequired' => true, - 'descriptions' => ['fre-FR' => 'fre-FR'], - 'names' => ['fre-FR' => 'fre-FR'], - 'fieldSettings' => [ - 'options' => [ - [ - 'identifier' => 'identifier0', - 'name' => 'Identifier0', - ], - [ - 'identifier' => 'identifier1', - 'name' => 'Identifier1', - ], - ], - 'isMultiple' => true, - 'isExpanded' => true, - ], - ] - ); - - $languageCode = 'eng-GB'; - - $this->handler->buildFieldCreateForm($formBuilder, $fieldDefinition, $languageCode); - } -}