From 82983adb748cad8af7ee9fb42106a9d08e5831e7 Mon Sep 17 00:00:00 2001 From: Marijan Klaric Date: Thu, 11 Jan 2024 17:07:28 +0100 Subject: [PATCH 01/87] CED-1124 WIP --- bundle/Controller/Admin/AdminController.php | 104 +++++++++++++++- bundle/Form/Builder/FormBuilder.php | 84 +++++++++++++ .../Form/InformationCollectionUpdateType.php | 115 ++++++++++++++++++ bundle/Resources/config/controllers.yml | 4 + bundle/Resources/config/routing.yaml | 5 + bundle/Resources/config/services.yml | 10 ++ .../Custom/CheckboxFieldHandler.php | 5 + .../Custom/CountryFieldHandler.php | 1 + .../Custom/DateAndTimeFieldHandler.php | 4 + .../FieldHandler/Custom/DateFieldHandler.php | 4 + .../FieldHandler/Custom/FloatFieldHandler.php | 5 + .../Custom/IntegerFieldHandler.php | 5 + .../FieldHandler/Custom/TimeFieldHandler.php | 4 + 13 files changed, 349 insertions(+), 1 deletion(-) create mode 100644 bundle/Form/Builder/FormBuilder.php create mode 100644 bundle/Form/InformationCollectionUpdateType.php diff --git a/bundle/Controller/Admin/AdminController.php b/bundle/Controller/Admin/AdminController.php index b211c2f2..cbdae09a 100644 --- a/bundle/Controller/Admin/AdminController.php +++ b/bundle/Controller/Admin/AdminController.php @@ -7,18 +7,23 @@ use Ibexa\Bundle\Core\Controller; use Ibexa\Contracts\Core\Repository\ContentService; use Ibexa\Contracts\Core\SiteAccess\ConfigResolverInterface; +use Netgen\Bundle\InformationCollectionBundle\Form\Builder\FormBuilder; use Netgen\InformationCollection\API\Persistence\Anonymizer\Anonymizer; use Netgen\InformationCollection\API\Service\InformationCollection; use Netgen\InformationCollection\API\Value\Collection; use Netgen\InformationCollection\API\Value\Filter\CollectionFields; use Netgen\InformationCollection\API\Value\Filter\Collections; +use Netgen\InformationCollection\API\Value\Filter\CollectionId; use Netgen\InformationCollection\API\Value\Filter\ContentId; use Netgen\InformationCollection\API\Value\Filter\Contents; use Netgen\InformationCollection\API\Value\Filter\Query; use Netgen\InformationCollection\API\Value\Filter\SearchQuery; +use Netgen\InformationCollection\Core\Factory\FieldDataFactory; use Netgen\InformationCollection\Core\Pagination\InformationCollectionCollectionListAdapter; use Netgen\InformationCollection\Core\Pagination\InformationCollectionCollectionListSearchAdapter; use Netgen\InformationCollection\Core\Pagination\InformationCollectionContentsAdapter; +use Netgen\InformationCollection\Doctrine\Repository\EzInfoCollectionAttributeRepository; +use Netgen\InformationCollection\Doctrine\Repository\EzInfoCollectionRepository; use Pagerfanta\Adapter\AdapterInterface; use Pagerfanta\Pagerfanta; use Symfony\Component\HttpFoundation\RedirectResponse; @@ -36,6 +41,13 @@ class AdminController extends Controller protected Anonymizer $anonymizer; + protected FieldDataFactory $factory; + protected EzInfoCollectionRepository $infoCollectionRepository; + + protected EzInfoCollectionAttributeRepository $infoCollectionAttributeRepository; + + protected FormBuilder $builder; + private TranslatorInterface $translator; public function __construct( @@ -43,7 +55,11 @@ public function __construct( Anonymizer $anonymizer, ContentService $contentService, ConfigResolverInterface $configResolver, - TranslatorInterface $translator + TranslatorInterface $translator, + FieldDataFactory $factory, + EzInfoCollectionRepository $infoCollectionRepository, + EzInfoCollectionAttributeRepository $infoCollectionAttributeRepository, + FormBuilder $builder ) { $this->service = $service; @@ -51,6 +67,10 @@ public function __construct( $this->configResolver = $configResolver; $this->anonymizer = $anonymizer; $this->translator = $translator; + $this->factory = $factory; + $this->infoCollectionRepository = $infoCollectionRepository; + $this->infoCollectionAttributeRepository = $infoCollectionAttributeRepository; + $this->builder = $builder; } /** @@ -271,6 +291,82 @@ public function handleCollectionAction(Request $request): RedirectResponse return $this->redirectToRoute('netgen_information_collection.route.admin.view', ['collectionId' => $collectionId]); } + public function editAction(Request $request, int $collectionId) + { + $this->checkEditPermissions(); + + + $collection = $this->service->getCollection(new CollectionId($collectionId)); + + $locationService = $this->getRepository()->getLocationService(); + + + $location = $locationService->loadLocation($collection->getContent()->contentInfo->mainLocationId); + + $form = $this->builder->createUpdateFormForLocation($location, $collection)->getForm(); + + + $form->handleRequest($request); + + if ($form->isSubmitted() && $form->isValid()) { + $struct = $form->getData()->payload; + + $contentType = $form->getData()->definition; + + $ezInfo = $this->infoCollectionRepository->find($collectionId); + $ezInfo->setModified(time()); + + $this->infoCollectionRepository->save($ezInfo); + + foreach ($struct->getCollectedFields() as $fieldDefIdentifier => $value) { + if ($value === null) { + continue; + } + + $fieldDefinition = $contentType->getFieldDefinition($fieldDefIdentifier); + + $legacyValue = $this->factory->getLegacyValue($value, $fieldDefinition); + + $ezInfoAttributes = $this->infoCollectionAttributeRepository->findByCollectionIdAndFieldDefinitionIds( + $collectionId, + [$fieldDefinition->id] + ); + + if (count($ezInfoAttributes) > 0) { + $ezInfoAttribute = $ezInfoAttributes[0]; + } else { + $ezInfoAttribute = $this->infoCollectionAttributeRepository->getInstance(); + $ezInfoAttribute->setContentObjectId($collection->getContent()->id); + $ezInfoAttribute->setContentObjectAttributeId($collection->getContent()->getField($fieldDefinition->identifier)->id); + $ezInfoAttribute->setContentClassAttributeId($fieldDefinition->id); + $ezInfoAttribute->setInformationCollectionId($collection->entity->getId()); + } + + $ezInfoAttribute->setDataInt($legacyValue->getDataInt()); + $ezInfoAttribute->setDataFloat($legacyValue->getDataFloat()); + $ezInfoAttribute->setDataText($legacyValue->getDataText()); + + $this->infoCollectionAttributeRepository->save($ezInfoAttribute); + } + + return $this->redirectToRoute( + 'netgen_information_collection.route.admin.view', + [ + 'contentId' => $location->contentInfo->id, + 'collectionId' => $collection->entity->getId(), + ] + ); + } + + return $this->render("themes/app/admin/edit.html.twig", [ + 'collection' => $collection, + 'content' => $location->getContent(), + 'form' => $form->createView(), + ]); + } + + + /** * Adds a flash message with specified parameters. */ @@ -320,4 +416,10 @@ protected function checkAnonymizePermissions(): void $attribute = new Attribute('infocollector', 'anonymize'); $this->denyAccessUnlessGranted($attribute); } + + protected function checkEditPermissions(): void + { + $attribute = new Attribute('infocollector', 'edit'); + $this->denyAccessUnlessGranted($attribute); + } } diff --git a/bundle/Form/Builder/FormBuilder.php b/bundle/Form/Builder/FormBuilder.php new file mode 100644 index 00000000..2f1debf2 --- /dev/null +++ b/bundle/Form/Builder/FormBuilder.php @@ -0,0 +1,84 @@ +contentInfo; + $contentType = $this->contentTypeService->loadContentType($contentInfo->contentTypeId); + $struct = new InformationCollectionStruct(); + + foreach ($collection->getAttributes() as $attribute) { + + $fieldValue = $this->fromLegacyValue( + new FieldValue( + $attribute->getField()->id, + $attribute->getValue()->getDataText(), + $attribute->getValue()->getDataInt(), + $attribute->getValue()->getDataFloat() + + ), + $attribute->getField() + ); + + if ($fieldValue !== null) { + $struct->setCollectedFieldValue($attribute->getField()->getFieldDefinitionIdentifier(), $fieldValue); + } + } + + $data = new DataWrapper($struct, $contentType, $location); + + $useCsrf = $this->configResolver->getParameter('information_collection.form.use_csrf', 'netgen'); + dd('here'); + return $this->formFactory + ->createNamedBuilder( + $contentType->identifier . '_' . $location->id, + InformationCollectionUpdateType::class, + $data, + [ + 'collection' => $collection, + 'csrf_protection' => $useCsrf, + ] + ); + } + + private function fromLegacyValue(FieldValue $legacyData, Field $field) + { + $handler = $this->registry->handle($field->value); + + if (!$handler instanceof CustomLegacyFieldHandlerInterface) { + return null; + } + + return $handler->fromLegacyValue($legacyData); + } +} diff --git a/bundle/Form/InformationCollectionUpdateType.php b/bundle/Form/InformationCollectionUpdateType.php new file mode 100644 index 00000000..610cc268 --- /dev/null +++ b/bundle/Form/InformationCollectionUpdateType.php @@ -0,0 +1,115 @@ +languages = []; + } + + public function getName(): string + { + return $this->getBlockPrefix(); + } + + /** + * Returns the prefix of the template block name for this type. + * + */ + public function getBlockPrefix(): string + { + return 'ezforms_information_collection_update'; + } + + public function configureOptions(OptionsResolver $resolver): void + { + $resolver->setRequired('collection'); + $resolver->setAllowedTypes('collection', Collection::class); + } + + /** + * {@inheritdoc} + */ + public function buildForm(FormBuilderInterface $builder, array $options) + { + /** @var DataWrapper $dataWrapper */ + $dataWrapper = $options['data']; + $collection = $options['collection']; + + if (!$dataWrapper instanceof DataWrapper) { + throw new RuntimeException( + 'Data must be an instance of Netgen\\EzFormsBundle\\Form\\DataWrapper' + ); + } + + /** @var InformationCollectionStruct $payload */ + $payload = $dataWrapper->payload; + + if (!$payload instanceof InformationCollectionStruct) { + throw new RuntimeException( + 'Data payload must be an instance of Netgen\\Bundle\\EzFormsBundle\\Form\\Payload\\InformationCollectionStruct' + ); + } + + /** @var ContentType $contentType */ + $contentType = $dataWrapper->definition; + + if (!$contentType instanceof ContentType) { + throw new RuntimeException( + 'Data definition must be an instance of eZ\\Publish\\API\\Repository\\Values\\ContentType\\ContentType' + ); + } + + $builder->setDataMapper($this->dataMapper); + + foreach ($contentType->getFieldDefinitions() as $fieldDefinition) { + if ($fieldDefinition->fieldTypeIdentifier === 'ezuser') { + continue; + } + + if (!$fieldDefinition->isInfoCollector) { + continue; + } + + $handler = $this->fieldTypeHandlerRegistry->get($fieldDefinition->fieldTypeIdentifier); + + $handler->buildFieldUpdateForm($builder, $fieldDefinition, $dataWrapper->target->content, $this->getLanguageCode($contentType)); + } + } + + /** + * If ContentType language code is in languages array then use it, else use first available one. + * + * @param ContentType $contentType + * + * @return string + */ + protected function getLanguageCode(ContentType $contentType) + { + $contentTypeLanguages = array_keys($contentType->getNames()); + + foreach ($this->languages as $languageCode) { + if (in_array($languageCode, $contentTypeLanguages, true)) { + return $languageCode; + } + } + + return $contentType->mainLanguageCode; + } +} + + diff --git a/bundle/Resources/config/controllers.yml b/bundle/Resources/config/controllers.yml index bb45643b..073bd430 100644 --- a/bundle/Resources/config/controllers.yml +++ b/bundle/Resources/config/controllers.yml @@ -17,6 +17,10 @@ services: - "@ibexa.api.service.content" - "@ibexa.config.resolver" - "@translator" + - '@netgen_information_collection.factory.field_data' + - '@netgen_information_collection.repository.ez_info_collection' + - '@netgen_information_collection.repository.ez_info_collection_attribute' + - '@netgen_information_collection.form.builder' netgen_information_collection.controller.export.export: class: Netgen\Bundle\InformationCollectionBundle\Controller\Admin\Export\Export diff --git a/bundle/Resources/config/routing.yaml b/bundle/Resources/config/routing.yaml index b3a25989..9f138568 100644 --- a/bundle/Resources/config/routing.yaml +++ b/bundle/Resources/config/routing.yaml @@ -18,6 +18,11 @@ netgen_information_collection.route.admin.view: defaults: { _controller: netgen_information_collection.controller.admin:viewAction } methods: [GET] +netgen_information_collection.route.admin.edit: + path: /netgen/informationcollection/edit/{collectionId} + defaults: { _controller: netgen_information_collection.controller.admin:editAction } + methods: [ GET, POST ] + netgen_information_collection.route.admin.handle_contents: path: /netgen/informationcollection/handle/contents defaults: { _controller: netgen_information_collection.controller.admin:handleContentsAction } diff --git a/bundle/Resources/config/services.yml b/bundle/Resources/config/services.yml index d051d4b0..d3b486a5 100644 --- a/bundle/Resources/config/services.yml +++ b/bundle/Resources/config/services.yml @@ -32,3 +32,13 @@ services: - '@request_stack' - '@netgen_information_collection.captcha.service' - '@translator' + + netgen_information_collection.form.builder: + class: Netgen\Bundle\InformationCollectionBundle\Form\Builder\FormBuilder + arguments: + - '@form.factory' + - '@ibexa.api.service.content_type' + - '@router' + - '@ibexa.config.resolver' + - '@netgen_information_collection.factory.field_data' + - '@netgen_information_collection.field_handler.registry' diff --git a/lib/Core/Persistence/FieldHandler/Custom/CheckboxFieldHandler.php b/lib/Core/Persistence/FieldHandler/Custom/CheckboxFieldHandler.php index 8d416daf..a7ef2a22 100644 --- a/lib/Core/Persistence/FieldHandler/Custom/CheckboxFieldHandler.php +++ b/lib/Core/Persistence/FieldHandler/Custom/CheckboxFieldHandler.php @@ -29,4 +29,9 @@ public function getLegacyValue(Value $value, FieldDefinition $fieldDefinition): { return FieldValue::withIntValue($fieldDefinition->id, (int) $value->bool); } + + public function fromLegacyValue(FieldValue $legacyData) + { + return new CheckboxValue($legacyData->getDataInt() === 1); + } } diff --git a/lib/Core/Persistence/FieldHandler/Custom/CountryFieldHandler.php b/lib/Core/Persistence/FieldHandler/Custom/CountryFieldHandler.php index 65f5ce8f..523c2cd9 100644 --- a/lib/Core/Persistence/FieldHandler/Custom/CountryFieldHandler.php +++ b/lib/Core/Persistence/FieldHandler/Custom/CountryFieldHandler.php @@ -5,6 +5,7 @@ namespace Netgen\InformationCollection\Core\Persistence\FieldHandler\Custom; use Ibexa\Contracts\Core\Repository\Values\ContentType\FieldDefinition; +use Ibexa\Core\FieldType\Checkbox\Value as CheckboxValue; use Ibexa\Core\FieldType\Country\Value as CountryValue; use Ibexa\Core\FieldType\Value; use Netgen\InformationCollection\API\FieldHandler\CustomLegacyFieldHandlerInterface; diff --git a/lib/Core/Persistence/FieldHandler/Custom/DateAndTimeFieldHandler.php b/lib/Core/Persistence/FieldHandler/Custom/DateAndTimeFieldHandler.php index 07db39f4..f519d5c5 100644 --- a/lib/Core/Persistence/FieldHandler/Custom/DateAndTimeFieldHandler.php +++ b/lib/Core/Persistence/FieldHandler/Custom/DateAndTimeFieldHandler.php @@ -31,4 +31,8 @@ public function getLegacyValue(Value $value, FieldDefinition $fieldDefinition): { return FieldValue::withIntValue($fieldDefinition->id, $value->value->getTimestamp()); } + + public function fromLegacyValue(FieldDefinition $legacyData) + { + } } diff --git a/lib/Core/Persistence/FieldHandler/Custom/DateFieldHandler.php b/lib/Core/Persistence/FieldHandler/Custom/DateFieldHandler.php index be53e50b..1c9fcccc 100644 --- a/lib/Core/Persistence/FieldHandler/Custom/DateFieldHandler.php +++ b/lib/Core/Persistence/FieldHandler/Custom/DateFieldHandler.php @@ -29,4 +29,8 @@ public function getLegacyValue(Value $value, FieldDefinition $fieldDefinition): { return FieldValue::withIntValue($fieldDefinition->id, $value->date->getTimestamp()); } + + public function fromLegacyValue(FieldDefinition $legacyData) + { + } } diff --git a/lib/Core/Persistence/FieldHandler/Custom/FloatFieldHandler.php b/lib/Core/Persistence/FieldHandler/Custom/FloatFieldHandler.php index 566910aa..6d2f49e4 100644 --- a/lib/Core/Persistence/FieldHandler/Custom/FloatFieldHandler.php +++ b/lib/Core/Persistence/FieldHandler/Custom/FloatFieldHandler.php @@ -29,4 +29,9 @@ public function getLegacyValue(Value $value, FieldDefinition $fieldDefinition): { return FieldValue::withFloatValue($fieldDefinition->id, $value->value); } + + public function fromLegacyValue(FieldValue $legacyData): FloatValue + { + return new FloatValue($legacyData->getDataFloat()); + } } diff --git a/lib/Core/Persistence/FieldHandler/Custom/IntegerFieldHandler.php b/lib/Core/Persistence/FieldHandler/Custom/IntegerFieldHandler.php index 7f3e5631..74695f7c 100644 --- a/lib/Core/Persistence/FieldHandler/Custom/IntegerFieldHandler.php +++ b/lib/Core/Persistence/FieldHandler/Custom/IntegerFieldHandler.php @@ -29,4 +29,9 @@ public function getLegacyValue(Value $value, FieldDefinition $fieldDefinition): { return FieldValue::withIntValue($fieldDefinition->id, $value->value); } + + public function fromLegacyValue(FieldValue $legacyData): IntegerValue + { + return new IntegerValue($legacyData->getDataInt()); + } } diff --git a/lib/Core/Persistence/FieldHandler/Custom/TimeFieldHandler.php b/lib/Core/Persistence/FieldHandler/Custom/TimeFieldHandler.php index 22e97a27..35521dde 100644 --- a/lib/Core/Persistence/FieldHandler/Custom/TimeFieldHandler.php +++ b/lib/Core/Persistence/FieldHandler/Custom/TimeFieldHandler.php @@ -29,4 +29,8 @@ public function getLegacyValue(Value $value, FieldDefinition $fieldDefinition): { return FieldValue::withIntValue($fieldDefinition->id, (int) $value->time); } + + public function fromLegacyValue(FieldValue $legacyData) + { + } } From a325b2c71a312fc3737ad30c5fe3788cc841d289 Mon Sep 17 00:00:00 2001 From: Marijan Klaric Date: Thu, 11 Jan 2024 18:27:32 +0100 Subject: [PATCH 02/87] CED-1124 WIP --- bundle/Controller/Admin/AdminController.php | 4 ++-- bundle/Form/Builder/FormBuilder.php | 2 +- .../Form/InformationCollectionUpdateType.php | 14 ++++++++++--- bundle/Resources/views/admin/edit.html.twig | 17 +++++++++++++++ bundle/Resources/views/admin/form.html.twig | 21 +++++++++++++++++++ lib/Resources/config/admin.yml | 9 ++++++++ 6 files changed, 61 insertions(+), 6 deletions(-) create mode 100644 bundle/Resources/views/admin/edit.html.twig create mode 100644 bundle/Resources/views/admin/form.html.twig diff --git a/bundle/Controller/Admin/AdminController.php b/bundle/Controller/Admin/AdminController.php index cbdae09a..29ca39c0 100644 --- a/bundle/Controller/Admin/AdminController.php +++ b/bundle/Controller/Admin/AdminController.php @@ -293,7 +293,7 @@ public function handleCollectionAction(Request $request): RedirectResponse public function editAction(Request $request, int $collectionId) { - $this->checkEditPermissions(); + //$this->checkEditPermissions(); $collection = $this->service->getCollection(new CollectionId($collectionId)); @@ -358,7 +358,7 @@ public function editAction(Request $request, int $collectionId) ); } - return $this->render("themes/app/admin/edit.html.twig", [ + return $this->render("@NetgenInformationCollection/admin/edit.html.twig", [ 'collection' => $collection, 'content' => $location->getContent(), 'form' => $form->createView(), diff --git a/bundle/Form/Builder/FormBuilder.php b/bundle/Form/Builder/FormBuilder.php index 2f1debf2..254b215b 100644 --- a/bundle/Form/Builder/FormBuilder.php +++ b/bundle/Form/Builder/FormBuilder.php @@ -58,7 +58,7 @@ public function createUpdateFormForLocation(Location $location, Collection $coll $data = new DataWrapper($struct, $contentType, $location); $useCsrf = $this->configResolver->getParameter('information_collection.form.use_csrf', 'netgen'); - dd('here'); + return $this->formFactory ->createNamedBuilder( $contentType->identifier . '_' . $location->id, diff --git a/bundle/Form/InformationCollectionUpdateType.php b/bundle/Form/InformationCollectionUpdateType.php index 610cc268..38ef8bb5 100644 --- a/bundle/Form/InformationCollectionUpdateType.php +++ b/bundle/Form/InformationCollectionUpdateType.php @@ -18,7 +18,11 @@ class InformationCollectionUpdateType extends AbstractContentType public function setLanguages($languages) { - $this->languages = []; + $this->languages = ["ng-GB" , + "cro-HR", + "slo-SI", + "ser-SR" , + "mkd-MK"]; } public function getName(): string @@ -101,8 +105,12 @@ public function buildForm(FormBuilderInterface $builder, array $options) protected function getLanguageCode(ContentType $contentType) { $contentTypeLanguages = array_keys($contentType->getNames()); - - foreach ($this->languages as $languageCode) { + $languages = ["ng-GB" , + "cro-HR", + "slo-SI", + "ser-SR" , + "mkd-MK"]; + foreach ($languages as $languageCode) { if (in_array($languageCode, $contentTypeLanguages, true)) { return $languageCode; } diff --git a/bundle/Resources/views/admin/edit.html.twig b/bundle/Resources/views/admin/edit.html.twig new file mode 100644 index 00000000..ca000540 --- /dev/null +++ b/bundle/Resources/views/admin/edit.html.twig @@ -0,0 +1,17 @@ +{% extends netgen_information_collection_admin.pageLayoutTemplate %} + +{% trans_default_domain 'netgen_information_collection_admin' %} + +{% form_theme form 'themes/app/admin/form.html.twig' %} + +{% block content %} {% dump(form) %} + {{ form_start(form, {attr: {novalidate: 'novalidate'}}) }} + {% for child in form.children %} + {{ form_row(child) }} + {% endfor %} + + {{ form_rest(form) }} + + + {{ form_end(form) }} +{% endblock %} diff --git a/bundle/Resources/views/admin/form.html.twig b/bundle/Resources/views/admin/form.html.twig new file mode 100644 index 00000000..114f2f5f --- /dev/null +++ b/bundle/Resources/views/admin/form.html.twig @@ -0,0 +1,21 @@ +{%- block form_row -%} +
+ {%- if 'checkbox' in block_prefixes or 'radio' in block_prefixes -%} + {{- form_widget(form) -}} + {{- form_label(form) -}} + {{- form_errors(form) -}} + {%- else -%} + {{- form_label(form) -}} + {{- form_widget(form) -}} + {{- form_errors(form) -}} + {%- endif -%} +
+{%- endblock form_row -%} + +{%- block birthday_row -%} +
+ {{- form_label(form) -}} + {{- form_widget(form) -}} + {{- form_errors(form) -}} +
+{%- endblock birthday_row -%} diff --git a/lib/Resources/config/admin.yml b/lib/Resources/config/admin.yml index 05388ff4..9784a465 100644 --- a/lib/Resources/config/admin.yml +++ b/lib/Resources/config/admin.yml @@ -58,3 +58,12 @@ services: - "@netgen_information_collection.core.export.registry" tags: - { name: form.type } + + netgen_information_collection.form.type.information_collection_update: + class: Netgen\Bundle\InformationCollectionBundle\Form\InformationCollectionUpdateType + # public: false + arguments: + - "@netgen.ibexa_forms.form.fieldtype_handler_registry" + - "@netgen.ibexa_forms.form.data_mapper.info_collection" + tags: + - { name: form.type, alias: ibexaforms_information_collection_update } From 10783200dba41472d2ce544b8396b299971422f1 Mon Sep 17 00:00:00 2001 From: Marijan Klaric Date: Fri, 12 Jan 2024 16:35:54 +0100 Subject: [PATCH 03/87] CED-1124 enable information collection editing --- bundle/Controller/Admin/AdminController.php | 5 +- bundle/Form/Builder/FormBuilder.php | 9 +- .../InformationCollectionUpdateMapper.php | 83 +++++++++++++++++++ .../Form/InformationCollectionUpdateType.php | 6 +- bundle/Resources/config/services.yml | 1 + .../Custom/BirthdayFieldHandler.php | 44 ++++++++++ .../Custom/EmailAddressFieldHandler.php | 41 +++++++++ .../Custom/EnhancedSelectionFieldHandler.php | 50 +++++++++++ .../Custom/StringFieldHandler.php | 41 +++++++++ .../EzInfoCollectionAttributeRepository.php | 4 +- lib/Resources/config/admin.yml | 8 +- lib/Resources/config/legacy_handlers.yml | 15 ++++ 12 files changed, 293 insertions(+), 14 deletions(-) create mode 100644 bundle/Form/DataMapper/InformationCollectionUpdateMapper.php create mode 100644 lib/Core/Persistence/FieldHandler/Custom/BirthdayFieldHandler.php create mode 100644 lib/Core/Persistence/FieldHandler/Custom/EmailAddressFieldHandler.php create mode 100644 lib/Core/Persistence/FieldHandler/Custom/EnhancedSelectionFieldHandler.php create mode 100644 lib/Core/Persistence/FieldHandler/Custom/StringFieldHandler.php diff --git a/bundle/Controller/Admin/AdminController.php b/bundle/Controller/Admin/AdminController.php index 29ca39c0..ebaa68db 100644 --- a/bundle/Controller/Admin/AdminController.php +++ b/bundle/Controller/Admin/AdminController.php @@ -305,7 +305,6 @@ public function editAction(Request $request, int $collectionId) $form = $this->builder->createUpdateFormForLocation($location, $collection)->getForm(); - $form->handleRequest($request); if ($form->isSubmitted() && $form->isValid()) { @@ -339,7 +338,7 @@ public function editAction(Request $request, int $collectionId) $ezInfoAttribute->setContentObjectId($collection->getContent()->id); $ezInfoAttribute->setContentObjectAttributeId($collection->getContent()->getField($fieldDefinition->identifier)->id); $ezInfoAttribute->setContentClassAttributeId($fieldDefinition->id); - $ezInfoAttribute->setInformationCollectionId($collection->entity->getId()); + $ezInfoAttribute->setInformationCollectionId($collection->getId()); } $ezInfoAttribute->setDataInt($legacyValue->getDataInt()); @@ -353,7 +352,7 @@ public function editAction(Request $request, int $collectionId) 'netgen_information_collection.route.admin.view', [ 'contentId' => $location->contentInfo->id, - 'collectionId' => $collection->entity->getId(), + 'collectionId' => $collection->getId(), ] ); } diff --git a/bundle/Form/Builder/FormBuilder.php b/bundle/Form/Builder/FormBuilder.php index 254b215b..20f18ad4 100644 --- a/bundle/Form/Builder/FormBuilder.php +++ b/bundle/Form/Builder/FormBuilder.php @@ -2,10 +2,10 @@ namespace Netgen\Bundle\InformationCollectionBundle\Form\Builder; -use Ibexa\Contracts\Core\Repository\Values\Content\Field; use Ibexa\Contracts\Core\Repository\Values\Content\Location; use Ibexa\Contracts\Core\SiteAccess\ConfigResolverInterface; use Ibexa\Core\Repository\SiteAccessAware\ContentTypeService; +use Ibexa\Core\Repository\Values\ContentType\FieldDefinition; use Netgen\Bundle\IbexaFormsBundle\Form\DataWrapper; use Netgen\Bundle\IbexaFormsBundle\Form\Payload\InformationCollectionStruct; use Netgen\Bundle\InformationCollectionBundle\Form\InformationCollectionUpdateType; @@ -47,7 +47,7 @@ public function createUpdateFormForLocation(Location $location, Collection $coll $attribute->getValue()->getDataFloat() ), - $attribute->getField() + $attribute->getFieldDefinition() ); if ($fieldValue !== null) { @@ -71,10 +71,9 @@ public function createUpdateFormForLocation(Location $location, Collection $coll ); } - private function fromLegacyValue(FieldValue $legacyData, Field $field) + private function fromLegacyValue(FieldValue $legacyData, FieldDefinition $field) { - $handler = $this->registry->handle($field->value); - + $handler = $this->registry->handle($field->defaultValue); if (!$handler instanceof CustomLegacyFieldHandlerInterface) { return null; } diff --git a/bundle/Form/DataMapper/InformationCollectionUpdateMapper.php b/bundle/Form/DataMapper/InformationCollectionUpdateMapper.php new file mode 100644 index 00000000..5a0f5772 --- /dev/null +++ b/bundle/Form/DataMapper/InformationCollectionUpdateMapper.php @@ -0,0 +1,83 @@ +definition; + + $fieldDefinitionIdentifier = (string)$propertyPath; + $fieldDefinition = $contentType->getFieldDefinition($fieldDefinitionIdentifier); + + if (null === $fieldDefinition) { + throw new RuntimeException( + "Data definition does not contain expected FieldDefinition '{$fieldDefinitionIdentifier}'" + ); + } + + $fieldTypeIdentifier = $fieldDefinition->fieldTypeIdentifier; + + $handler = $this->fieldTypeHandlerRegistry->get($fieldTypeIdentifier); + + + $struct = $data->payload; + + $collectedFieldValue = $struct->getCollectedFieldValue($fieldDefinitionIdentifier); + if ($collectedFieldValue === null) { + return; + } + + $form->setData( + $handler->convertFieldValueToForm( + $struct->getCollectedFieldValue($fieldDefinitionIdentifier), + $fieldDefinition + ) + ); + } + + protected function mapFromForm( + FormInterface $form, + DataWrapper $data, + PropertyPathInterface $propertyPath + ): void + { + /** @var InformationCollectionStruct $payload */ + $payload = $data->payload; + /** @var ContentType $contentType */ + $contentType = $data->definition; + + $fieldDefinitionIdentifier = (string)$propertyPath; + $fieldDefinition = $contentType->getFieldDefinition($fieldDefinitionIdentifier); + + if (null === $fieldDefinition) { + throw new RuntimeException( + "Data definition does not contain expected FieldDefinition '{$fieldDefinitionIdentifier}'" + ); + } + + $fieldTypeIdentifier = $fieldDefinition->fieldTypeIdentifier; + $handler = $this->fieldTypeHandlerRegistry->get($fieldTypeIdentifier); + + $payload->setCollectedFieldValue( + $fieldDefinitionIdentifier, + $handler->convertFieldValueFromForm($form->getData()) + ); + } +} diff --git a/bundle/Form/InformationCollectionUpdateType.php b/bundle/Form/InformationCollectionUpdateType.php index 38ef8bb5..cd467fe0 100644 --- a/bundle/Form/InformationCollectionUpdateType.php +++ b/bundle/Form/InformationCollectionUpdateType.php @@ -18,7 +18,7 @@ class InformationCollectionUpdateType extends AbstractContentType public function setLanguages($languages) { - $this->languages = ["ng-GB" , + $this->languages = ["ng-GB", "cro-HR", "slo-SI", "ser-SR" , @@ -53,7 +53,7 @@ public function buildForm(FormBuilderInterface $builder, array $options) /** @var DataWrapper $dataWrapper */ $dataWrapper = $options['data']; $collection = $options['collection']; - + if (!$dataWrapper instanceof DataWrapper) { throw new RuntimeException( 'Data must be an instance of Netgen\\EzFormsBundle\\Form\\DataWrapper' @@ -105,7 +105,7 @@ public function buildForm(FormBuilderInterface $builder, array $options) protected function getLanguageCode(ContentType $contentType) { $contentTypeLanguages = array_keys($contentType->getNames()); - $languages = ["ng-GB" , + $languages = ["ng-GB", "cro-HR", "slo-SI", "ser-SR" , diff --git a/bundle/Resources/config/services.yml b/bundle/Resources/config/services.yml index d3b486a5..211b9ec8 100644 --- a/bundle/Resources/config/services.yml +++ b/bundle/Resources/config/services.yml @@ -42,3 +42,4 @@ services: - '@ibexa.config.resolver' - '@netgen_information_collection.factory.field_data' - '@netgen_information_collection.field_handler.registry' + diff --git a/lib/Core/Persistence/FieldHandler/Custom/BirthdayFieldHandler.php b/lib/Core/Persistence/FieldHandler/Custom/BirthdayFieldHandler.php new file mode 100644 index 00000000..050c3685 --- /dev/null +++ b/lib/Core/Persistence/FieldHandler/Custom/BirthdayFieldHandler.php @@ -0,0 +1,44 @@ +id, (string) $value, 0, 0); + } + + /** + * @inheritDoc + */ + public function fromLegacyValue(FieldValue $legacyData) + { + return new BirthdayValue($legacyData->getDataText()); + } +} diff --git a/lib/Core/Persistence/FieldHandler/Custom/EmailAddressFieldHandler.php b/lib/Core/Persistence/FieldHandler/Custom/EmailAddressFieldHandler.php new file mode 100644 index 00000000..33820818 --- /dev/null +++ b/lib/Core/Persistence/FieldHandler/Custom/EmailAddressFieldHandler.php @@ -0,0 +1,41 @@ +id, $value->email, 0, 0); + } + + public function fromLegacyValue(FieldValue $legacyData) + { + return new EmailAddressValue($legacyData->getDataText()); + } +} diff --git a/lib/Core/Persistence/FieldHandler/Custom/EnhancedSelectionFieldHandler.php b/lib/Core/Persistence/FieldHandler/Custom/EnhancedSelectionFieldHandler.php new file mode 100644 index 00000000..342a91d8 --- /dev/null +++ b/lib/Core/Persistence/FieldHandler/Custom/EnhancedSelectionFieldHandler.php @@ -0,0 +1,50 @@ +identifiers[0])) { + $identifier = $value->identifiers[0]; + } + + return new FieldValue($fieldDefinition->id, 0, 0, $identifier); + } + + /** + * @inheritDoc + */ + public function fromLegacyValue(FieldValue $legacyData) + { + return new EnhancedSelectionValue([$legacyData->getDataText()]); + } + +} diff --git a/lib/Core/Persistence/FieldHandler/Custom/StringFieldHandler.php b/lib/Core/Persistence/FieldHandler/Custom/StringFieldHandler.php new file mode 100644 index 00000000..6d5c4886 --- /dev/null +++ b/lib/Core/Persistence/FieldHandler/Custom/StringFieldHandler.php @@ -0,0 +1,41 @@ +id, $value->text, 0, 0); + } + + public function fromLegacyValue(FieldValue $legacyData) + { + return new TextLineValue($legacyData->getDataText()); + } +} diff --git a/lib/Doctrine/Repository/EzInfoCollectionAttributeRepository.php b/lib/Doctrine/Repository/EzInfoCollectionAttributeRepository.php index f4069e79..521aaa42 100644 --- a/lib/Doctrine/Repository/EzInfoCollectionAttributeRepository.php +++ b/lib/Doctrine/Repository/EzInfoCollectionAttributeRepository.php @@ -90,8 +90,8 @@ public function findByCollectionIdAndFieldDefinitionIds(int $collectionId, array $qb = $this->createQueryBuilder('eica'); return $qb->select('eica') - ->where('eica.informationCollectionId = :collection-id') - ->setParameter('collection-id', $collectionId) + ->where('eica.informationCollectionId = :collectionId') + ->setParameter('collectionId', $collectionId) ->andWhere($qb->expr()->in('eica.contentClassAttributeId', ':fields')) ->setParameter('fields', $fieldDefinitionIds) ->getQuery() diff --git a/lib/Resources/config/admin.yml b/lib/Resources/config/admin.yml index 9784a465..5f927143 100644 --- a/lib/Resources/config/admin.yml +++ b/lib/Resources/config/admin.yml @@ -59,11 +59,17 @@ services: tags: - { name: form.type } + netgen_information_collection.form.data_mapper.info_collection_update: + class: Netgen\Bundle\InformationCollectionBundle\Form\DataMapper\InformationCollectionUpdateMapper + public: false + arguments: + - "@netgen.ibexa_forms.form.fieldtype_handler_registry" + netgen_information_collection.form.type.information_collection_update: class: Netgen\Bundle\InformationCollectionBundle\Form\InformationCollectionUpdateType # public: false arguments: - "@netgen.ibexa_forms.form.fieldtype_handler_registry" - - "@netgen.ibexa_forms.form.data_mapper.info_collection" + - "@netgen_information_collection.form.data_mapper.info_collection_update" tags: - { name: form.type, alias: ibexaforms_information_collection_update } diff --git a/lib/Resources/config/legacy_handlers.yml b/lib/Resources/config/legacy_handlers.yml index 019f4f40..a454e35d 100644 --- a/lib/Resources/config/legacy_handlers.yml +++ b/lib/Resources/config/legacy_handlers.yml @@ -28,3 +28,18 @@ services: class: Netgen\InformationCollection\Core\Persistence\FieldHandler\Custom\DateFieldHandler tags: - { name: netgen_information_collection.field_handler.custom } + + netgen_information_collection.field_handler.string: + class: Netgen\InformationCollection\Core\Persistence\FieldHandler\Custom\StringFieldHandler + tags: + - { name: netgen_information_collection.field_handler.custom } + + netgen_information_collection.field_handler.birthday: + class: Netgen\InformationCollection\Core\Persistence\FieldHandler\Custom\BirthdayFieldHandler + tags: + - { name: netgen_information_collection.field_handler.custom } + + netgen_information_collection.field_handler.email_address: + class: Netgen\InformationCollection\Core\Persistence\FieldHandler\Custom\EmailAddressFieldHandler + tags: + - { name: netgen_information_collection.field_handler.custom } From 0feeea35917c95d045f42f580a969a8f6cb74835 Mon Sep 17 00:00:00 2001 From: Marijan Klaric Date: Fri, 12 Jan 2024 17:01:15 +0100 Subject: [PATCH 04/87] CED-1124 use form theme from bundle --- bundle/Resources/views/admin/edit.html.twig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bundle/Resources/views/admin/edit.html.twig b/bundle/Resources/views/admin/edit.html.twig index ca000540..99871ca3 100644 --- a/bundle/Resources/views/admin/edit.html.twig +++ b/bundle/Resources/views/admin/edit.html.twig @@ -2,7 +2,7 @@ {% trans_default_domain 'netgen_information_collection_admin' %} -{% form_theme form 'themes/app/admin/form.html.twig' %} +{% form_theme form '@NetgenInformationCollection/admin/form.html.twig' %} {% block content %} {% dump(form) %} {{ form_start(form, {attr: {novalidate: 'novalidate'}}) }} From 9837590692ae6e3fed3c962658d7a95ab96d321a Mon Sep 17 00:00:00 2001 From: Marijan Klaric Date: Fri, 12 Jan 2024 17:02:29 +0100 Subject: [PATCH 05/87] CED-1124 add configuration for EnhancedSelectionFieldHandler and fix getLegacyValue method --- .../FieldHandler/Custom/EnhancedSelectionFieldHandler.php | 2 +- lib/Resources/config/legacy_handlers.yml | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/Core/Persistence/FieldHandler/Custom/EnhancedSelectionFieldHandler.php b/lib/Core/Persistence/FieldHandler/Custom/EnhancedSelectionFieldHandler.php index 342a91d8..11f2b1eb 100644 --- a/lib/Core/Persistence/FieldHandler/Custom/EnhancedSelectionFieldHandler.php +++ b/lib/Core/Persistence/FieldHandler/Custom/EnhancedSelectionFieldHandler.php @@ -36,7 +36,7 @@ public function getLegacyValue(Value $value, FieldDefinition $fieldDefinition): $identifier = $value->identifiers[0]; } - return new FieldValue($fieldDefinition->id, 0, 0, $identifier); + return new FieldValue($fieldDefinition->id, $identifier, 0, 0); } /** diff --git a/lib/Resources/config/legacy_handlers.yml b/lib/Resources/config/legacy_handlers.yml index a454e35d..0342b1db 100644 --- a/lib/Resources/config/legacy_handlers.yml +++ b/lib/Resources/config/legacy_handlers.yml @@ -43,3 +43,8 @@ services: class: Netgen\InformationCollection\Core\Persistence\FieldHandler\Custom\EmailAddressFieldHandler tags: - { name: netgen_information_collection.field_handler.custom } + + netgen_information_collection.field_handler.enhanced_selection: + class: Netgen\InformationCollection\Core\Persistence\FieldHandler\Custom\EnhancedSelectionFieldHandler + tags: + - { name: netgen_information_collection.field_handler.custom } From b5712901e12ee8f1179e9a4e853731b93bd87224 Mon Sep 17 00:00:00 2001 From: Marijan Klaric Date: Fri, 12 Jan 2024 17:06:39 +0100 Subject: [PATCH 06/87] CED-1124 remove dump from form.html.twig --- bundle/Resources/views/admin/edit.html.twig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bundle/Resources/views/admin/edit.html.twig b/bundle/Resources/views/admin/edit.html.twig index 99871ca3..60f1527f 100644 --- a/bundle/Resources/views/admin/edit.html.twig +++ b/bundle/Resources/views/admin/edit.html.twig @@ -4,7 +4,7 @@ {% form_theme form '@NetgenInformationCollection/admin/form.html.twig' %} -{% block content %} {% dump(form) %} +{% block content %} {{ form_start(form, {attr: {novalidate: 'novalidate'}}) }} {% for child in form.children %} {{ form_row(child) }} From 8ae1fc80eae6619073aeaabc03a3977cdd1141d7 Mon Sep 17 00:00:00 2001 From: Vjeran Vlahovic Date: Fri, 12 Jan 2024 18:58:39 +0100 Subject: [PATCH 07/87] CED-1124 Add minimal styling for ic edit form and translations for edit/save buttons --- .../Resources/public/admin/css/ic_forms.css | 81 +++++++++++++++++++ ...netgen_information_collection_admin.en.yml | 3 + .../views/admin/stylesheets.html.twig | 1 + bundle/Resources/views/admin/view.html.twig | 4 + 4 files changed, 89 insertions(+) create mode 100644 bundle/Resources/public/admin/css/ic_forms.css diff --git a/bundle/Resources/public/admin/css/ic_forms.css b/bundle/Resources/public/admin/css/ic_forms.css new file mode 100644 index 00000000..c2cc8839 --- /dev/null +++ b/bundle/Resources/public/admin/css/ic_forms.css @@ -0,0 +1,81 @@ + .ic-content { + margin-bottom: 2em; + } + .ic-content .row-input { + margin-bottom: 1em; + } + .ic-content label { + display: block; + font-weight: normal; + font-size: 14px; + margin: 0; + } + .ic-content input[type=text], + .ic-content input[type=number], + .ic-content input[type=url], + .ic-content input[type=email], + .ic-content textarea, + .ic-content select { + display: block; + margin: 0 0 1em; + border-radius: 2px; + width: 40%; + padding: 0 0.75em; + font-size: 14px; + height: 44px; + border: 1px solid #b3b3b3; + background: #fff; + } + .ic-content input[type=text]::placeholder, + .ic-content input[type=number]::placeholder, + .ic-content input[type=url]::placeholder, + .ic-content input[type=email]::placeholder, + .ic-content textarea::placeholder, + .ic-content select::placeholder { + color: #b3b3b3; + } + .ic-content input[type=text][disabled], + .ic-content input[type=number][disabled], + .ic-content input[type=url][disabled], + .ic-content input[type=email][disabled], + .ic-content textarea[disabled], + .ic-content select[disabled] { + color: #999999; + border-color: #cccccc; + cursor: not-allowed; + } + .ic-content select[multiple] { + background-image: none; + height: auto; + padding: 0.25em 0; + } + .ic-content select[multiple] option { + padding: 0.25em 0.5em; + } + .ic-content textarea { + height: auto; + min-height: 120px; + padding-top: 0.375em; + resize: vertical; + } + .ic-content .file-input-group .filename { + margin-left: 1em; + font-size: 0.875em; + } + .ic-content .birthday div { + display: flex; + } + .ic-content .birthday div select { + width: 13%; + margin-right: 7px; + } + .ic-content .error-input ul { + margin-left: 0; + } + .ic-content .error-input ul li { + list-style-type: none; + color: red; + } + .ic-content form div { + padding: 8px 0; + } \ No newline at end of file diff --git a/bundle/Resources/translations/netgen_information_collection_admin.en.yml b/bundle/Resources/translations/netgen_information_collection_admin.en.yml index aa20034e..fbe33836 100644 --- a/bundle/Resources/translations/netgen_information_collection_admin.en.yml +++ b/bundle/Resources/translations/netgen_information_collection_admin.en.yml @@ -58,3 +58,6 @@ netgen_information_collection_admin_export_no_formatters: 'No formatters found' netgen_information_collection_admin_collected_information: 'Collected information (%count%)' netgen_information_collection_admin_missing_location: 'Content does not have a valid location.' + +netgen_information_collection_admin_collection_edit: 'Edit' +netgen_information_collection_admin_collection_save: 'Save' diff --git a/bundle/Resources/views/admin/stylesheets.html.twig b/bundle/Resources/views/admin/stylesheets.html.twig index 4b98fa53..c3dacce6 100644 --- a/bundle/Resources/views/admin/stylesheets.html.twig +++ b/bundle/Resources/views/admin/stylesheets.html.twig @@ -1 +1,2 @@ + diff --git a/bundle/Resources/views/admin/view.html.twig b/bundle/Resources/views/admin/view.html.twig index 54cf4a85..ad942734 100644 --- a/bundle/Resources/views/admin/view.html.twig +++ b/bundle/Resources/views/admin/view.html.twig @@ -16,6 +16,10 @@
+ + {{ 'netgen_information_collection_admin_collection_edit'|trans }} + + From 577d9e8834e1cdd0a9529eb388f197c137d338f0 Mon Sep 17 00:00:00 2001 From: Marijan Klaric Date: Mon, 15 Jan 2024 08:13:39 +0100 Subject: [PATCH 08/87] CED-1124 check edit permissions --- bundle/Controller/Admin/AdminController.php | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/bundle/Controller/Admin/AdminController.php b/bundle/Controller/Admin/AdminController.php index ebaa68db..e7b0100e 100644 --- a/bundle/Controller/Admin/AdminController.php +++ b/bundle/Controller/Admin/AdminController.php @@ -293,14 +293,12 @@ public function handleCollectionAction(Request $request): RedirectResponse public function editAction(Request $request, int $collectionId) { - //$this->checkEditPermissions(); - + $this->checkEditPermissions(); $collection = $this->service->getCollection(new CollectionId($collectionId)); $locationService = $this->getRepository()->getLocationService(); - $location = $locationService->loadLocation($collection->getContent()->contentInfo->mainLocationId); $form = $this->builder->createUpdateFormForLocation($location, $collection)->getForm(); From 3f85b70522073cfd805b71afa5e5986126b9556f Mon Sep 17 00:00:00 2001 From: Marijan Klaric Date: Mon, 15 Jan 2024 08:15:41 +0100 Subject: [PATCH 09/87] CED-1124 add return type in createUpdateFormForLocation method --- bundle/Form/Builder/FormBuilder.php | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/bundle/Form/Builder/FormBuilder.php b/bundle/Form/Builder/FormBuilder.php index 20f18ad4..214ab723 100644 --- a/bundle/Form/Builder/FormBuilder.php +++ b/bundle/Form/Builder/FormBuilder.php @@ -14,10 +14,10 @@ use Netgen\InformationCollection\API\Value\Legacy\FieldValue; use Netgen\InformationCollection\Core\Factory\FieldDataFactory; use Netgen\InformationCollection\Core\Persistence\FieldHandler\FieldHandlerRegistry; +use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\Form\FormFactoryInterface; use Symfony\Component\Routing\RouterInterface; - class FormBuilder { public function __construct( @@ -27,11 +27,10 @@ public function __construct( protected readonly ConfigResolverInterface $configResolver, protected readonly FieldDataFactory $legacyFactory, protected readonly FieldHandlerRegistry $registry - ) - { + ) { } - public function createUpdateFormForLocation(Location $location, Collection $collection) + public function createUpdateFormForLocation(Location $location, Collection $collection): FormBuilderInterface { $contentInfo = $location->contentInfo; $contentType = $this->contentTypeService->loadContentType($contentInfo->contentTypeId); From f9cf7a1eecd5c703422dd404228a0e35113de735 Mon Sep 17 00:00:00 2001 From: Marijan Klaric Date: Mon, 15 Jan 2024 08:17:40 +0100 Subject: [PATCH 10/87] CED-1124 remove uneccessary comments --- bundle/Form/DataMapper/InformationCollectionUpdateMapper.php | 5 ----- 1 file changed, 5 deletions(-) diff --git a/bundle/Form/DataMapper/InformationCollectionUpdateMapper.php b/bundle/Form/DataMapper/InformationCollectionUpdateMapper.php index 5a0f5772..5dfc6d66 100644 --- a/bundle/Form/DataMapper/InformationCollectionUpdateMapper.php +++ b/bundle/Form/DataMapper/InformationCollectionUpdateMapper.php @@ -13,14 +13,12 @@ class InformationCollectionUpdateMapper extends DataMapper { - protected function mapToForm( FormInterface $form, DataWrapper $data, PropertyPathInterface $propertyPath ): void { - /** @var ContentType $contentType */ $contentType = $data->definition; $fieldDefinitionIdentifier = (string)$propertyPath; @@ -36,7 +34,6 @@ protected function mapToForm( $handler = $this->fieldTypeHandlerRegistry->get($fieldTypeIdentifier); - $struct = $data->payload; $collectedFieldValue = $struct->getCollectedFieldValue($fieldDefinitionIdentifier); @@ -58,9 +55,7 @@ protected function mapFromForm( PropertyPathInterface $propertyPath ): void { - /** @var InformationCollectionStruct $payload */ $payload = $data->payload; - /** @var ContentType $contentType */ $contentType = $data->definition; $fieldDefinitionIdentifier = (string)$propertyPath; From 5ddfd75a8bad4fd9aa800a1f6a63a2c20b73bdc7 Mon Sep 17 00:00:00 2001 From: Marijan Klaric Date: Mon, 15 Jan 2024 09:12:46 +0100 Subject: [PATCH 11/87] CED-1124 set languages with config resolver --- .../Form/InformationCollectionUpdateType.php | 35 ++++++++++--------- lib/Resources/config/admin.yml | 1 + 2 files changed, 20 insertions(+), 16 deletions(-) diff --git a/bundle/Form/InformationCollectionUpdateType.php b/bundle/Form/InformationCollectionUpdateType.php index cd467fe0..dab4ee1c 100644 --- a/bundle/Form/InformationCollectionUpdateType.php +++ b/bundle/Form/InformationCollectionUpdateType.php @@ -3,26 +3,32 @@ namespace Netgen\Bundle\InformationCollectionBundle\Form; use eZ\Publish\API\Repository\Values\ContentType\ContentType; +use Ibexa\Contracts\Core\SiteAccess\ConfigResolverInterface; use Netgen\Bundle\IbexaFormsBundle\Form\DataWrapper; +use Netgen\Bundle\IbexaFormsBundle\Form\FieldTypeHandlerRegistry; use Netgen\Bundle\IbexaFormsBundle\Form\Payload\InformationCollectionStruct; use Netgen\Bundle\IbexaFormsBundle\Form\Type\AbstractContentType; use Netgen\InformationCollection\API\Value\Collection; use RuntimeException; +use Symfony\Component\Form\DataMapperInterface; use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\OptionsResolver\OptionsResolver; class InformationCollectionUpdateType extends AbstractContentType { + protected FieldTypeHandlerRegistry $fieldTypeHandlerRegistry; - protected array $languages; + protected DataMapperInterface $dataMapper; - public function setLanguages($languages) - { - $this->languages = ["ng-GB", - "cro-HR", - "slo-SI", - "ser-SR" , - "mkd-MK"]; + protected ConfigResolverInterface $configResolver; + + public function __construct( + FieldTypeHandlerRegistry $fieldTypeHandlerRegistry, + DataMapperInterface $dataMapper, + ConfigResolverInterface $configResolver + ) { + parent::__construct($fieldTypeHandlerRegistry, $dataMapper); + $this->configResolver = $configResolver; } public function getName(): string @@ -48,12 +54,12 @@ public function configureOptions(OptionsResolver $resolver): void /** * {@inheritdoc} */ - public function buildForm(FormBuilderInterface $builder, array $options) + public function buildForm(FormBuilderInterface $builder, array $options): void { /** @var DataWrapper $dataWrapper */ $dataWrapper = $options['data']; $collection = $options['collection']; - + if (!$dataWrapper instanceof DataWrapper) { throw new RuntimeException( 'Data must be an instance of Netgen\\EzFormsBundle\\Form\\DataWrapper' @@ -102,14 +108,11 @@ public function buildForm(FormBuilderInterface $builder, array $options) * * @return string */ - protected function getLanguageCode(ContentType $contentType) + protected function getLanguageCode(ContentType $contentType): string { $contentTypeLanguages = array_keys($contentType->getNames()); - $languages = ["ng-GB", - "cro-HR", - "slo-SI", - "ser-SR" , - "mkd-MK"]; + $languages = $this->configResolver->getParameter('languages'); + foreach ($languages as $languageCode) { if (in_array($languageCode, $contentTypeLanguages, true)) { return $languageCode; diff --git a/lib/Resources/config/admin.yml b/lib/Resources/config/admin.yml index 5f927143..5b94b19b 100644 --- a/lib/Resources/config/admin.yml +++ b/lib/Resources/config/admin.yml @@ -71,5 +71,6 @@ services: arguments: - "@netgen.ibexa_forms.form.fieldtype_handler_registry" - "@netgen_information_collection.form.data_mapper.info_collection_update" + - "@ibexa.config.resolver" tags: - { name: form.type, alias: ibexaforms_information_collection_update } From 11c12af1e91a51eb4678dba5499a403633766a84 Mon Sep 17 00:00:00 2001 From: Marijan Klaric Date: Thu, 18 Jan 2024 12:01:19 +0100 Subject: [PATCH 12/87] CED-1124 add edit link on collection list --- bundle/Resources/views/admin/collection_list.html.twig | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/bundle/Resources/views/admin/collection_list.html.twig b/bundle/Resources/views/admin/collection_list.html.twig index d550aeae..8be80c82 100644 --- a/bundle/Resources/views/admin/collection_list.html.twig +++ b/bundle/Resources/views/admin/collection_list.html.twig @@ -56,6 +56,7 @@ {{ 'netgen_information_collection_admin_collection_created'|trans }} {{ 'netgen_information_collection_admin_collection_modified'|trans }} {{ 'netgen_information_collection_admin_collection_collection_id'|trans }} + @@ -81,6 +82,11 @@ {{ collection_id }} + + + {{ 'netgen_information_collection_admin_collection_edit'|trans }} + + {% endfor %} From 39638eaa95ac25db497ecdcde0a9608ee1160a40 Mon Sep 17 00:00:00 2001 From: Borna Matijanic Date: Tue, 23 Jan 2024 18:47:47 +0100 Subject: [PATCH 13/87] CS Fixes --- bundle/Controller/Admin/AdminController.php | 62 +++++++++---------- bundle/Form/Builder/FormBuilder.php | 14 ++--- .../Form/InformationCollectionUpdateType.php | 12 ++-- .../Custom/BirthdayFieldHandler.php | 16 ++--- .../Custom/CountryFieldHandler.php | 2 +- .../Custom/EmailAddressFieldHandler.php | 14 +++-- .../Custom/EnhancedSelectionFieldHandler.php | 17 ++--- .../Custom/StringFieldHandler.php | 14 +++-- .../EzInfoCollectionAttributeRepository.php | 1 + 9 files changed, 79 insertions(+), 73 deletions(-) diff --git a/bundle/Controller/Admin/AdminController.php b/bundle/Controller/Admin/AdminController.php index e7b0100e..ca927de5 100644 --- a/bundle/Controller/Admin/AdminController.php +++ b/bundle/Controller/Admin/AdminController.php @@ -1,19 +1,21 @@ service = $service; $this->contentService = $contentService; $this->configResolver = $configResolver; @@ -74,7 +79,7 @@ public function __construct( } /** - * Displays overview page + * Displays overview page. */ public function overviewAction(Request $request): Response { @@ -83,27 +88,27 @@ public function overviewAction(Request $request): Response $adapter = new InformationCollectionContentsAdapter($this->service, Query::countQuery()); $pager = $this->getPager($adapter, (int) $request->query->get('page')); - return $this->render("@NetgenInformationCollection/admin/overview.html.twig", ['objects' => $pager]); + return $this->render('@NetgenInformationCollection/admin/overview.html.twig', ['objects' => $pager]); } /** - * Displays list of collection for selected Content + * Displays list of collection for selected Content. */ public function collectionListAction(Request $request, Content $content): Response { $this->checkReadPermissions(); $adapter = new InformationCollectionCollectionListAdapter($this->service, ContentId::withContentId($content->id)); - $pager = $this->getPager($adapter, (int)$request->query->get('page')); + $pager = $this->getPager($adapter, (int) $request->query->get('page')); - return $this->render("@NetgenInformationCollection/admin/collection_list.html.twig", [ + return $this->render('@NetgenInformationCollection/admin/collection_list.html.twig', [ 'objects' => $pager, 'content' => $content, ]); } /** - * Handles collection search + * Handles collection search. */ public function searchAction(Request $request, Content $content): Response { @@ -112,9 +117,10 @@ public function searchAction(Request $request, Content $content): Response $query = SearchQuery::withContentAndSearchText($content->id, $request->query->get('searchText')); $adapter = new InformationCollectionCollectionListSearchAdapter($this->service, $query); - $pager = $this->getPager($adapter, (int)$request->query->get('page')); + $pager = $this->getPager($adapter, (int) $request->query->get('page')); - return $this->render("@NetgenInformationCollection/admin/collection_list.html.twig", + return $this->render( + '@NetgenInformationCollection/admin/collection_list.html.twig', [ 'objects' => $pager, 'content' => $content, @@ -123,20 +129,20 @@ public function searchAction(Request $request, Content $content): Response } /** - * Displays individual collection details + * Displays individual collection details. */ public function viewAction(Collection $collection): Response { $this->checkReadPermissions(); - return $this->render("@NetgenInformationCollection/admin/view.html.twig", [ + return $this->render('@NetgenInformationCollection/admin/view.html.twig', [ 'collection' => $collection, 'content' => $collection->getContent(), ]); } /** - * Handles actions performed on overview page + * Handles actions performed on overview page. */ public function handleContentsAction(Request $request): RedirectResponse { @@ -152,7 +158,6 @@ public function handleContentsAction(Request $request): RedirectResponse } if ($request->request->has('DeleteCollectionByContentAction')) { - $this->checkDeletePermissions(); $query = new Contents($contents); @@ -170,7 +175,7 @@ public function handleContentsAction(Request $request): RedirectResponse } /** - * Handles actions performed on collection list page + * Handles actions performed on collection list page. */ public function handleCollectionListAction(Request $request): RedirectResponse { @@ -187,7 +192,6 @@ public function handleCollectionListAction(Request $request): RedirectResponse } if ($request->request->has('DeleteCollectionAction')) { - $this->checkDeletePermissions(); $query = new Collections($contentId, $collections); @@ -200,7 +204,6 @@ public function handleCollectionListAction(Request $request): RedirectResponse } if ($request->request->has('AnonymizeCollectionAction')) { - $this->checkAnonymizePermissions(); foreach ($collections as $collection) { @@ -218,7 +221,7 @@ public function handleCollectionListAction(Request $request): RedirectResponse } /** - * Handles action on collection details page + * Handles action on collection details page. */ public function handleCollectionAction(Request $request): RedirectResponse { @@ -239,7 +242,6 @@ public function handleCollectionAction(Request $request): RedirectResponse } if ($request->request->has('DeleteFieldAction')) { - $this->checkDeletePermissions(); $query = new CollectionFields($contentId, $collectionId, $fields); @@ -252,7 +254,6 @@ public function handleCollectionAction(Request $request): RedirectResponse } if ($request->request->has('AnonymizeFieldAction')) { - $this->checkAnonymizePermissions(); $this->anonymizer->anonymizeCollection($collectionId, $fields); @@ -263,25 +264,22 @@ public function handleCollectionAction(Request $request): RedirectResponse } if ($request->request->has('DeleteCollectionAction')) { - $this->checkDeletePermissions(); $query = new Collections($contentId, [$collectionId]); $this->service->deleteCollections($query); - $this->addFlashMessage("success", "collection_removed"); + $this->addFlashMessage('success', 'collection_removed'); return $this->redirectToRoute('netgen_information_collection.route.admin.collection_list', ['contentId' => $contentId]); - } if ($request->request->has('AnonymizeCollectionAction')) { - $this->checkAnonymizePermissions(); $this->anonymizer->anonymizeCollection($collectionId); - $this->addFlashMessage("success", "collection_anonymized"); + $this->addFlashMessage('success', 'collection_anonymized'); return $this->redirectToRoute('netgen_information_collection.route.admin.view', ['collectionId' => $collectionId]); } @@ -355,19 +353,17 @@ public function editAction(Request $request, int $collectionId) ); } - return $this->render("@NetgenInformationCollection/admin/edit.html.twig", [ + return $this->render('@NetgenInformationCollection/admin/edit.html.twig', [ 'collection' => $collection, 'content' => $location->getContent(), 'form' => $form->createView(), ]); } - - /** * Adds a flash message with specified parameters. */ - protected function addFlashMessage(string $messageType, string $message, int $count = 1, array $parameters = array()): void + protected function addFlashMessage(string $messageType, string $message, int $count = 1, array $parameters = []): void { $parameters = array_merge($parameters, ['count' => $count]); @@ -382,7 +378,7 @@ protected function addFlashMessage(string $messageType, string $message, int $co } /** - * Returns configured instance of Pagerfanta + * Returns configured instance of Pagerfanta. */ protected function getPager(AdapterInterface $adapter, int $currentPage): Pagerfanta { diff --git a/bundle/Form/Builder/FormBuilder.php b/bundle/Form/Builder/FormBuilder.php index 214ab723..a63f1f46 100644 --- a/bundle/Form/Builder/FormBuilder.php +++ b/bundle/Form/Builder/FormBuilder.php @@ -1,5 +1,7 @@ getAttributes() as $attribute) { - $fieldValue = $this->fromLegacyValue( new FieldValue( $attribute->getField()->id, $attribute->getValue()->getDataText(), $attribute->getValue()->getDataInt(), $attribute->getValue()->getDataFloat() - ), $attribute->getFieldDefinition() ); diff --git a/bundle/Form/InformationCollectionUpdateType.php b/bundle/Form/InformationCollectionUpdateType.php index dab4ee1c..b3599735 100644 --- a/bundle/Form/InformationCollectionUpdateType.php +++ b/bundle/Form/InformationCollectionUpdateType.php @@ -1,5 +1,7 @@ configResolver = $configResolver; @@ -38,7 +43,6 @@ public function getName(): string /** * Returns the prefix of the template block name for this type. - * */ public function getBlockPrefix(): string { @@ -122,5 +126,3 @@ protected function getLanguageCode(ContentType $contentType): string return $contentType->mainLanguageCode; } } - - diff --git a/lib/Core/Persistence/FieldHandler/Custom/BirthdayFieldHandler.php b/lib/Core/Persistence/FieldHandler/Custom/BirthdayFieldHandler.php index 050c3685..d7a812ab 100644 --- a/lib/Core/Persistence/FieldHandler/Custom/BirthdayFieldHandler.php +++ b/lib/Core/Persistence/FieldHandler/Custom/BirthdayFieldHandler.php @@ -1,17 +1,19 @@ getDataText()]); } - } diff --git a/lib/Core/Persistence/FieldHandler/Custom/StringFieldHandler.php b/lib/Core/Persistence/FieldHandler/Custom/StringFieldHandler.php index 6d5c4886..cab98601 100644 --- a/lib/Core/Persistence/FieldHandler/Custom/StringFieldHandler.php +++ b/lib/Core/Persistence/FieldHandler/Custom/StringFieldHandler.php @@ -1,17 +1,19 @@ Date: Wed, 21 Feb 2024 15:19:56 +0100 Subject: [PATCH 14/87] CED-1124 add ibexa-forms-bundle package to composer.json --- composer.json | 1 + 1 file changed, 1 insertion(+) diff --git a/composer.json b/composer.json index 78681af4..44e0d89b 100644 --- a/composer.json +++ b/composer.json @@ -29,6 +29,7 @@ "ibexa/admin-ui": "^4.0", "ibexa/content-forms": "^4.0", "ibexa/core": "^4.0", + "netgen/ibexa-forms-bundle": "^4.0", "symfony/swiftmailer-bundle": "^3.4", "twig/twig": "^3.0", "google/recaptcha": "^1.2", From 2dedd9f9aa7466f8cacc848465c008a3a7294f69 Mon Sep 17 00:00:00 2001 From: Marijan Klaric Date: Wed, 21 Feb 2024 15:20:45 +0100 Subject: [PATCH 15/87] CED-1124 refactor fromLegacyValue method --- bundle/Form/Builder/FormBuilder.php | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/bundle/Form/Builder/FormBuilder.php b/bundle/Form/Builder/FormBuilder.php index a63f1f46..5a37137b 100644 --- a/bundle/Form/Builder/FormBuilder.php +++ b/bundle/Form/Builder/FormBuilder.php @@ -7,11 +7,11 @@ use Ibexa\Contracts\Core\Repository\Values\Content\Location; use Ibexa\Contracts\Core\SiteAccess\ConfigResolverInterface; use Ibexa\Core\Repository\SiteAccessAware\ContentTypeService; -use Ibexa\Core\Repository\Values\ContentType\FieldDefinition; use Netgen\Bundle\IbexaFormsBundle\Form\DataWrapper; use Netgen\Bundle\IbexaFormsBundle\Form\Payload\InformationCollectionStruct; use Netgen\Bundle\InformationCollectionBundle\Form\InformationCollectionUpdateType; use Netgen\InformationCollection\API\FieldHandler\CustomLegacyFieldHandlerInterface; +use Netgen\InformationCollection\API\Value\Attribute; use Netgen\InformationCollection\API\Value\Collection; use Netgen\InformationCollection\API\Value\Legacy\FieldValue; use Netgen\InformationCollection\Core\Factory\FieldDataFactory; @@ -39,15 +39,7 @@ public function createUpdateFormForLocation(Location $location, Collection $coll $struct = new InformationCollectionStruct(); foreach ($collection->getAttributes() as $attribute) { - $fieldValue = $this->fromLegacyValue( - new FieldValue( - $attribute->getField()->id, - $attribute->getValue()->getDataText(), - $attribute->getValue()->getDataInt(), - $attribute->getValue()->getDataFloat() - ), - $attribute->getFieldDefinition() - ); + $fieldValue = $this->fromLegacyValue($attribute); if ($fieldValue !== null) { $struct->setCollectedFieldValue($attribute->getField()->getFieldDefinitionIdentifier(), $fieldValue); @@ -70,9 +62,16 @@ public function createUpdateFormForLocation(Location $location, Collection $coll ); } - private function fromLegacyValue(FieldValue $legacyData, FieldDefinition $field) + private function fromLegacyValue(Attribute $attribute) { - $handler = $this->registry->handle($field->defaultValue); + $legacyData = new FieldValue( + $attribute->getField()->id, + $attribute->getValue()->getDataText(), + $attribute->getValue()->getDataInt(), + $attribute->getValue()->getDataFloat() + ); + + $handler = $this->registry->handle($attribute->getFieldDefinition()->defaultValue); if (!$handler instanceof CustomLegacyFieldHandlerInterface) { return null; } From d44fc88072e4d2fddfa24b789d946b2a2dbaaef0 Mon Sep 17 00:00:00 2001 From: Marijan Klaric Date: Wed, 21 Feb 2024 15:21:34 +0100 Subject: [PATCH 16/87] CED-1124 add fromLegacyValue method to interface --- .../CustomLegacyFieldHandlerInterface.php | 4 +++- .../FieldHandler/Custom/CountryFieldHandler.php | 14 ++++++++++++++ .../Custom/DateAndTimeFieldHandler.php | 2 +- .../FieldHandler/Custom/DateFieldHandler.php | 2 +- 4 files changed, 19 insertions(+), 3 deletions(-) diff --git a/lib/API/FieldHandler/CustomLegacyFieldHandlerInterface.php b/lib/API/FieldHandler/CustomLegacyFieldHandlerInterface.php index 5db99768..581fa3ec 100644 --- a/lib/API/FieldHandler/CustomLegacyFieldHandlerInterface.php +++ b/lib/API/FieldHandler/CustomLegacyFieldHandlerInterface.php @@ -15,4 +15,6 @@ interface CustomLegacyFieldHandlerInterface extends CustomFieldHandlerInterface * in legacy information collection database structure. */ public function getLegacyValue(Value $value, FieldDefinition $fieldDefinition): FieldValue; -} + + public function fromLegacyValue(FieldValue $legacyData); +} \ No newline at end of file diff --git a/lib/Core/Persistence/FieldHandler/Custom/CountryFieldHandler.php b/lib/Core/Persistence/FieldHandler/Custom/CountryFieldHandler.php index 37e59adc..c9f27388 100644 --- a/lib/Core/Persistence/FieldHandler/Custom/CountryFieldHandler.php +++ b/lib/Core/Persistence/FieldHandler/Custom/CountryFieldHandler.php @@ -6,6 +6,7 @@ use Ibexa\Contracts\Core\Repository\Values\ContentType\FieldDefinition; use Ibexa\Core\FieldType\Country\Value as CountryValue; +use Ibexa\Core\FieldType\Country\Type as CountryType; use Ibexa\Core\FieldType\Value; use Netgen\InformationCollection\API\FieldHandler\CustomLegacyFieldHandlerInterface; use Netgen\InformationCollection\API\Value\Legacy\FieldValue; @@ -19,6 +20,14 @@ */ final class CountryFieldHandler implements CustomLegacyFieldHandlerInterface { + + private CountryType $countryType; + + public function __construct(CountryType $countryType) + { + $this->countryType = $countryType; + } + public function supports(Value $value): bool { return $value instanceof CountryValue; @@ -36,4 +45,9 @@ public function getLegacyValue(Value $value, FieldDefinition $fieldDefinition): { return FieldValue::withStringValue($fieldDefinition->id, implode(', ', array_column($value->countries, 'Alpha2'))); } + + public function fromLegacyValue(FieldValue $legacyData) + { + return $this->countryType->fromHash(explode(', ', $legacyData->getDataText())); + } } diff --git a/lib/Core/Persistence/FieldHandler/Custom/DateAndTimeFieldHandler.php b/lib/Core/Persistence/FieldHandler/Custom/DateAndTimeFieldHandler.php index f519d5c5..14d2b3de 100644 --- a/lib/Core/Persistence/FieldHandler/Custom/DateAndTimeFieldHandler.php +++ b/lib/Core/Persistence/FieldHandler/Custom/DateAndTimeFieldHandler.php @@ -32,7 +32,7 @@ public function getLegacyValue(Value $value, FieldDefinition $fieldDefinition): return FieldValue::withIntValue($fieldDefinition->id, $value->value->getTimestamp()); } - public function fromLegacyValue(FieldDefinition $legacyData) + public function fromLegacyValue(FieldValue $legacyData) { } } diff --git a/lib/Core/Persistence/FieldHandler/Custom/DateFieldHandler.php b/lib/Core/Persistence/FieldHandler/Custom/DateFieldHandler.php index 1c9fcccc..60427976 100644 --- a/lib/Core/Persistence/FieldHandler/Custom/DateFieldHandler.php +++ b/lib/Core/Persistence/FieldHandler/Custom/DateFieldHandler.php @@ -30,7 +30,7 @@ public function getLegacyValue(Value $value, FieldDefinition $fieldDefinition): return FieldValue::withIntValue($fieldDefinition->id, $value->date->getTimestamp()); } - public function fromLegacyValue(FieldDefinition $legacyData) + public function fromLegacyValue(FieldValue $legacyData) { } } From 0b4f8204ea1374a838040981c1b03de2bcbb2797 Mon Sep 17 00:00:00 2001 From: Marijan Klaric Date: Wed, 21 Feb 2024 19:12:12 +0100 Subject: [PATCH 17/87] CED-1124 rename method fromLegacyValue to fromAttribute --- bundle/Form/Builder/FormBuilder.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bundle/Form/Builder/FormBuilder.php b/bundle/Form/Builder/FormBuilder.php index 5a37137b..0eb154e3 100644 --- a/bundle/Form/Builder/FormBuilder.php +++ b/bundle/Form/Builder/FormBuilder.php @@ -39,7 +39,7 @@ public function createUpdateFormForLocation(Location $location, Collection $coll $struct = new InformationCollectionStruct(); foreach ($collection->getAttributes() as $attribute) { - $fieldValue = $this->fromLegacyValue($attribute); + $fieldValue = $this->fromAttribute($attribute); if ($fieldValue !== null) { $struct->setCollectedFieldValue($attribute->getField()->getFieldDefinitionIdentifier(), $fieldValue); @@ -62,7 +62,7 @@ public function createUpdateFormForLocation(Location $location, Collection $coll ); } - private function fromLegacyValue(Attribute $attribute) + private function fromAttribute(Attribute $attribute) { $legacyData = new FieldValue( $attribute->getField()->id, From 2d33a49b8c8b385f44dd01ded8dce441655e6aca Mon Sep 17 00:00:00 2001 From: Marijan Klaric Date: Wed, 21 Feb 2024 19:15:17 +0100 Subject: [PATCH 18/87] CED-1124 use spritf when creating name for formbuilder --- bundle/Form/Builder/FormBuilder.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bundle/Form/Builder/FormBuilder.php b/bundle/Form/Builder/FormBuilder.php index 0eb154e3..d5be8708 100644 --- a/bundle/Form/Builder/FormBuilder.php +++ b/bundle/Form/Builder/FormBuilder.php @@ -52,7 +52,7 @@ public function createUpdateFormForLocation(Location $location, Collection $coll return $this->formFactory ->createNamedBuilder( - $contentType->identifier . '_' . $location->id, + sprintf('%s_%d', $contentType->identifier, $location->id), InformationCollectionUpdateType::class, $data, [ From ac40a59c81c9ccaeb61265bcf6d52860d482a04a Mon Sep 17 00:00:00 2001 From: Marijan Klaric Date: Wed, 21 Feb 2024 19:25:45 +0100 Subject: [PATCH 19/87] CED-1124 change the php version in composer.json --- composer.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/composer.json b/composer.json index 44e0d89b..02fa3956 100644 --- a/composer.json +++ b/composer.json @@ -23,7 +23,7 @@ } ], "require": { - "php": "^7.4 || ^8.0", + "php": "^8.1", "ext-pdo": "*", "doctrine/orm": "^2.5", "ibexa/admin-ui": "^4.0", @@ -41,7 +41,7 @@ "phpunit/phpunit": "^8.2", "matthiasnoback/symfony-config-test": "~4.0", "matthiasnoback/symfony-dependency-injection-test": "~4.0", - "friendsofphp/php-cs-fixer": "^3.3" + "friendsofphp/php-cs-fixer": "^3.9" }, "autoload": { "psr-4": { From a5f8e502750bf54c7177a13b3640abe1063c98e7 Mon Sep 17 00:00:00 2001 From: Marijan Klaric Date: Wed, 21 Feb 2024 19:27:06 +0100 Subject: [PATCH 20/87] CED-1124 fix code style and remove not necessary use statements in InformationCollectionUpdateMapper.php --- .../InformationCollectionUpdateMapper.php | 23 ++++++++----------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/bundle/Form/DataMapper/InformationCollectionUpdateMapper.php b/bundle/Form/DataMapper/InformationCollectionUpdateMapper.php index 5dfc6d66..5294debf 100644 --- a/bundle/Form/DataMapper/InformationCollectionUpdateMapper.php +++ b/bundle/Form/DataMapper/InformationCollectionUpdateMapper.php @@ -1,27 +1,25 @@ definition; - $fieldDefinitionIdentifier = (string)$propertyPath; + $fieldDefinitionIdentifier = (string) $propertyPath; $fieldDefinition = $contentType->getFieldDefinition($fieldDefinitionIdentifier); if (null === $fieldDefinition) { @@ -50,15 +48,14 @@ protected function mapToForm( } protected function mapFromForm( - FormInterface $form, - DataWrapper $data, + FormInterface $form, + DataWrapper $data, PropertyPathInterface $propertyPath - ): void - { + ): void { $payload = $data->payload; $contentType = $data->definition; - $fieldDefinitionIdentifier = (string)$propertyPath; + $fieldDefinitionIdentifier = (string) $propertyPath; $fieldDefinition = $contentType->getFieldDefinition($fieldDefinitionIdentifier); if (null === $fieldDefinition) { From 0ff240265f025f304f580657f2fe3a0cc3897d37 Mon Sep 17 00:00:00 2001 From: Marijan Klaric Date: Wed, 21 Feb 2024 19:32:41 +0100 Subject: [PATCH 21/87] CED-1124 require php 8.1 or greater --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 02fa3956..01e27a72 100644 --- a/composer.json +++ b/composer.json @@ -23,7 +23,7 @@ } ], "require": { - "php": "^8.1", + "php": ">=8.1", "ext-pdo": "*", "doctrine/orm": "^2.5", "ibexa/admin-ui": "^4.0", From 6fc74a5d3aab1a4018f65711f61e55cf381b994b Mon Sep 17 00:00:00 2001 From: Marijan Klaric Date: Fri, 23 Feb 2024 09:40:12 +0100 Subject: [PATCH 22/87] CED-1124 InformationCollectionUpdateType.php code cleaning --- .../Form/InformationCollectionUpdateType.php | 23 +++++++++---------- 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/bundle/Form/InformationCollectionUpdateType.php b/bundle/Form/InformationCollectionUpdateType.php index b3599735..69aefb03 100644 --- a/bundle/Form/InformationCollectionUpdateType.php +++ b/bundle/Form/InformationCollectionUpdateType.php @@ -18,6 +18,7 @@ use function array_keys; use function in_array; +use function sprintf; class InformationCollectionUpdateType extends AbstractContentType { @@ -62,30 +63,23 @@ public function buildForm(FormBuilderInterface $builder, array $options): void { /** @var DataWrapper $dataWrapper */ $dataWrapper = $options['data']; - $collection = $options['collection']; if (!$dataWrapper instanceof DataWrapper) { - throw new RuntimeException( - 'Data must be an instance of Netgen\\EzFormsBundle\\Form\\DataWrapper' - ); + throw new RuntimeException(sprintf('Data must be an instance of %s', DataWrapper::class)); } /** @var InformationCollectionStruct $payload */ $payload = $dataWrapper->payload; if (!$payload instanceof InformationCollectionStruct) { - throw new RuntimeException( - 'Data payload must be an instance of Netgen\\Bundle\\EzFormsBundle\\Form\\Payload\\InformationCollectionStruct' - ); + throw new RuntimeException(sprintf('Data payload must be an instance of %s', InformationCollectionStruct::class)); } /** @var ContentType $contentType */ $contentType = $dataWrapper->definition; if (!$contentType instanceof ContentType) { - throw new RuntimeException( - 'Data definition must be an instance of eZ\\Publish\\API\\Repository\\Values\\ContentType\\ContentType' - ); + throw new RuntimeException(sprintf('Data definition must be an instance of %s', ContentType::class)); } $builder->setDataMapper($this->dataMapper); @@ -101,12 +95,17 @@ public function buildForm(FormBuilderInterface $builder, array $options): void $handler = $this->fieldTypeHandlerRegistry->get($fieldDefinition->fieldTypeIdentifier); - $handler->buildFieldUpdateForm($builder, $fieldDefinition, $dataWrapper->target->content, $this->getLanguageCode($contentType)); + $handler->buildFieldUpdateForm( + $builder, + $fieldDefinition, + $dataWrapper->target->content, + $this->getLanguageCode($contentType) + ); } } /** - * If ContentType language code is in languages array then use it, else use first available one. + * If ContentType language code is in languages array then use it, else use the main language. * * @param ContentType $contentType * From 1d67a7cc9f4f0a8315150b198f35926c7f998418 Mon Sep 17 00:00:00 2001 From: Marijan Klaric Date: Fri, 23 Feb 2024 09:42:53 +0100 Subject: [PATCH 23/87] CED-1124 InformationCollectionUpdateMapper.php code cleaning --- .../InformationCollectionUpdateMapper.php | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/bundle/Form/DataMapper/InformationCollectionUpdateMapper.php b/bundle/Form/DataMapper/InformationCollectionUpdateMapper.php index 5294debf..d2dc737c 100644 --- a/bundle/Form/DataMapper/InformationCollectionUpdateMapper.php +++ b/bundle/Form/DataMapper/InformationCollectionUpdateMapper.php @@ -4,12 +4,16 @@ namespace Netgen\Bundle\InformationCollectionBundle\Form\DataMapper; +use eZ\Publish\API\Repository\Values\ContentType\ContentType; use Netgen\Bundle\IbexaFormsBundle\Form\DataMapper; use Netgen\Bundle\IbexaFormsBundle\Form\DataWrapper; +use Netgen\Bundle\IbexaFormsBundle\Form\Payload\InformationCollectionStruct; use RuntimeException; use Symfony\Component\Form\FormInterface; use Symfony\Component\PropertyAccess\PropertyPathInterface; +use function sprintf; + class InformationCollectionUpdateMapper extends DataMapper { protected function mapToForm( @@ -17,21 +21,21 @@ protected function mapToForm( DataWrapper $data, PropertyPathInterface $propertyPath ): void { + /** @var ContentType $contentType */ $contentType = $data->definition; $fieldDefinitionIdentifier = (string) $propertyPath; $fieldDefinition = $contentType->getFieldDefinition($fieldDefinitionIdentifier); - if (null === $fieldDefinition) { - throw new RuntimeException( - "Data definition does not contain expected FieldDefinition '{$fieldDefinitionIdentifier}'" - ); + if ($fieldDefinition === null) { + throw new RuntimeException(sprintf('Data definition does not contain expected FieldDefinition %s', $fieldDefinitionIdentifier)); } $fieldTypeIdentifier = $fieldDefinition->fieldTypeIdentifier; $handler = $this->fieldTypeHandlerRegistry->get($fieldTypeIdentifier); + /** @var InformationCollectionStruct $struct */ $struct = $data->payload; $collectedFieldValue = $struct->getCollectedFieldValue($fieldDefinitionIdentifier); @@ -58,10 +62,8 @@ protected function mapFromForm( $fieldDefinitionIdentifier = (string) $propertyPath; $fieldDefinition = $contentType->getFieldDefinition($fieldDefinitionIdentifier); - if (null === $fieldDefinition) { - throw new RuntimeException( - "Data definition does not contain expected FieldDefinition '{$fieldDefinitionIdentifier}'" - ); + if ($fieldDefinition === null) { + throw new RuntimeException(sprintf('Data definition does not contain expected FieldDefinition %s', $fieldDefinitionIdentifier)); } $fieldTypeIdentifier = $fieldDefinition->fieldTypeIdentifier; From 7faf13c5cbcb732b1334871ee865554d60be1893 Mon Sep 17 00:00:00 2001 From: Marijan Klaric Date: Fri, 23 Feb 2024 09:45:51 +0100 Subject: [PATCH 24/87] CED-1124 FormBuilder.php code cleaning --- bundle/Form/Builder/FormBuilder.php | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/bundle/Form/Builder/FormBuilder.php b/bundle/Form/Builder/FormBuilder.php index d5be8708..32aae21a 100644 --- a/bundle/Form/Builder/FormBuilder.php +++ b/bundle/Form/Builder/FormBuilder.php @@ -20,6 +20,8 @@ use Symfony\Component\Form\FormFactoryInterface; use Symfony\Component\Routing\RouterInterface; +use function sprintf; + class FormBuilder { public function __construct( @@ -29,8 +31,7 @@ public function __construct( protected readonly ConfigResolverInterface $configResolver, protected readonly FieldDataFactory $legacyFactory, protected readonly FieldHandlerRegistry $registry - ) { - } + ) {} public function createUpdateFormForLocation(Location $location, Collection $collection): FormBuilderInterface { @@ -64,6 +65,11 @@ public function createUpdateFormForLocation(Location $location, Collection $coll private function fromAttribute(Attribute $attribute) { + $handler = $this->registry->handle($attribute->getFieldDefinition()->defaultValue); + if (!$handler instanceof CustomLegacyFieldHandlerInterface) { + return null; + } + $legacyData = new FieldValue( $attribute->getField()->id, $attribute->getValue()->getDataText(), @@ -71,11 +77,6 @@ private function fromAttribute(Attribute $attribute) $attribute->getValue()->getDataFloat() ); - $handler = $this->registry->handle($attribute->getFieldDefinition()->defaultValue); - if (!$handler instanceof CustomLegacyFieldHandlerInterface) { - return null; - } - return $handler->fromLegacyValue($legacyData); } } From c34cdb59b612ee8237ad7fb0613fc889dd3f6e34 Mon Sep 17 00:00:00 2001 From: Marijan Klaric Date: Fri, 23 Feb 2024 15:03:05 +0100 Subject: [PATCH 25/87] CED-1124 code cleanup FormBuilder.php --- bundle/Form/Builder/FormBuilder.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/bundle/Form/Builder/FormBuilder.php b/bundle/Form/Builder/FormBuilder.php index 32aae21a..59e42bf2 100644 --- a/bundle/Form/Builder/FormBuilder.php +++ b/bundle/Form/Builder/FormBuilder.php @@ -4,6 +4,7 @@ namespace Netgen\Bundle\InformationCollectionBundle\Form\Builder; +use Ibexa\Contracts\Core\FieldType\Value as ValueInterface; use Ibexa\Contracts\Core\Repository\Values\Content\Location; use Ibexa\Contracts\Core\SiteAccess\ConfigResolverInterface; use Ibexa\Core\Repository\SiteAccessAware\ContentTypeService; @@ -63,7 +64,7 @@ public function createUpdateFormForLocation(Location $location, Collection $coll ); } - private function fromAttribute(Attribute $attribute) + private function fromAttribute(Attribute $attribute): ?ValueInterface { $handler = $this->registry->handle($attribute->getFieldDefinition()->defaultValue); if (!$handler instanceof CustomLegacyFieldHandlerInterface) { From 251ce3861835a2ccb8c7098a47dd014a9f5483a7 Mon Sep 17 00:00:00 2001 From: Marijan Klaric Date: Fri, 23 Feb 2024 15:06:06 +0100 Subject: [PATCH 26/87] CED-1124 code cleanup AdminController.php --- bundle/Controller/Admin/AdminController.php | 34 +++++++++++++-------- 1 file changed, 22 insertions(+), 12 deletions(-) diff --git a/bundle/Controller/Admin/AdminController.php b/bundle/Controller/Admin/AdminController.php index ca927de5..41c7d173 100644 --- a/bundle/Controller/Admin/AdminController.php +++ b/bundle/Controller/Admin/AdminController.php @@ -4,6 +4,8 @@ namespace Netgen\Bundle\InformationCollectionBundle\Controller\Admin; +use Doctrine\ORM\NonUniqueResultException; +use eZ\Publish\API\Repository\Values\ContentType\ContentType; use Ibexa\Bundle\Core\Controller; use Ibexa\Contracts\Core\Repository\ContentService; use Ibexa\Contracts\Core\Repository\Values\Content\Content; @@ -20,6 +22,7 @@ use Netgen\InformationCollection\API\Value\Filter\Contents; use Netgen\InformationCollection\API\Value\Filter\Query; use Netgen\InformationCollection\API\Value\Filter\SearchQuery; +use Netgen\InformationCollection\API\Value\InformationCollectionStruct; use Netgen\InformationCollection\Core\Factory\FieldDataFactory; use Netgen\InformationCollection\Core\Pagination\InformationCollectionCollectionListAdapter; use Netgen\InformationCollection\Core\Pagination\InformationCollectionCollectionListSearchAdapter; @@ -31,6 +34,7 @@ use Symfony\Component\HttpFoundation\RedirectResponse; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; +use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; use Symfony\Contracts\Translation\TranslatorInterface; use function array_merge; @@ -289,29 +293,37 @@ public function handleCollectionAction(Request $request): RedirectResponse return $this->redirectToRoute('netgen_information_collection.route.admin.view', ['collectionId' => $collectionId]); } - public function editAction(Request $request, int $collectionId) + /** + * @throws NonUniqueResultException + */ + public function editAction(Request $request, int $collectionId): RedirectResponse|Response { $this->checkEditPermissions(); $collection = $this->service->getCollection(new CollectionId($collectionId)); - $locationService = $this->getRepository()->getLocationService(); - - $location = $locationService->loadLocation($collection->getContent()->contentInfo->mainLocationId); + $location = $collection->getContent()->contentInfo->getMainLocation(); $form = $this->builder->createUpdateFormForLocation($location, $collection)->getForm(); $form->handleRequest($request); if ($form->isSubmitted() && $form->isValid()) { + /** @var InformationCollectionStruct $struct */ $struct = $form->getData()->payload; + /** @var ContentType $contentType */ $contentType = $form->getData()->definition; - $ezInfo = $this->infoCollectionRepository->find($collectionId); - $ezInfo->setModified(time()); + $ezInfoCollection = $this->infoCollectionRepository->find($collectionId); + + if ($ezInfoCollection === null) { + throw new NotFoundHttpException(); + } + + $ezInfoCollection->setModified(time()); - $this->infoCollectionRepository->save($ezInfo); + $this->infoCollectionRepository->save($ezInfoCollection); foreach ($struct->getCollectedFields() as $fieldDefIdentifier => $value) { if ($value === null) { @@ -322,14 +334,12 @@ public function editAction(Request $request, int $collectionId) $legacyValue = $this->factory->getLegacyValue($value, $fieldDefinition); - $ezInfoAttributes = $this->infoCollectionAttributeRepository->findByCollectionIdAndFieldDefinitionIds( + $ezInfoAttributes = $this->infoCollectionAttributeRepository->findByCollectionIdAndFieldDefinitionId( $collectionId, - [$fieldDefinition->id] + $fieldDefinition->id ); - if (count($ezInfoAttributes) > 0) { - $ezInfoAttribute = $ezInfoAttributes[0]; - } else { + if ($ezInfoAttributes === null) { $ezInfoAttribute = $this->infoCollectionAttributeRepository->getInstance(); $ezInfoAttribute->setContentObjectId($collection->getContent()->id); $ezInfoAttribute->setContentObjectAttributeId($collection->getContent()->getField($fieldDefinition->identifier)->id); From 316673c56a2ca5b99afe58abdc8acba99f25c4c8 Mon Sep 17 00:00:00 2001 From: Marijan Klaric Date: Fri, 23 Feb 2024 15:07:32 +0100 Subject: [PATCH 27/87] CED-1124 code cleanup field handlers --- lib/API/FieldHandler/CustomLegacyFieldHandlerInterface.php | 3 ++- .../Persistence/FieldHandler/Custom/BirthdayFieldHandler.php | 3 ++- .../Persistence/FieldHandler/Custom/CheckboxFieldHandler.php | 3 ++- .../Persistence/FieldHandler/Custom/CountryFieldHandler.php | 3 ++- .../FieldHandler/Custom/DateAndTimeFieldHandler.php | 3 ++- lib/Core/Persistence/FieldHandler/Custom/DateFieldHandler.php | 3 ++- .../FieldHandler/Custom/EmailAddressFieldHandler.php | 3 ++- .../FieldHandler/Custom/EnhancedSelectionFieldHandler.php | 3 ++- .../Persistence/FieldHandler/Custom/StringFieldHandler.php | 3 ++- lib/Core/Persistence/FieldHandler/Custom/TimeFieldHandler.php | 3 ++- 10 files changed, 20 insertions(+), 10 deletions(-) diff --git a/lib/API/FieldHandler/CustomLegacyFieldHandlerInterface.php b/lib/API/FieldHandler/CustomLegacyFieldHandlerInterface.php index 581fa3ec..01952faa 100644 --- a/lib/API/FieldHandler/CustomLegacyFieldHandlerInterface.php +++ b/lib/API/FieldHandler/CustomLegacyFieldHandlerInterface.php @@ -4,6 +4,7 @@ namespace Netgen\InformationCollection\API\FieldHandler; +use Ibexa\Contracts\Core\FieldType\Value as ValueInterface; use Ibexa\Contracts\Core\Repository\Values\ContentType\FieldDefinition; use Ibexa\Core\FieldType\Value; use Netgen\InformationCollection\API\Value\Legacy\FieldValue; @@ -16,5 +17,5 @@ interface CustomLegacyFieldHandlerInterface extends CustomFieldHandlerInterface */ public function getLegacyValue(Value $value, FieldDefinition $fieldDefinition): FieldValue; - public function fromLegacyValue(FieldValue $legacyData); + public function fromLegacyValue(FieldValue $legacyData): ?ValueInterface; } \ No newline at end of file diff --git a/lib/Core/Persistence/FieldHandler/Custom/BirthdayFieldHandler.php b/lib/Core/Persistence/FieldHandler/Custom/BirthdayFieldHandler.php index d7a812ab..0a62272e 100644 --- a/lib/Core/Persistence/FieldHandler/Custom/BirthdayFieldHandler.php +++ b/lib/Core/Persistence/FieldHandler/Custom/BirthdayFieldHandler.php @@ -4,6 +4,7 @@ namespace Netgen\InformationCollection\Core\Persistence\FieldHandler\Custom; +use Ibexa\Contracts\Core\FieldType\Value as ValueInterface; use Ibexa\Contracts\Core\Repository\Values\ContentType\FieldDefinition; use Ibexa\Core\FieldType\Value; use Netgen\Bundle\BirthdayBundle\Core\FieldType\Birthday\Value as BirthdayValue; @@ -39,7 +40,7 @@ public function getLegacyValue(Value $value, FieldDefinition $fieldDefinition): /** * {@inheritDoc} */ - public function fromLegacyValue(FieldValue $legacyData) + public function fromLegacyValue(FieldValue $legacyData): ValueInterface { return new BirthdayValue($legacyData->getDataText()); } diff --git a/lib/Core/Persistence/FieldHandler/Custom/CheckboxFieldHandler.php b/lib/Core/Persistence/FieldHandler/Custom/CheckboxFieldHandler.php index a7ef2a22..66f410ae 100644 --- a/lib/Core/Persistence/FieldHandler/Custom/CheckboxFieldHandler.php +++ b/lib/Core/Persistence/FieldHandler/Custom/CheckboxFieldHandler.php @@ -4,6 +4,7 @@ namespace Netgen\InformationCollection\Core\Persistence\FieldHandler\Custom; +use Ibexa\Contracts\Core\FieldType\Value as ValueInterface; use Ibexa\Contracts\Core\Repository\Values\ContentType\FieldDefinition; use Ibexa\Core\FieldType\Checkbox\Value as CheckboxValue; use Ibexa\Core\FieldType\Value; @@ -30,7 +31,7 @@ public function getLegacyValue(Value $value, FieldDefinition $fieldDefinition): return FieldValue::withIntValue($fieldDefinition->id, (int) $value->bool); } - public function fromLegacyValue(FieldValue $legacyData) + public function fromLegacyValue(FieldValue $legacyData): ValueInterface { return new CheckboxValue($legacyData->getDataInt() === 1); } diff --git a/lib/Core/Persistence/FieldHandler/Custom/CountryFieldHandler.php b/lib/Core/Persistence/FieldHandler/Custom/CountryFieldHandler.php index c9f27388..b1551456 100644 --- a/lib/Core/Persistence/FieldHandler/Custom/CountryFieldHandler.php +++ b/lib/Core/Persistence/FieldHandler/Custom/CountryFieldHandler.php @@ -48,6 +48,7 @@ public function getLegacyValue(Value $value, FieldDefinition $fieldDefinition): public function fromLegacyValue(FieldValue $legacyData) { - return $this->countryType->fromHash(explode(', ', $legacyData->getDataText())); + $countryCodes = explode(',', $legacyData->getDataText()); + return $this->countryType->fromHash(array_map(fn($code) => trim($code), $countryCodes)); } } diff --git a/lib/Core/Persistence/FieldHandler/Custom/DateAndTimeFieldHandler.php b/lib/Core/Persistence/FieldHandler/Custom/DateAndTimeFieldHandler.php index 14d2b3de..efb47718 100644 --- a/lib/Core/Persistence/FieldHandler/Custom/DateAndTimeFieldHandler.php +++ b/lib/Core/Persistence/FieldHandler/Custom/DateAndTimeFieldHandler.php @@ -4,6 +4,7 @@ namespace Netgen\InformationCollection\Core\Persistence\FieldHandler\Custom; +use Ibexa\Contracts\Core\FieldType\Value as ValueInterface; use Ibexa\Contracts\Core\Repository\Values\ContentType\FieldDefinition; use Ibexa\Core\FieldType\DateAndTime\Value as DateAndTimeValue; use Ibexa\Core\FieldType\Value; @@ -32,7 +33,7 @@ public function getLegacyValue(Value $value, FieldDefinition $fieldDefinition): return FieldValue::withIntValue($fieldDefinition->id, $value->value->getTimestamp()); } - public function fromLegacyValue(FieldValue $legacyData) + public function fromLegacyValue(FieldValue $legacyData): ?ValueInterface { } } diff --git a/lib/Core/Persistence/FieldHandler/Custom/DateFieldHandler.php b/lib/Core/Persistence/FieldHandler/Custom/DateFieldHandler.php index 60427976..92498b26 100644 --- a/lib/Core/Persistence/FieldHandler/Custom/DateFieldHandler.php +++ b/lib/Core/Persistence/FieldHandler/Custom/DateFieldHandler.php @@ -4,6 +4,7 @@ namespace Netgen\InformationCollection\Core\Persistence\FieldHandler\Custom; +use Ibexa\Contracts\Core\FieldType\Value as ValueInterface; use Ibexa\Contracts\Core\Repository\Values\ContentType\FieldDefinition; use Ibexa\Core\FieldType\Date\Value as DateValue; use Ibexa\Core\FieldType\Value; @@ -30,7 +31,7 @@ public function getLegacyValue(Value $value, FieldDefinition $fieldDefinition): return FieldValue::withIntValue($fieldDefinition->id, $value->date->getTimestamp()); } - public function fromLegacyValue(FieldValue $legacyData) + public function fromLegacyValue(FieldValue $legacyData): ?ValueInterface { } } diff --git a/lib/Core/Persistence/FieldHandler/Custom/EmailAddressFieldHandler.php b/lib/Core/Persistence/FieldHandler/Custom/EmailAddressFieldHandler.php index f40515f9..e0fdd97c 100644 --- a/lib/Core/Persistence/FieldHandler/Custom/EmailAddressFieldHandler.php +++ b/lib/Core/Persistence/FieldHandler/Custom/EmailAddressFieldHandler.php @@ -4,6 +4,7 @@ namespace Netgen\InformationCollection\Core\Persistence\FieldHandler\Custom; +use Ibexa\Contracts\Core\FieldType\Value as ValueInterface; use Ibexa\Contracts\Core\Repository\Values\ContentType\FieldDefinition; use Ibexa\Core\FieldType\EmailAddress\Value as EmailAddressValue; use Ibexa\Core\FieldType\Value; @@ -36,7 +37,7 @@ public function getLegacyValue(Value $value, FieldDefinition $fieldDefinition): return new FieldValue($fieldDefinition->id, $value->email, 0, 0); } - public function fromLegacyValue(FieldValue $legacyData) + public function fromLegacyValue(FieldValue $legacyData): ValueInterface { return new EmailAddressValue($legacyData->getDataText()); } diff --git a/lib/Core/Persistence/FieldHandler/Custom/EnhancedSelectionFieldHandler.php b/lib/Core/Persistence/FieldHandler/Custom/EnhancedSelectionFieldHandler.php index 75c801d8..05c10f95 100644 --- a/lib/Core/Persistence/FieldHandler/Custom/EnhancedSelectionFieldHandler.php +++ b/lib/Core/Persistence/FieldHandler/Custom/EnhancedSelectionFieldHandler.php @@ -4,6 +4,7 @@ namespace Netgen\InformationCollection\Core\Persistence\FieldHandler\Custom; +use Ibexa\Contracts\Core\FieldType\Value as ValueInterface; use Ibexa\Contracts\Core\Repository\Values\ContentType\FieldDefinition; use Ibexa\Core\FieldType\Value; use Netgen\Bundle\EnhancedSelectionBundle\Core\FieldType\EnhancedSelection\Value as EnhancedSelectionValue; @@ -44,7 +45,7 @@ public function getLegacyValue(Value $value, FieldDefinition $fieldDefinition): /** * {@inheritDoc} */ - public function fromLegacyValue(FieldValue $legacyData) + public function fromLegacyValue(FieldValue $legacyData): ValueInterface { return new EnhancedSelectionValue([$legacyData->getDataText()]); } diff --git a/lib/Core/Persistence/FieldHandler/Custom/StringFieldHandler.php b/lib/Core/Persistence/FieldHandler/Custom/StringFieldHandler.php index cab98601..19f6278b 100644 --- a/lib/Core/Persistence/FieldHandler/Custom/StringFieldHandler.php +++ b/lib/Core/Persistence/FieldHandler/Custom/StringFieldHandler.php @@ -4,6 +4,7 @@ namespace Netgen\InformationCollection\Core\Persistence\FieldHandler\Custom; +use Ibexa\Contracts\Core\FieldType\Value as ValueInterface; use Ibexa\Contracts\Core\Repository\Values\ContentType\FieldDefinition; use Ibexa\Core\FieldType\TextLine\Value as TextLineValue; use Ibexa\Core\FieldType\Value; @@ -36,7 +37,7 @@ public function getLegacyValue(Value $value, FieldDefinition $fieldDefinition): return new FieldValue($fieldDefinition->id, $value->text, 0, 0); } - public function fromLegacyValue(FieldValue $legacyData) + public function fromLegacyValue(FieldValue $legacyData): ValueInterface { return new TextLineValue($legacyData->getDataText()); } diff --git a/lib/Core/Persistence/FieldHandler/Custom/TimeFieldHandler.php b/lib/Core/Persistence/FieldHandler/Custom/TimeFieldHandler.php index 35521dde..9257c76d 100644 --- a/lib/Core/Persistence/FieldHandler/Custom/TimeFieldHandler.php +++ b/lib/Core/Persistence/FieldHandler/Custom/TimeFieldHandler.php @@ -4,6 +4,7 @@ namespace Netgen\InformationCollection\Core\Persistence\FieldHandler\Custom; +use Ibexa\Contracts\Core\FieldType\Value as ValueInterface; use Ibexa\Contracts\Core\Repository\Values\ContentType\FieldDefinition; use Ibexa\Core\FieldType\Time\Value as TimeValue; use Ibexa\Core\FieldType\Value; @@ -30,7 +31,7 @@ public function getLegacyValue(Value $value, FieldDefinition $fieldDefinition): return FieldValue::withIntValue($fieldDefinition->id, (int) $value->time); } - public function fromLegacyValue(FieldValue $legacyData) + public function fromLegacyValue(FieldValue $legacyData): ValueInterface { } } From 7182dd9c9dba7111b530050f745c4295aa14a3b3 Mon Sep 17 00:00:00 2001 From: Marijan Klaric Date: Fri, 23 Feb 2024 15:08:28 +0100 Subject: [PATCH 28/87] CED-1124 add findByCollectionIdAndFieldDefinitionId method to EzInfoCollectionAttributeRepository.php --- .../EzInfoCollectionAttributeRepository.php | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/lib/Doctrine/Repository/EzInfoCollectionAttributeRepository.php b/lib/Doctrine/Repository/EzInfoCollectionAttributeRepository.php index 935df1ee..30067b61 100644 --- a/lib/Doctrine/Repository/EzInfoCollectionAttributeRepository.php +++ b/lib/Doctrine/Repository/EzInfoCollectionAttributeRepository.php @@ -99,6 +99,22 @@ public function findByCollectionIdAndFieldDefinitionIds(int $collectionId, array ->getResult(); } + /** + * @throws NonUniqueResultException + */ + public function findByCollectionIdAndFieldDefinitionId(int $collectionId, int $fieldDefinitionId): mixed + { + $qb = $this->createQueryBuilder('eica'); + + return $qb->select('eica') + ->where('eica.informationCollectionId = :collectionId') + ->setParameter('collectionId', $collectionId) + ->andWhere('eica.contentClassAttributeId = :fieldId') + ->setParameter('fieldId', $fieldDefinitionId) + ->getQuery() + ->getOneOrNullResult(); + } + public function updateByCollectionId(CollectionId $collectionId, Attribute $attribute): void { $entity = $this->findOneBy([ From 2f1bdff481f228d48e2cc5d43c3d16b288f10752 Mon Sep 17 00:00:00 2001 From: Marijan Klaric Date: Fri, 23 Feb 2024 16:39:49 +0100 Subject: [PATCH 29/87] CED-1024 rename variable in AdminController editAction --- bundle/Controller/Admin/AdminController.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bundle/Controller/Admin/AdminController.php b/bundle/Controller/Admin/AdminController.php index 41c7d173..bc40f844 100644 --- a/bundle/Controller/Admin/AdminController.php +++ b/bundle/Controller/Admin/AdminController.php @@ -334,12 +334,12 @@ public function editAction(Request $request, int $collectionId): RedirectRespons $legacyValue = $this->factory->getLegacyValue($value, $fieldDefinition); - $ezInfoAttributes = $this->infoCollectionAttributeRepository->findByCollectionIdAndFieldDefinitionId( + $ezInfoAttribute = $this->infoCollectionAttributeRepository->findByCollectionIdAndFieldDefinitionId( $collectionId, $fieldDefinition->id ); - if ($ezInfoAttributes === null) { + if ($ezInfoAttribute === null) { $ezInfoAttribute = $this->infoCollectionAttributeRepository->getInstance(); $ezInfoAttribute->setContentObjectId($collection->getContent()->id); $ezInfoAttribute->setContentObjectAttributeId($collection->getContent()->getField($fieldDefinition->identifier)->id); From 34ebdf255a89537af23899a27090c868bd2897e2 Mon Sep 17 00:00:00 2001 From: Marijan Klaric Date: Fri, 23 Feb 2024 16:40:29 +0100 Subject: [PATCH 30/87] CED-1024 add return value to CountryFieldHandler --- .../Persistence/FieldHandler/Custom/CountryFieldHandler.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/Core/Persistence/FieldHandler/Custom/CountryFieldHandler.php b/lib/Core/Persistence/FieldHandler/Custom/CountryFieldHandler.php index b1551456..b54e21e0 100644 --- a/lib/Core/Persistence/FieldHandler/Custom/CountryFieldHandler.php +++ b/lib/Core/Persistence/FieldHandler/Custom/CountryFieldHandler.php @@ -4,6 +4,7 @@ namespace Netgen\InformationCollection\Core\Persistence\FieldHandler\Custom; +use Ibexa\Contracts\Core\FieldType\Value as ValueInterface; use Ibexa\Contracts\Core\Repository\Values\ContentType\FieldDefinition; use Ibexa\Core\FieldType\Country\Value as CountryValue; use Ibexa\Core\FieldType\Country\Type as CountryType; @@ -46,7 +47,7 @@ public function getLegacyValue(Value $value, FieldDefinition $fieldDefinition): return FieldValue::withStringValue($fieldDefinition->id, implode(', ', array_column($value->countries, 'Alpha2'))); } - public function fromLegacyValue(FieldValue $legacyData) + public function fromLegacyValue(FieldValue $legacyData): ?ValueInterface { $countryCodes = explode(',', $legacyData->getDataText()); return $this->countryType->fromHash(array_map(fn($code) => trim($code), $countryCodes)); From 4dc434f307a5d3db9d3b9d90c2ff733146ca86d1 Mon Sep 17 00:00:00 2001 From: Marijan Klaric Date: Tue, 27 Feb 2024 08:39:05 +0100 Subject: [PATCH 31/87] CED-1124 typehint ValueObject instead of Value to make code more robust --- lib/API/FieldHandler/CustomFieldHandlerInterface.php | 6 +++--- lib/API/FieldHandler/CustomLegacyFieldHandlerInterface.php | 4 ++-- lib/Core/Factory/FieldDataFactory.php | 4 ++-- lib/Core/Persistence/FieldHandler/FieldHandlerRegistry.php | 4 ++-- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/lib/API/FieldHandler/CustomFieldHandlerInterface.php b/lib/API/FieldHandler/CustomFieldHandlerInterface.php index ac64ea8a..44510cbb 100644 --- a/lib/API/FieldHandler/CustomFieldHandlerInterface.php +++ b/lib/API/FieldHandler/CustomFieldHandlerInterface.php @@ -5,17 +5,17 @@ namespace Netgen\InformationCollection\API\FieldHandler; use Ibexa\Contracts\Core\Repository\Values\ContentType\FieldDefinition; -use Ibexa\Core\FieldType\Value; +use Ibexa\Contracts\Core\Repository\Values\ValueObject; interface CustomFieldHandlerInterface { /** * Checks if given Value can be handled. */ - public function supports(Value $value): bool; + public function supports(ValueObject $value): bool; /** * Transforms field value object to string. */ - public function toString(Value $value, FieldDefinition $fieldDefinition): string; + public function toString(ValueObject $value, FieldDefinition $fieldDefinition): string; } diff --git a/lib/API/FieldHandler/CustomLegacyFieldHandlerInterface.php b/lib/API/FieldHandler/CustomLegacyFieldHandlerInterface.php index 01952faa..0b773fa1 100644 --- a/lib/API/FieldHandler/CustomLegacyFieldHandlerInterface.php +++ b/lib/API/FieldHandler/CustomLegacyFieldHandlerInterface.php @@ -6,7 +6,7 @@ use Ibexa\Contracts\Core\FieldType\Value as ValueInterface; use Ibexa\Contracts\Core\Repository\Values\ContentType\FieldDefinition; -use Ibexa\Core\FieldType\Value; +use Ibexa\Contracts\Core\Repository\Values\ValueObject; use Netgen\InformationCollection\API\Value\Legacy\FieldValue; interface CustomLegacyFieldHandlerInterface extends CustomFieldHandlerInterface @@ -15,7 +15,7 @@ interface CustomLegacyFieldHandlerInterface extends CustomFieldHandlerInterface * Transforms Ibexa field value to object persistable * in legacy information collection database structure. */ - public function getLegacyValue(Value $value, FieldDefinition $fieldDefinition): FieldValue; + public function getLegacyValue(ValueObject $value, FieldDefinition $fieldDefinition): FieldValue; public function fromLegacyValue(FieldValue $legacyData): ?ValueInterface; } \ No newline at end of file diff --git a/lib/Core/Factory/FieldDataFactory.php b/lib/Core/Factory/FieldDataFactory.php index b5474d58..e2f58f5c 100644 --- a/lib/Core/Factory/FieldDataFactory.php +++ b/lib/Core/Factory/FieldDataFactory.php @@ -5,7 +5,7 @@ namespace Netgen\InformationCollection\Core\Factory; use Ibexa\Contracts\Core\Repository\Values\ContentType\FieldDefinition; -use Ibexa\Core\FieldType\Value; +use Ibexa\Contracts\Core\Repository\Values\ValueObject; use Netgen\InformationCollection\API\Factory\FieldValueFactoryInterface; use Netgen\InformationCollection\API\FieldHandler\CustomFieldHandlerInterface; use Netgen\InformationCollection\API\FieldHandler\CustomLegacyFieldHandlerInterface; @@ -24,7 +24,7 @@ public function __construct(FieldHandlerRegistry $registry) /** * Returns value object that represents legacy value. */ - public function getLegacyValue(Value $value, FieldDefinition $fieldDefinition): FieldValue + public function getLegacyValue(ValueObject $value, FieldDefinition $fieldDefinition): FieldValue { /** @var CustomFieldHandlerInterface $handler */ $handler = $this->registry->handle($value); diff --git a/lib/Core/Persistence/FieldHandler/FieldHandlerRegistry.php b/lib/Core/Persistence/FieldHandler/FieldHandlerRegistry.php index b3c0e633..02b0d18c 100644 --- a/lib/Core/Persistence/FieldHandler/FieldHandlerRegistry.php +++ b/lib/Core/Persistence/FieldHandler/FieldHandlerRegistry.php @@ -4,7 +4,7 @@ namespace Netgen\InformationCollection\Core\Persistence\FieldHandler; -use Ibexa\Core\FieldType\Value; +use Ibexa\Contracts\Core\Repository\Values\ValueObject; use Netgen\InformationCollection\API\FieldHandler\CustomFieldHandlerInterface; final class FieldHandlerRegistry @@ -24,7 +24,7 @@ public function addHandler(CustomFieldHandlerInterface $handler): void $this->handlers[] = $handler; } - public function handle(Value $value): ?CustomFieldHandlerInterface + public function handle(ValueObject $value): ?CustomFieldHandlerInterface { /** @var CustomFieldHandlerInterface $handler */ foreach ($this->handlers as $handler) { From d9710edd386b4764d1f5cd8ff16ac262a4d2cebf Mon Sep 17 00:00:00 2001 From: Marijan Klaric Date: Tue, 27 Feb 2024 08:40:24 +0100 Subject: [PATCH 32/87] CED-1124 use $this->createNotFoundException() in AdminController.php --- bundle/Controller/Admin/AdminController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bundle/Controller/Admin/AdminController.php b/bundle/Controller/Admin/AdminController.php index bc40f844..b65f64ed 100644 --- a/bundle/Controller/Admin/AdminController.php +++ b/bundle/Controller/Admin/AdminController.php @@ -318,7 +318,7 @@ public function editAction(Request $request, int $collectionId): RedirectRespons $ezInfoCollection = $this->infoCollectionRepository->find($collectionId); if ($ezInfoCollection === null) { - throw new NotFoundHttpException(); + $this->createNotFoundException(); } $ezInfoCollection->setModified(time()); From 36d5f6a8fc0e3455040f1cab8b57c4a968ea2ded Mon Sep 17 00:00:00 2001 From: Marijan Klaric Date: Tue, 27 Feb 2024 08:42:30 +0100 Subject: [PATCH 33/87] CED-1124 check if fielddefinition is null --- bundle/Controller/Admin/AdminController.php | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/bundle/Controller/Admin/AdminController.php b/bundle/Controller/Admin/AdminController.php index b65f64ed..e22916ee 100644 --- a/bundle/Controller/Admin/AdminController.php +++ b/bundle/Controller/Admin/AdminController.php @@ -34,7 +34,6 @@ use Symfony\Component\HttpFoundation\RedirectResponse; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; -use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; use Symfony\Contracts\Translation\TranslatorInterface; use function array_merge; @@ -318,7 +317,7 @@ public function editAction(Request $request, int $collectionId): RedirectRespons $ezInfoCollection = $this->infoCollectionRepository->find($collectionId); if ($ezInfoCollection === null) { - $this->createNotFoundException(); + $this->createNotFoundException(); } $ezInfoCollection->setModified(time()); @@ -332,6 +331,10 @@ public function editAction(Request $request, int $collectionId): RedirectRespons $fieldDefinition = $contentType->getFieldDefinition($fieldDefIdentifier); + if ($fieldDefinition === null) { + continue; + } + $legacyValue = $this->factory->getLegacyValue($value, $fieldDefinition); $ezInfoAttribute = $this->infoCollectionAttributeRepository->findByCollectionIdAndFieldDefinitionId( From 2f9f33f6b7cb6341c488fb6cb48f400010d430e6 Mon Sep 17 00:00:00 2001 From: Marijan Klaric Date: Tue, 27 Feb 2024 08:48:15 +0100 Subject: [PATCH 34/87] CED-1124 check if location is not null --- bundle/Controller/Admin/AdminController.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/bundle/Controller/Admin/AdminController.php b/bundle/Controller/Admin/AdminController.php index e22916ee..43ab1d03 100644 --- a/bundle/Controller/Admin/AdminController.php +++ b/bundle/Controller/Admin/AdminController.php @@ -303,6 +303,10 @@ public function editAction(Request $request, int $collectionId): RedirectRespons $location = $collection->getContent()->contentInfo->getMainLocation(); + if ($location === null) { + $this->createNotFoundException(); + } + $form = $this->builder->createUpdateFormForLocation($location, $collection)->getForm(); $form->handleRequest($request); From 58bc4055dbcf00129f2e698d4d44110ae163aa3d Mon Sep 17 00:00:00 2001 From: Marijan Klaric Date: Tue, 27 Feb 2024 09:07:30 +0100 Subject: [PATCH 35/87] CED-1124 instead of type hinting ValueObject type hint Value Interface --- .../CustomFieldHandlerInterface.php | 6 +++--- .../CustomLegacyFieldHandlerInterface.php | 6 +++--- lib/Core/Factory/FieldDataFactory.php | 4 ++-- .../Custom/BirthdayFieldHandler.php | 7 +++---- .../Custom/CheckboxFieldHandler.php | 10 +++++----- .../Custom/CountryFieldHandler.php | 19 +++++++++++-------- .../Custom/DateAndTimeFieldHandler.php | 14 ++++++-------- .../FieldHandler/Custom/DateFieldHandler.php | 14 ++++++-------- .../Custom/EmailAddressFieldHandler.php | 7 +++---- .../Custom/EnhancedSelectionFieldHandler.php | 7 +++---- .../FieldHandler/Custom/FloatFieldHandler.php | 11 ++++++----- .../Custom/IntegerFieldHandler.php | 11 ++++++----- .../Custom/StringFieldHandler.php | 7 +++---- .../FieldHandler/Custom/TimeFieldHandler.php | 14 ++++++-------- .../FieldHandler/FieldHandlerRegistry.php | 4 ++-- 15 files changed, 68 insertions(+), 73 deletions(-) diff --git a/lib/API/FieldHandler/CustomFieldHandlerInterface.php b/lib/API/FieldHandler/CustomFieldHandlerInterface.php index 44510cbb..62c87614 100644 --- a/lib/API/FieldHandler/CustomFieldHandlerInterface.php +++ b/lib/API/FieldHandler/CustomFieldHandlerInterface.php @@ -4,18 +4,18 @@ namespace Netgen\InformationCollection\API\FieldHandler; +use Ibexa\Contracts\Core\FieldType\Value; use Ibexa\Contracts\Core\Repository\Values\ContentType\FieldDefinition; -use Ibexa\Contracts\Core\Repository\Values\ValueObject; interface CustomFieldHandlerInterface { /** * Checks if given Value can be handled. */ - public function supports(ValueObject $value): bool; + public function supports(Value $value): bool; /** * Transforms field value object to string. */ - public function toString(ValueObject $value, FieldDefinition $fieldDefinition): string; + public function toString(Value $value, FieldDefinition $fieldDefinition): string; } diff --git a/lib/API/FieldHandler/CustomLegacyFieldHandlerInterface.php b/lib/API/FieldHandler/CustomLegacyFieldHandlerInterface.php index 0b773fa1..4bf201b7 100644 --- a/lib/API/FieldHandler/CustomLegacyFieldHandlerInterface.php +++ b/lib/API/FieldHandler/CustomLegacyFieldHandlerInterface.php @@ -4,9 +4,9 @@ namespace Netgen\InformationCollection\API\FieldHandler; +use Ibexa\Contracts\Core\FieldType\Value; use Ibexa\Contracts\Core\FieldType\Value as ValueInterface; use Ibexa\Contracts\Core\Repository\Values\ContentType\FieldDefinition; -use Ibexa\Contracts\Core\Repository\Values\ValueObject; use Netgen\InformationCollection\API\Value\Legacy\FieldValue; interface CustomLegacyFieldHandlerInterface extends CustomFieldHandlerInterface @@ -15,7 +15,7 @@ interface CustomLegacyFieldHandlerInterface extends CustomFieldHandlerInterface * Transforms Ibexa field value to object persistable * in legacy information collection database structure. */ - public function getLegacyValue(ValueObject $value, FieldDefinition $fieldDefinition): FieldValue; + public function getLegacyValue(Value $value, FieldDefinition $fieldDefinition): FieldValue; public function fromLegacyValue(FieldValue $legacyData): ?ValueInterface; -} \ No newline at end of file +} diff --git a/lib/Core/Factory/FieldDataFactory.php b/lib/Core/Factory/FieldDataFactory.php index e2f58f5c..38108d4e 100644 --- a/lib/Core/Factory/FieldDataFactory.php +++ b/lib/Core/Factory/FieldDataFactory.php @@ -4,8 +4,8 @@ namespace Netgen\InformationCollection\Core\Factory; +use Ibexa\Contracts\Core\FieldType\Value; use Ibexa\Contracts\Core\Repository\Values\ContentType\FieldDefinition; -use Ibexa\Contracts\Core\Repository\Values\ValueObject; use Netgen\InformationCollection\API\Factory\FieldValueFactoryInterface; use Netgen\InformationCollection\API\FieldHandler\CustomFieldHandlerInterface; use Netgen\InformationCollection\API\FieldHandler\CustomLegacyFieldHandlerInterface; @@ -24,7 +24,7 @@ public function __construct(FieldHandlerRegistry $registry) /** * Returns value object that represents legacy value. */ - public function getLegacyValue(ValueObject $value, FieldDefinition $fieldDefinition): FieldValue + public function getLegacyValue(Value $value, FieldDefinition $fieldDefinition): FieldValue { /** @var CustomFieldHandlerInterface $handler */ $handler = $this->registry->handle($value); diff --git a/lib/Core/Persistence/FieldHandler/Custom/BirthdayFieldHandler.php b/lib/Core/Persistence/FieldHandler/Custom/BirthdayFieldHandler.php index 0a62272e..940eb6d0 100644 --- a/lib/Core/Persistence/FieldHandler/Custom/BirthdayFieldHandler.php +++ b/lib/Core/Persistence/FieldHandler/Custom/BirthdayFieldHandler.php @@ -6,7 +6,6 @@ use Ibexa\Contracts\Core\FieldType\Value as ValueInterface; use Ibexa\Contracts\Core\Repository\Values\ContentType\FieldDefinition; -use Ibexa\Core\FieldType\Value; use Netgen\Bundle\BirthdayBundle\Core\FieldType\Birthday\Value as BirthdayValue; use Netgen\InformationCollection\API\FieldHandler\CustomLegacyFieldHandlerInterface; use Netgen\InformationCollection\API\Value\Legacy\FieldValue; @@ -16,7 +15,7 @@ class BirthdayFieldHandler implements CustomLegacyFieldHandlerInterface /** * {@inheritDoc} */ - public function supports(Value $value): bool + public function supports(ValueInterface $value): bool { return $value instanceof BirthdayValue; } @@ -24,7 +23,7 @@ public function supports(Value $value): bool /** * {@inheritDoc} */ - public function toString(Value $value, FieldDefinition $fieldDefinition): string + public function toString(ValueInterface $value, FieldDefinition $fieldDefinition): string { return (string) $value; } @@ -32,7 +31,7 @@ public function toString(Value $value, FieldDefinition $fieldDefinition): string /** * {@inheritDoc} */ - public function getLegacyValue(Value $value, FieldDefinition $fieldDefinition): FieldValue + public function getLegacyValue(ValueInterface $value, FieldDefinition $fieldDefinition): FieldValue { return new FieldValue($fieldDefinition->id, (string) $value, 0, 0); } diff --git a/lib/Core/Persistence/FieldHandler/Custom/CheckboxFieldHandler.php b/lib/Core/Persistence/FieldHandler/Custom/CheckboxFieldHandler.php index 66f410ae..b5cba632 100644 --- a/lib/Core/Persistence/FieldHandler/Custom/CheckboxFieldHandler.php +++ b/lib/Core/Persistence/FieldHandler/Custom/CheckboxFieldHandler.php @@ -6,27 +6,27 @@ use Ibexa\Contracts\Core\FieldType\Value as ValueInterface; use Ibexa\Contracts\Core\Repository\Values\ContentType\FieldDefinition; +use Ibexa\Core\FieldType\Checkbox\Value; use Ibexa\Core\FieldType\Checkbox\Value as CheckboxValue; -use Ibexa\Core\FieldType\Value; use Netgen\InformationCollection\API\FieldHandler\CustomLegacyFieldHandlerInterface; use Netgen\InformationCollection\API\Value\Legacy\FieldValue; class CheckboxFieldHandler implements CustomLegacyFieldHandlerInterface { - public function supports(Value $value): bool + public function supports(ValueInterface $value): bool { return $value instanceof CheckboxValue; } - public function toString(Value $value, FieldDefinition $fieldDefinition): string + public function toString(ValueInterface $value, FieldDefinition $fieldDefinition): string { return (string) $value; } /** - * @param \Ibexa\Core\FieldType\Checkbox\Value $value + * @param Value $value */ - public function getLegacyValue(Value $value, FieldDefinition $fieldDefinition): FieldValue + public function getLegacyValue(ValueInterface $value, FieldDefinition $fieldDefinition): FieldValue { return FieldValue::withIntValue($fieldDefinition->id, (int) $value->bool); } diff --git a/lib/Core/Persistence/FieldHandler/Custom/CountryFieldHandler.php b/lib/Core/Persistence/FieldHandler/Custom/CountryFieldHandler.php index b54e21e0..050c6f36 100644 --- a/lib/Core/Persistence/FieldHandler/Custom/CountryFieldHandler.php +++ b/lib/Core/Persistence/FieldHandler/Custom/CountryFieldHandler.php @@ -6,14 +6,17 @@ use Ibexa\Contracts\Core\FieldType\Value as ValueInterface; use Ibexa\Contracts\Core\Repository\Values\ContentType\FieldDefinition; -use Ibexa\Core\FieldType\Country\Value as CountryValue; use Ibexa\Core\FieldType\Country\Type as CountryType; -use Ibexa\Core\FieldType\Value; +use Ibexa\Core\FieldType\Country\Value; +use Ibexa\Core\FieldType\Country\Value as CountryValue; use Netgen\InformationCollection\API\FieldHandler\CustomLegacyFieldHandlerInterface; use Netgen\InformationCollection\API\Value\Legacy\FieldValue; use function array_column; +use function array_map; +use function explode; use function implode; +use function trim; /** * Overrides the original country handler to save country alpha2 code to collected info @@ -21,7 +24,6 @@ */ final class CountryFieldHandler implements CustomLegacyFieldHandlerInterface { - private CountryType $countryType; public function __construct(CountryType $countryType) @@ -29,20 +31,20 @@ public function __construct(CountryType $countryType) $this->countryType = $countryType; } - public function supports(Value $value): bool + public function supports(ValueInterface $value): bool { return $value instanceof CountryValue; } - public function toString(Value $value, FieldDefinition $fieldDefinition): string + public function toString(ValueInterface $value, FieldDefinition $fieldDefinition): string { return (string) $value; } /** - * @param \Ibexa\Core\FieldType\Country\Value $value + * @param Value $value */ - public function getLegacyValue(Value $value, FieldDefinition $fieldDefinition): FieldValue + public function getLegacyValue(ValueInterface $value, FieldDefinition $fieldDefinition): FieldValue { return FieldValue::withStringValue($fieldDefinition->id, implode(', ', array_column($value->countries, 'Alpha2'))); } @@ -50,6 +52,7 @@ public function getLegacyValue(Value $value, FieldDefinition $fieldDefinition): public function fromLegacyValue(FieldValue $legacyData): ?ValueInterface { $countryCodes = explode(',', $legacyData->getDataText()); - return $this->countryType->fromHash(array_map(fn($code) => trim($code), $countryCodes)); + + return $this->countryType->fromHash(array_map(static fn ($code) => trim($code), $countryCodes)); } } diff --git a/lib/Core/Persistence/FieldHandler/Custom/DateAndTimeFieldHandler.php b/lib/Core/Persistence/FieldHandler/Custom/DateAndTimeFieldHandler.php index efb47718..c4f99b26 100644 --- a/lib/Core/Persistence/FieldHandler/Custom/DateAndTimeFieldHandler.php +++ b/lib/Core/Persistence/FieldHandler/Custom/DateAndTimeFieldHandler.php @@ -6,19 +6,19 @@ use Ibexa\Contracts\Core\FieldType\Value as ValueInterface; use Ibexa\Contracts\Core\Repository\Values\ContentType\FieldDefinition; +use Ibexa\Core\FieldType\DateAndTime\Value; use Ibexa\Core\FieldType\DateAndTime\Value as DateAndTimeValue; -use Ibexa\Core\FieldType\Value; use Netgen\InformationCollection\API\FieldHandler\CustomLegacyFieldHandlerInterface; use Netgen\InformationCollection\API\Value\Legacy\FieldValue; class DateAndTimeFieldHandler implements CustomLegacyFieldHandlerInterface { - public function supports(Value $value): bool + public function supports(ValueInterface $value): bool { return $value instanceof DateAndTimeValue; } - public function toString(Value $value, FieldDefinition $fieldDefinition): string + public function toString(ValueInterface $value, FieldDefinition $fieldDefinition): string { if ($value instanceof DateAndTimeValue) { return (string) $value; @@ -26,14 +26,12 @@ public function toString(Value $value, FieldDefinition $fieldDefinition): string } /** - * @param \Ibexa\Core\FieldType\DateAndTime\Value $value + * @param Value $value */ - public function getLegacyValue(Value $value, FieldDefinition $fieldDefinition): FieldValue + public function getLegacyValue(ValueInterface $value, FieldDefinition $fieldDefinition): FieldValue { return FieldValue::withIntValue($fieldDefinition->id, $value->value->getTimestamp()); } - public function fromLegacyValue(FieldValue $legacyData): ?ValueInterface - { - } + public function fromLegacyValue(FieldValue $legacyData): ?ValueInterface {} } diff --git a/lib/Core/Persistence/FieldHandler/Custom/DateFieldHandler.php b/lib/Core/Persistence/FieldHandler/Custom/DateFieldHandler.php index 92498b26..6b75c873 100644 --- a/lib/Core/Persistence/FieldHandler/Custom/DateFieldHandler.php +++ b/lib/Core/Persistence/FieldHandler/Custom/DateFieldHandler.php @@ -6,32 +6,30 @@ use Ibexa\Contracts\Core\FieldType\Value as ValueInterface; use Ibexa\Contracts\Core\Repository\Values\ContentType\FieldDefinition; +use Ibexa\Core\FieldType\Date\Value; use Ibexa\Core\FieldType\Date\Value as DateValue; -use Ibexa\Core\FieldType\Value; use Netgen\InformationCollection\API\FieldHandler\CustomLegacyFieldHandlerInterface; use Netgen\InformationCollection\API\Value\Legacy\FieldValue; class DateFieldHandler implements CustomLegacyFieldHandlerInterface { - public function supports(Value $value): bool + public function supports(ValueInterface $value): bool { return $value instanceof DateValue; } - public function toString(Value $value, FieldDefinition $fieldDefinition): string + public function toString(ValueInterface $value, FieldDefinition $fieldDefinition): string { return (string) $value; } /** - * @param \Ibexa\Core\FieldType\Date\Value $value + * @param Value $value */ - public function getLegacyValue(Value $value, FieldDefinition $fieldDefinition): FieldValue + public function getLegacyValue(ValueInterface $value, FieldDefinition $fieldDefinition): FieldValue { return FieldValue::withIntValue($fieldDefinition->id, $value->date->getTimestamp()); } - public function fromLegacyValue(FieldValue $legacyData): ?ValueInterface - { - } + public function fromLegacyValue(FieldValue $legacyData): ?ValueInterface {} } diff --git a/lib/Core/Persistence/FieldHandler/Custom/EmailAddressFieldHandler.php b/lib/Core/Persistence/FieldHandler/Custom/EmailAddressFieldHandler.php index e0fdd97c..ef792339 100644 --- a/lib/Core/Persistence/FieldHandler/Custom/EmailAddressFieldHandler.php +++ b/lib/Core/Persistence/FieldHandler/Custom/EmailAddressFieldHandler.php @@ -7,7 +7,6 @@ use Ibexa\Contracts\Core\FieldType\Value as ValueInterface; use Ibexa\Contracts\Core\Repository\Values\ContentType\FieldDefinition; use Ibexa\Core\FieldType\EmailAddress\Value as EmailAddressValue; -use Ibexa\Core\FieldType\Value; use Netgen\InformationCollection\API\FieldHandler\CustomLegacyFieldHandlerInterface; use Netgen\InformationCollection\API\Value\Legacy\FieldValue; @@ -16,7 +15,7 @@ class EmailAddressFieldHandler implements CustomLegacyFieldHandlerInterface /** * {@inheritDoc} */ - public function supports(Value $value): bool + public function supports(ValueInterface $value): bool { return $value instanceof EmailAddressValue; } @@ -24,7 +23,7 @@ public function supports(Value $value): bool /** * {@inheritDoc} */ - public function toString(Value $value, FieldDefinition $fieldDefinition): string + public function toString(ValueInterface $value, FieldDefinition $fieldDefinition): string { return (string) $value; } @@ -32,7 +31,7 @@ public function toString(Value $value, FieldDefinition $fieldDefinition): string /** * {@inheritDoc} */ - public function getLegacyValue(Value $value, FieldDefinition $fieldDefinition): FieldValue + public function getLegacyValue(ValueInterface $value, FieldDefinition $fieldDefinition): FieldValue { return new FieldValue($fieldDefinition->id, $value->email, 0, 0); } diff --git a/lib/Core/Persistence/FieldHandler/Custom/EnhancedSelectionFieldHandler.php b/lib/Core/Persistence/FieldHandler/Custom/EnhancedSelectionFieldHandler.php index 05c10f95..6bbb296d 100644 --- a/lib/Core/Persistence/FieldHandler/Custom/EnhancedSelectionFieldHandler.php +++ b/lib/Core/Persistence/FieldHandler/Custom/EnhancedSelectionFieldHandler.php @@ -6,7 +6,6 @@ use Ibexa\Contracts\Core\FieldType\Value as ValueInterface; use Ibexa\Contracts\Core\Repository\Values\ContentType\FieldDefinition; -use Ibexa\Core\FieldType\Value; use Netgen\Bundle\EnhancedSelectionBundle\Core\FieldType\EnhancedSelection\Value as EnhancedSelectionValue; use Netgen\InformationCollection\API\FieldHandler\CustomLegacyFieldHandlerInterface; use Netgen\InformationCollection\API\Value\Legacy\FieldValue; @@ -16,7 +15,7 @@ class EnhancedSelectionFieldHandler implements CustomLegacyFieldHandlerInterface /** * {@inheritDoc} */ - public function supports(Value $value): bool + public function supports(ValueInterface $value): bool { return $value instanceof EnhancedSelectionValue; } @@ -24,7 +23,7 @@ public function supports(Value $value): bool /** * {@inheritDoc} */ - public function toString(Value $value, FieldDefinition $fieldDefinition): string + public function toString(ValueInterface $value, FieldDefinition $fieldDefinition): string { return (string) $value; } @@ -32,7 +31,7 @@ public function toString(Value $value, FieldDefinition $fieldDefinition): string /** * {@inheritDoc} */ - public function getLegacyValue(Value $value, FieldDefinition $fieldDefinition): FieldValue + public function getLegacyValue(ValueInterface $value, FieldDefinition $fieldDefinition): FieldValue { $identifier = ''; if (isset($value->identifiers[0])) { diff --git a/lib/Core/Persistence/FieldHandler/Custom/FloatFieldHandler.php b/lib/Core/Persistence/FieldHandler/Custom/FloatFieldHandler.php index 6d2f49e4..0076b025 100644 --- a/lib/Core/Persistence/FieldHandler/Custom/FloatFieldHandler.php +++ b/lib/Core/Persistence/FieldHandler/Custom/FloatFieldHandler.php @@ -4,28 +4,29 @@ namespace Netgen\InformationCollection\Core\Persistence\FieldHandler\Custom; +use Ibexa\Contracts\Core\FieldType\Value as ValueInterface; use Ibexa\Contracts\Core\Repository\Values\ContentType\FieldDefinition; +use Ibexa\Core\FieldType\Float\Value; use Ibexa\Core\FieldType\Float\Value as FloatValue; -use Ibexa\Core\FieldType\Value; use Netgen\InformationCollection\API\FieldHandler\CustomLegacyFieldHandlerInterface; use Netgen\InformationCollection\API\Value\Legacy\FieldValue; class FloatFieldHandler implements CustomLegacyFieldHandlerInterface { - public function supports(Value $value): bool + public function supports(ValueInterface $value): bool { return $value instanceof FloatValue; } - public function toString(Value $value, FieldDefinition $fieldDefinition): string + public function toString(ValueInterface $value, FieldDefinition $fieldDefinition): string { return (string) $value; } /** - * @param \Ibexa\Core\FieldType\Float\Value $value + * @param Value $value */ - public function getLegacyValue(Value $value, FieldDefinition $fieldDefinition): FieldValue + public function getLegacyValue(ValueInterface $value, FieldDefinition $fieldDefinition): FieldValue { return FieldValue::withFloatValue($fieldDefinition->id, $value->value); } diff --git a/lib/Core/Persistence/FieldHandler/Custom/IntegerFieldHandler.php b/lib/Core/Persistence/FieldHandler/Custom/IntegerFieldHandler.php index 74695f7c..fd146c98 100644 --- a/lib/Core/Persistence/FieldHandler/Custom/IntegerFieldHandler.php +++ b/lib/Core/Persistence/FieldHandler/Custom/IntegerFieldHandler.php @@ -4,28 +4,29 @@ namespace Netgen\InformationCollection\Core\Persistence\FieldHandler\Custom; +use Ibexa\Contracts\Core\FieldType\Value as ValueInterface; use Ibexa\Contracts\Core\Repository\Values\ContentType\FieldDefinition; +use Ibexa\Core\FieldType\Integer\Value; use Ibexa\Core\FieldType\Integer\Value as IntegerValue; -use Ibexa\Core\FieldType\Value; use Netgen\InformationCollection\API\FieldHandler\CustomLegacyFieldHandlerInterface; use Netgen\InformationCollection\API\Value\Legacy\FieldValue; class IntegerFieldHandler implements CustomLegacyFieldHandlerInterface { - public function supports(Value $value): bool + public function supports(ValueInterface $value): bool { return $value instanceof IntegerValue; } - public function toString(Value $value, FieldDefinition $fieldDefinition): string + public function toString(ValueInterface $value, FieldDefinition $fieldDefinition): string { return (string) $value; } /** - * @param \Ibexa\Core\FieldType\Integer\Value $value + * @param Value $value */ - public function getLegacyValue(Value $value, FieldDefinition $fieldDefinition): FieldValue + public function getLegacyValue(ValueInterface $value, FieldDefinition $fieldDefinition): FieldValue { return FieldValue::withIntValue($fieldDefinition->id, $value->value); } diff --git a/lib/Core/Persistence/FieldHandler/Custom/StringFieldHandler.php b/lib/Core/Persistence/FieldHandler/Custom/StringFieldHandler.php index 19f6278b..49bb0486 100644 --- a/lib/Core/Persistence/FieldHandler/Custom/StringFieldHandler.php +++ b/lib/Core/Persistence/FieldHandler/Custom/StringFieldHandler.php @@ -7,7 +7,6 @@ use Ibexa\Contracts\Core\FieldType\Value as ValueInterface; use Ibexa\Contracts\Core\Repository\Values\ContentType\FieldDefinition; use Ibexa\Core\FieldType\TextLine\Value as TextLineValue; -use Ibexa\Core\FieldType\Value; use Netgen\InformationCollection\API\FieldHandler\CustomLegacyFieldHandlerInterface; use Netgen\InformationCollection\API\Value\Legacy\FieldValue; @@ -16,7 +15,7 @@ class StringFieldHandler implements CustomLegacyFieldHandlerInterface /** * {@inheritDoc} */ - public function supports(Value $value): bool + public function supports(ValueInterface $value): bool { return $value instanceof TextLineValue; } @@ -24,7 +23,7 @@ public function supports(Value $value): bool /** * {@inheritDoc} */ - public function toString(Value $value, FieldDefinition $fieldDefinition): string + public function toString(ValueInterface $value, FieldDefinition $fieldDefinition): string { return (string) $value; } @@ -32,7 +31,7 @@ public function toString(Value $value, FieldDefinition $fieldDefinition): string /** * {@inheritDoc} */ - public function getLegacyValue(Value $value, FieldDefinition $fieldDefinition): FieldValue + public function getLegacyValue(ValueInterface $value, FieldDefinition $fieldDefinition): FieldValue { return new FieldValue($fieldDefinition->id, $value->text, 0, 0); } diff --git a/lib/Core/Persistence/FieldHandler/Custom/TimeFieldHandler.php b/lib/Core/Persistence/FieldHandler/Custom/TimeFieldHandler.php index 9257c76d..68a5860d 100644 --- a/lib/Core/Persistence/FieldHandler/Custom/TimeFieldHandler.php +++ b/lib/Core/Persistence/FieldHandler/Custom/TimeFieldHandler.php @@ -6,32 +6,30 @@ use Ibexa\Contracts\Core\FieldType\Value as ValueInterface; use Ibexa\Contracts\Core\Repository\Values\ContentType\FieldDefinition; +use Ibexa\Core\FieldType\Time\Value; use Ibexa\Core\FieldType\Time\Value as TimeValue; -use Ibexa\Core\FieldType\Value; use Netgen\InformationCollection\API\FieldHandler\CustomLegacyFieldHandlerInterface; use Netgen\InformationCollection\API\Value\Legacy\FieldValue; class TimeFieldHandler implements CustomLegacyFieldHandlerInterface { - public function supports(Value $value): bool + public function supports(ValueInterface $value): bool { return $value instanceof TimeValue; } - public function toString(Value $value, FieldDefinition $fieldDefinition): string + public function toString(ValueInterface $value, FieldDefinition $fieldDefinition): string { return (string) $value; } /** - * @param \Ibexa\Core\FieldType\Time\Value $value + * @param Value $value */ - public function getLegacyValue(Value $value, FieldDefinition $fieldDefinition): FieldValue + public function getLegacyValue(ValueInterface $value, FieldDefinition $fieldDefinition): FieldValue { return FieldValue::withIntValue($fieldDefinition->id, (int) $value->time); } - public function fromLegacyValue(FieldValue $legacyData): ValueInterface - { - } + public function fromLegacyValue(FieldValue $legacyData): ValueInterface {} } diff --git a/lib/Core/Persistence/FieldHandler/FieldHandlerRegistry.php b/lib/Core/Persistence/FieldHandler/FieldHandlerRegistry.php index 02b0d18c..2ea2de2a 100644 --- a/lib/Core/Persistence/FieldHandler/FieldHandlerRegistry.php +++ b/lib/Core/Persistence/FieldHandler/FieldHandlerRegistry.php @@ -4,7 +4,7 @@ namespace Netgen\InformationCollection\Core\Persistence\FieldHandler; -use Ibexa\Contracts\Core\Repository\Values\ValueObject; +use Ibexa\Contracts\Core\FieldType\Value; use Netgen\InformationCollection\API\FieldHandler\CustomFieldHandlerInterface; final class FieldHandlerRegistry @@ -24,7 +24,7 @@ public function addHandler(CustomFieldHandlerInterface $handler): void $this->handlers[] = $handler; } - public function handle(ValueObject $value): ?CustomFieldHandlerInterface + public function handle(Value $value): ?CustomFieldHandlerInterface { /** @var CustomFieldHandlerInterface $handler */ foreach ($this->handlers as $handler) { From e00a98dcb7775070b636a70eeb6b437d9b57b57e Mon Sep 17 00:00:00 2001 From: Marijan Klaric Date: Tue, 27 Feb 2024 10:01:32 +0100 Subject: [PATCH 36/87] CED-1124 rename method fromAttribute to getFieldValueFromAttribute --- bundle/Form/Builder/FormBuilder.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bundle/Form/Builder/FormBuilder.php b/bundle/Form/Builder/FormBuilder.php index 59e42bf2..855a4501 100644 --- a/bundle/Form/Builder/FormBuilder.php +++ b/bundle/Form/Builder/FormBuilder.php @@ -64,7 +64,7 @@ public function createUpdateFormForLocation(Location $location, Collection $coll ); } - private function fromAttribute(Attribute $attribute): ?ValueInterface + private function getFieldValueFromAttribute(Attribute $attribute): ?ValueInterface { $handler = $this->registry->handle($attribute->getFieldDefinition()->defaultValue); if (!$handler instanceof CustomLegacyFieldHandlerInterface) { From 9d633537f9401bb7ae1398606e0daeccd27d4254 Mon Sep 17 00:00:00 2001 From: Marijan Klaric Date: Tue, 27 Feb 2024 10:02:40 +0100 Subject: [PATCH 37/87] CED-1124 use getFieldValueFromAttribute instead of fromAttribute --- bundle/Form/Builder/FormBuilder.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bundle/Form/Builder/FormBuilder.php b/bundle/Form/Builder/FormBuilder.php index 855a4501..8cc06452 100644 --- a/bundle/Form/Builder/FormBuilder.php +++ b/bundle/Form/Builder/FormBuilder.php @@ -41,7 +41,7 @@ public function createUpdateFormForLocation(Location $location, Collection $coll $struct = new InformationCollectionStruct(); foreach ($collection->getAttributes() as $attribute) { - $fieldValue = $this->fromAttribute($attribute); + $fieldValue = $this->getFieldValueFromAttribute($attribute); if ($fieldValue !== null) { $struct->setCollectedFieldValue($attribute->getField()->getFieldDefinitionIdentifier(), $fieldValue); From 89702d52874f55bd5fca27272f1a65c249c294b6 Mon Sep 17 00:00:00 2001 From: Marijan Klaric Date: Mon, 18 Mar 2024 07:13:00 +0100 Subject: [PATCH 38/87] CED-1124 typehint right InformationCollectionStruct --- bundle/Controller/Admin/AdminController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bundle/Controller/Admin/AdminController.php b/bundle/Controller/Admin/AdminController.php index 43ab1d03..762b401d 100644 --- a/bundle/Controller/Admin/AdminController.php +++ b/bundle/Controller/Admin/AdminController.php @@ -11,6 +11,7 @@ use Ibexa\Contracts\Core\Repository\Values\Content\Content; use Ibexa\Contracts\Core\SiteAccess\ConfigResolverInterface; use Ibexa\Core\MVC\Symfony\Security\Authorization\Attribute; +use Netgen\Bundle\IbexaFormsBundle\Form\Payload\InformationCollectionStruct; use Netgen\Bundle\InformationCollectionBundle\Form\Builder\FormBuilder; use Netgen\InformationCollection\API\Persistence\Anonymizer\Anonymizer; use Netgen\InformationCollection\API\Service\InformationCollection; @@ -22,7 +23,6 @@ use Netgen\InformationCollection\API\Value\Filter\Contents; use Netgen\InformationCollection\API\Value\Filter\Query; use Netgen\InformationCollection\API\Value\Filter\SearchQuery; -use Netgen\InformationCollection\API\Value\InformationCollectionStruct; use Netgen\InformationCollection\Core\Factory\FieldDataFactory; use Netgen\InformationCollection\Core\Pagination\InformationCollectionCollectionListAdapter; use Netgen\InformationCollection\Core\Pagination\InformationCollectionCollectionListSearchAdapter; From 0c50e28d3276cb21f8947cf361843fe570ac5de7 Mon Sep 17 00:00:00 2001 From: Marijan Klaric Date: Mon, 18 Mar 2024 07:13:33 +0100 Subject: [PATCH 39/87] CED-1124 throw NotFoundException --- bundle/Controller/Admin/AdminController.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bundle/Controller/Admin/AdminController.php b/bundle/Controller/Admin/AdminController.php index 762b401d..0534c17a 100644 --- a/bundle/Controller/Admin/AdminController.php +++ b/bundle/Controller/Admin/AdminController.php @@ -304,7 +304,7 @@ public function editAction(Request $request, int $collectionId): RedirectRespons $location = $collection->getContent()->contentInfo->getMainLocation(); if ($location === null) { - $this->createNotFoundException(); + throw $this->createNotFoundException(); } $form = $this->builder->createUpdateFormForLocation($location, $collection)->getForm(); @@ -321,7 +321,7 @@ public function editAction(Request $request, int $collectionId): RedirectRespons $ezInfoCollection = $this->infoCollectionRepository->find($collectionId); if ($ezInfoCollection === null) { - $this->createNotFoundException(); + throw $this->createNotFoundException(); } $ezInfoCollection->setModified(time()); From 1d3bd95079c256b1a960a042093e6fced35db554 Mon Sep 17 00:00:00 2001 From: Marijan Klaric Date: Mon, 18 Mar 2024 11:34:30 +0100 Subject: [PATCH 40/87] CED-1124 remove dependency on ibexa-forms-bundle --- bundle/Controller/Admin/AdminController.php | 2 +- bundle/Form/Builder/FormBuilder.php | 4 +- bundle/Form/DataMapper.php | 151 ++++++++++++++++++ .../InformationCollectionUpdateMapper.php | 6 +- bundle/Form/DataWrapper.php | 48 ++++++ bundle/Form/FieldTypeHandler.php | 112 +++++++++++++ bundle/Form/FieldTypeHandler/BinaryFile.php | 64 ++++++++ bundle/Form/FieldTypeHandler/Checkbox.php | 49 ++++++ bundle/Form/FieldTypeHandler/Country.php | 95 +++++++++++ bundle/Form/FieldTypeHandler/Date.php | 43 +++++ bundle/Form/FieldTypeHandler/DateAndTime.php | 46 ++++++ bundle/Form/FieldTypeHandler/Email.php | 42 +++++ bundle/Form/FieldTypeHandler/FloatHandler.php | 74 +++++++++ bundle/Form/FieldTypeHandler/Image.php | 62 +++++++ .../Form/FieldTypeHandler/IntegerHandler.php | 74 +++++++++ bundle/Form/FieldTypeHandler/Isbn.php | 52 ++++++ bundle/Form/FieldTypeHandler/MapLocation.php | 54 +++++++ bundle/Form/FieldTypeHandler/Relation.php | 63 ++++++++ bundle/Form/FieldTypeHandler/RelationList.php | 105 ++++++++++++ bundle/Form/FieldTypeHandler/Selection.php | 59 +++++++ bundle/Form/FieldTypeHandler/TextBlock.php | 43 +++++ bundle/Form/FieldTypeHandler/TextLine.php | 61 +++++++ bundle/Form/FieldTypeHandler/Time.php | 59 +++++++ bundle/Form/FieldTypeHandler/Url.php | 44 +++++ bundle/Form/FieldTypeHandler/User.php | 42 +++++ bundle/Form/FieldTypeHandlerInterface.php | 57 +++++++ bundle/Form/FieldTypeHandlerRegistry.php | 69 ++++++++ .../Form/InformationCollectionUpdateType.php | 6 +- .../Payload/InformationCollectionStruct.php | 41 +++++ bundle/Form/Type/AbstractContentType.php | 22 +++ bundle/Form/Type/FieldType/UserCreateType.php | 57 +++++++ bundle/Form/Type/FieldType/UserType.php | 73 +++++++++ bundle/Form/Type/FieldType/UserUpdateType.php | 50 ++++++ bundle/Form/Type/MapType.php | 33 ++++ bundle/Form/Type/UrlType.php | 32 ++++ composer.json | 1 - doc/cookbook/override_something_on_form.rst | 4 +- .../InformationCollectionControllerTest.php | 4 +- tests/old/Factory/EmailDataFactoryTest.php | 4 +- 39 files changed, 1890 insertions(+), 17 deletions(-) create mode 100644 bundle/Form/DataMapper.php create mode 100644 bundle/Form/DataWrapper.php create mode 100644 bundle/Form/FieldTypeHandler.php create mode 100644 bundle/Form/FieldTypeHandler/BinaryFile.php create mode 100644 bundle/Form/FieldTypeHandler/Checkbox.php create mode 100644 bundle/Form/FieldTypeHandler/Country.php create mode 100644 bundle/Form/FieldTypeHandler/Date.php create mode 100644 bundle/Form/FieldTypeHandler/DateAndTime.php create mode 100644 bundle/Form/FieldTypeHandler/Email.php create mode 100644 bundle/Form/FieldTypeHandler/FloatHandler.php create mode 100644 bundle/Form/FieldTypeHandler/Image.php create mode 100644 bundle/Form/FieldTypeHandler/IntegerHandler.php create mode 100644 bundle/Form/FieldTypeHandler/Isbn.php create mode 100644 bundle/Form/FieldTypeHandler/MapLocation.php create mode 100644 bundle/Form/FieldTypeHandler/Relation.php create mode 100644 bundle/Form/FieldTypeHandler/RelationList.php create mode 100644 bundle/Form/FieldTypeHandler/Selection.php create mode 100644 bundle/Form/FieldTypeHandler/TextBlock.php create mode 100644 bundle/Form/FieldTypeHandler/TextLine.php create mode 100644 bundle/Form/FieldTypeHandler/Time.php create mode 100644 bundle/Form/FieldTypeHandler/Url.php create mode 100644 bundle/Form/FieldTypeHandler/User.php create mode 100644 bundle/Form/FieldTypeHandlerInterface.php create mode 100644 bundle/Form/FieldTypeHandlerRegistry.php create mode 100644 bundle/Form/Payload/InformationCollectionStruct.php create mode 100644 bundle/Form/Type/AbstractContentType.php create mode 100644 bundle/Form/Type/FieldType/UserCreateType.php create mode 100644 bundle/Form/Type/FieldType/UserType.php create mode 100644 bundle/Form/Type/FieldType/UserUpdateType.php create mode 100644 bundle/Form/Type/MapType.php create mode 100644 bundle/Form/Type/UrlType.php diff --git a/bundle/Controller/Admin/AdminController.php b/bundle/Controller/Admin/AdminController.php index 0534c17a..3f0b2de8 100644 --- a/bundle/Controller/Admin/AdminController.php +++ b/bundle/Controller/Admin/AdminController.php @@ -11,7 +11,7 @@ use Ibexa\Contracts\Core\Repository\Values\Content\Content; use Ibexa\Contracts\Core\SiteAccess\ConfigResolverInterface; use Ibexa\Core\MVC\Symfony\Security\Authorization\Attribute; -use Netgen\Bundle\IbexaFormsBundle\Form\Payload\InformationCollectionStruct; +use Netgen\Bundle\InformationCollectionBundle\Form\Payload\InformationCollectionStruct; use Netgen\Bundle\InformationCollectionBundle\Form\Builder\FormBuilder; use Netgen\InformationCollection\API\Persistence\Anonymizer\Anonymizer; use Netgen\InformationCollection\API\Service\InformationCollection; diff --git a/bundle/Form/Builder/FormBuilder.php b/bundle/Form/Builder/FormBuilder.php index 8cc06452..d16e11f2 100644 --- a/bundle/Form/Builder/FormBuilder.php +++ b/bundle/Form/Builder/FormBuilder.php @@ -8,8 +8,8 @@ use Ibexa\Contracts\Core\Repository\Values\Content\Location; use Ibexa\Contracts\Core\SiteAccess\ConfigResolverInterface; use Ibexa\Core\Repository\SiteAccessAware\ContentTypeService; -use Netgen\Bundle\IbexaFormsBundle\Form\DataWrapper; -use Netgen\Bundle\IbexaFormsBundle\Form\Payload\InformationCollectionStruct; +use Netgen\Bundle\InformationCollectionBundle\Form\DataWrapper; +use Netgen\Bundle\InformationCollectionBundle\Form\Payload\InformationCollectionStruct; use Netgen\Bundle\InformationCollectionBundle\Form\InformationCollectionUpdateType; use Netgen\InformationCollection\API\FieldHandler\CustomLegacyFieldHandlerInterface; use Netgen\InformationCollection\API\Value\Attribute; diff --git a/bundle/Form/DataMapper.php b/bundle/Form/DataMapper.php new file mode 100644 index 00000000..b867d65e --- /dev/null +++ b/bundle/Form/DataMapper.php @@ -0,0 +1,151 @@ +fieldTypeHandlerRegistry = $fieldTypeHandlerRegistry; + $this->propertyAccessor = $propertyAccessor ?: PropertyAccess::createPropertyAccessor(); + } + + public function mapDataToForms($data, $forms): void + { + $empty = null === $data || [] === $data; + + if (!$empty && !is_array($data) && !is_object($data)) { + throw new UnexpectedTypeException($data, 'object, array or empty'); + } + + foreach ($forms as $form) { + $propertyPath = $form->getPropertyPath(); + $config = $form->getConfig(); + + if ($data instanceof DataWrapper && null !== $propertyPath && $config->getMapped()) { + /* @var $data \Netgen\Bundle\InformationCollectionBundle\Form\DataWrapper */ + $this->mapToForm($form, $data, $propertyPath); + } elseif (!$empty && null !== $propertyPath && $config->getMapped()) { + $form->setData($this->propertyAccessor->getValue($data, $propertyPath)); + } else { + $form->setData($form->getConfig()->getData()); + } + } + } + + public function mapFormsToData($forms, &$data): void + { + if (null === $data) { + return; + } + + if (!is_array($data) && !is_object($data)) { + throw new UnexpectedTypeException($data, 'object, array or empty'); + } + + foreach ($forms as $form) { + $propertyPath = $form->getPropertyPath(); + $config = $form->getConfig(); + + // Write-back is disabled if the form is not synchronized (transformation failed), + // if the form was not submitted and if the form is disabled (modification not allowed) + if ( + null === $propertyPath + || !$config->getMapped() + || !$form->isSubmitted() + || !$form->isSynchronized() + || $form->isDisabled() + ) { + continue; + } + + // If $data is out ContentCreateStruct, we need to map it to the corresponding field + // in the struct + if ($data instanceof DataWrapper) { + /* @var $data \Netgen\Bundle\InformationCollectionBundle\Form\DataWrapper */ + $this->mapFromForm($form, $data, $propertyPath); + + continue; + } + + // If the field is of type DateTime and the data is the same skip the update to + // keep the original object hash + if ( + $form->getData() instanceof DateTime + && $form->getData() === $this->propertyAccessor->getValue($data, $propertyPath) + ) { + continue; + } + + // If the data is identical to the value in $data, we are + // dealing with a reference + if ( + is_object($data) + && $config->getByReference() + && $form->getData() === $this->propertyAccessor->getValue($data, $propertyPath) + ) { + continue; + } + + $this->propertyAccessor->setValue($data, $propertyPath, $form->getData()); + } + } + + /** + * Maps data from Ibexa Platform structure to the form. + */ + abstract protected function mapToForm( + FormInterface $form, + DataWrapper $data, + PropertyPathInterface $propertyPath + ): void; + + /** + * Maps data from form to the Ibexa Platform structure. + */ + abstract protected function mapFromForm( + FormInterface $form, + DataWrapper $data, + PropertyPathInterface $propertyPath + ): void; + + /** + * Returns if the update should be skipped for empty value. + * + * @param mixed $value + */ + protected function shouldSkipForEmptyUpdate(FormInterface $form, $value, string $fieldDefinitionIdentifier): bool + { + return + $value === null + && ( + $form->getRoot()->has("ibexa_forms_skip_empty_update_{$fieldDefinitionIdentifier}") + && $form->getRoot()->get("ibexa_forms_skip_empty_update_{$fieldDefinitionIdentifier}")->getData() === 'yes' + ) + ; + } +} diff --git a/bundle/Form/DataMapper/InformationCollectionUpdateMapper.php b/bundle/Form/DataMapper/InformationCollectionUpdateMapper.php index d2dc737c..37b64a86 100644 --- a/bundle/Form/DataMapper/InformationCollectionUpdateMapper.php +++ b/bundle/Form/DataMapper/InformationCollectionUpdateMapper.php @@ -5,9 +5,9 @@ namespace Netgen\Bundle\InformationCollectionBundle\Form\DataMapper; use eZ\Publish\API\Repository\Values\ContentType\ContentType; -use Netgen\Bundle\IbexaFormsBundle\Form\DataMapper; -use Netgen\Bundle\IbexaFormsBundle\Form\DataWrapper; -use Netgen\Bundle\IbexaFormsBundle\Form\Payload\InformationCollectionStruct; +use Netgen\Bundle\InformationCollectionBundle\Form\DataMapper; +use Netgen\Bundle\InformationCollectionBundle\Form\DataWrapper; +use Netgen\Bundle\InformationCollectionBundle\Form\Payload\InformationCollectionStruct; use RuntimeException; use Symfony\Component\Form\FormInterface; use Symfony\Component\PropertyAccess\PropertyPathInterface; diff --git a/bundle/Form/DataWrapper.php b/bundle/Form/DataWrapper.php new file mode 100644 index 00000000..d1c46044 --- /dev/null +++ b/bundle/Form/DataWrapper.php @@ -0,0 +1,48 @@ +payload = $payload; + $this->definition = $definition; + $this->target = $target; + } +} diff --git a/bundle/Form/FieldTypeHandler.php b/bundle/Form/FieldTypeHandler.php new file mode 100644 index 00000000..1a7a6507 --- /dev/null +++ b/bundle/Form/FieldTypeHandler.php @@ -0,0 +1,112 @@ +buildFieldForm($formBuilder, $fieldDefinition, $languageCode); + } + + /** + * In most cases this will be the same as {@link self::buildCreateFieldForm()}. + * For this reason default implementation falls back to the internal method + * {@link self::buildFieldForm()}, which should be implemented as needed. + */ + public function buildFieldUpdateForm( + FormBuilderInterface $formBuilder, + FieldDefinition $fieldDefinition, + Content $content, + string $languageCode + ): void { + $this->buildFieldForm($formBuilder, $fieldDefinition, $languageCode, $content); + } + + /** + * In most cases implementations of methods {@link self::buildCreateFieldForm()} + * and {@link self::buildUpdateFieldForm()} will be the same, therefore default + * handler implementation of those falls back to this method. + * + * Implement as needed. + */ + protected function buildFieldForm( + FormBuilderInterface $formBuilder, + FieldDefinition $fieldDefinition, + string $languageCode, + ?Content $content = null + ): void { + throw new RuntimeException('Not implemented.'); + } + + /** + * Returns default field options, created from given $fieldDefinition and $languageCode. + */ + protected function getDefaultFieldOptions( + FieldDefinition $fieldDefinition, + string $languageCode, + ?Content $content = null + ): array { + $options = []; + + $options['label'] = $fieldDefinition->getName($languageCode); + $options['required'] = $fieldDefinition->isRequired; + $options['ibexa_forms']['description'] = $fieldDefinition->getDescription($languageCode); + $options['ibexa_forms']['language_code'] = $languageCode; + $options['ibexa_forms']['fielddefinition'] = $fieldDefinition; + + if ($content !== null) { + $options['ibexa_forms']['content'] = $content; + } + + $options['constraints'] = []; + if ($fieldDefinition->isRequired) { + $options['constraints'][] = new Constraints\NotBlank(); + } + + return $options; + } + + /** + * Adds a hidden field to the from, indicating that empty value passed + * for update should be ignored. + */ + protected function skipEmptyUpdate(FormBuilderInterface $formBuilder, string $fieldDefinitionIdentifier): void + { + $options = [ + 'mapped' => false, + 'data' => 'yes', + ]; + + $formBuilder->add( + "ibexa_forms_skip_empty_update_{$fieldDefinitionIdentifier}", + HiddenType::class, + $options + ); + } +} diff --git a/bundle/Form/FieldTypeHandler/BinaryFile.php b/bundle/Form/FieldTypeHandler/BinaryFile.php new file mode 100644 index 00000000..df0c1161 --- /dev/null +++ b/bundle/Form/FieldTypeHandler/BinaryFile.php @@ -0,0 +1,64 @@ + $data->getRealPath(), + 'fileName' => $data->getClientOriginalName(), + 'fileSize' => $data->getSize(), + ]; + + return new FileValue($fileData); + } + + protected function buildFieldForm( + FormBuilderInterface $formBuilder, + FieldDefinition $fieldDefinition, + string $languageCode, + ?Content $content = null + ): void { + $options = $this->getDefaultFieldOptions($fieldDefinition, $languageCode, $content); + $maxFileSize = $fieldDefinition->validatorConfiguration['FileSizeValidator']['maxFileSize'] ?? false; + + if ($maxFileSize !== false) { + $options['constraints'][] = new Constraints\File( + [ + 'maxSize' => $maxFileSize * Constraints\FileValidator::MB_BYTES, + ] + ); + } + + // File should not be erased (updated as empty) if nothing is selected in file input + $this->skipEmptyUpdate($formBuilder, $fieldDefinition->identifier); + // Used with update for displaying current file + $options['block_name'] = 'ibexa_forms_binary_file'; + + $formBuilder->add($fieldDefinition->identifier, FileType::class, $options); + } +} diff --git a/bundle/Form/FieldTypeHandler/Checkbox.php b/bundle/Form/FieldTypeHandler/Checkbox.php new file mode 100644 index 00000000..908e7cc9 --- /dev/null +++ b/bundle/Form/FieldTypeHandler/Checkbox.php @@ -0,0 +1,49 @@ +fieldHelper = $fieldHelper; + } + + public function convertFieldValueToForm(Value $value, ?FieldDefinition $fieldDefinition = null): bool + { + return $value->bool; + } + + public function convertFieldValueFromForm($data): CheckBoxValue\Value + { + return new CheckboxValue\Value($data); + } + + protected function buildFieldForm( + FormBuilderInterface $formBuilder, + FieldDefinition $fieldDefinition, + string $languageCode, + ?Content $content = null + ): void { + $options = $this->getDefaultFieldOptions($fieldDefinition, $languageCode, $content); + + if (!$content instanceof Content && $fieldDefinition->defaultValue instanceof CheckboxValue\Value) { + $options['data'] = $fieldDefinition->defaultValue->bool; + } + + $formBuilder->add($fieldDefinition->identifier, CheckboxType::class, $options); + } +} diff --git a/bundle/Form/FieldTypeHandler/Country.php b/bundle/Form/FieldTypeHandler/Country.php new file mode 100644 index 00000000..8400f54e --- /dev/null +++ b/bundle/Form/FieldTypeHandler/Country.php @@ -0,0 +1,95 @@ +countryData = $countryData; + + foreach ($countryData as $countryCode => $country) { + $this->filteredCountryData[$countryCode] = $country['Name']; + } + } + + public function convertFieldValueToForm(Value $value, ?FieldDefinition $fieldDefinition = null) + { + $isMultiple = true; + if ($fieldDefinition !== null) { + $fieldSettings = $fieldDefinition->getFieldSettings(); + $isMultiple = $fieldSettings['isMultiple']; + } + + if (!$isMultiple) { + if (empty($value->countries)) { + return ''; + } + + $keys = array_keys($value->countries); + + return reset($keys); + } + + return array_keys($value->countries); + } + + public function convertFieldValueFromForm($data): CountryValue + { + $country = []; + + // case if multiple is true + if (is_array($data)) { + foreach ($data as $countryCode) { + if (array_key_exists($countryCode, $this->countryData)) { + $country[$countryCode] = $this->countryData[$countryCode]; + } + } + } elseif (array_key_exists($data, $this->countryData)) { + $country[$data] = $this->countryData[$data]; + } + + return new CountryValue($country); + } + + protected function buildFieldForm( + FormBuilderInterface $formBuilder, + FieldDefinition $fieldDefinition, + string $languageCode, + ?Content $content = null + ): void { + $options = $this->getDefaultFieldOptions($fieldDefinition, $languageCode, $content); + + $options['expanded'] = false; + $options['multiple'] = $fieldDefinition->getFieldSettings()['isMultiple'] ?? false; + + $options['choices'] = array_flip($this->filteredCountryData); + + $formBuilder->add($fieldDefinition->identifier, ChoiceType::class, $options); + } +} diff --git a/bundle/Form/FieldTypeHandler/Date.php b/bundle/Form/FieldTypeHandler/Date.php new file mode 100644 index 00000000..edbbcfc0 --- /dev/null +++ b/bundle/Form/FieldTypeHandler/Date.php @@ -0,0 +1,43 @@ +date; + } + + public function convertFieldValueFromForm($data): DateValue\Value + { + return new DateValue\Value($data); + } + + protected function buildFieldForm( + FormBuilderInterface $formBuilder, + FieldDefinition $fieldDefinition, + string $languageCode, + ?Content $content = null + ): void { + $options = $this->getDefaultFieldOptions($fieldDefinition, $languageCode, $content); + + $options['input'] = 'datetime'; + $options['widget'] = 'choice'; + $options['constraints'][] = new Assert\Date(); + + $formBuilder->add($fieldDefinition->identifier, DateType::class, $options); + } +} diff --git a/bundle/Form/FieldTypeHandler/DateAndTime.php b/bundle/Form/FieldTypeHandler/DateAndTime.php new file mode 100644 index 00000000..a27afa6b --- /dev/null +++ b/bundle/Form/FieldTypeHandler/DateAndTime.php @@ -0,0 +1,46 @@ +value; + } + + public function convertFieldValueFromForm($data): DTValue\Value + { + return new DTValue\Value($data); + } + + protected function buildFieldForm( + FormBuilderInterface $formBuilder, + FieldDefinition $fieldDefinition, + string $languageCode, + ?Content $content = null + ): void { + $options = $this->getDefaultFieldOptions($fieldDefinition, $languageCode, $content); + + $useSeconds = $fieldDefinition->getFieldSettings()['useSeconds'] ?? false; + $options['input'] = 'datetime'; + $options['date_widget'] = 'choice'; + $options['time_widget'] = 'choice'; + $options['with_seconds'] = $useSeconds; + $options['constraints'][] = new Assert\DateTime(); + + $formBuilder->add($fieldDefinition->identifier, DateTimeType::class, $options); + } +} diff --git a/bundle/Form/FieldTypeHandler/Email.php b/bundle/Form/FieldTypeHandler/Email.php new file mode 100644 index 00000000..1de4e6bf --- /dev/null +++ b/bundle/Form/FieldTypeHandler/Email.php @@ -0,0 +1,42 @@ +email; + } + + public function convertFieldValueFromForm($data): EmailAddress\Value + { + return new EmailAddress\Value($data); + } + + protected function buildFieldForm( + FormBuilderInterface $formBuilder, + FieldDefinition $fieldDefinition, + string $languageCode, + ?Content $content = null + ): void { + $options = $this->getDefaultFieldOptions($fieldDefinition, $languageCode, $content); + + if (isset($fieldDefinition->validatorConfiguration['EmailAddressValidator'])) { + $options['constraints'][] = new Constraints\Email(); + } + + $formBuilder->add($fieldDefinition->identifier, EmailType::class, $options); + } +} diff --git a/bundle/Form/FieldTypeHandler/FloatHandler.php b/bundle/Form/FieldTypeHandler/FloatHandler.php new file mode 100644 index 00000000..1a710ce9 --- /dev/null +++ b/bundle/Form/FieldTypeHandler/FloatHandler.php @@ -0,0 +1,74 @@ +fieldHelper = $fieldHelper; + } + + public function convertFieldValueToForm(Value $value, ?FieldDefinition $fieldDefinition = null): float + { + return $value->value; + } + + public function convertFieldValueFromForm($data): FloatValue + { + if (!is_numeric($data)) { + $data = null; + } + + return new FloatValue($data); + } + + protected function buildFieldForm( + FormBuilderInterface $formBuilder, + FieldDefinition $fieldDefinition, + string $languageCode, + ?Content $content = null + ): void { + $options = $this->getDefaultFieldOptions($fieldDefinition, $languageCode, $content); + + if (!empty($fieldDefinition->getValidatorConfiguration()['FloatValueValidator'])) { + $rangeConstraints = []; + + $min = $fieldDefinition->getValidatorConfiguration()['FloatValueValidator']['minFloatValue']; + $max = $fieldDefinition->getValidatorConfiguration()['FloatValueValidator']['maxFloatValue']; + + if ($min !== false) { + $rangeConstraints['min'] = $min; + } + + if ($max !== false) { + $rangeConstraints['max'] = $max; + } + + if (!empty($rangeConstraints)) { + $options['constraints'][] = new Assert\Range($rangeConstraints); + } + } + + if (!$content instanceof Content && $fieldDefinition->defaultValue instanceof FloatValue) { + $options['data'] = (float) $fieldDefinition->defaultValue->value; + } + + $formBuilder->add($fieldDefinition->identifier, NumberType::class, $options); + } +} diff --git a/bundle/Form/FieldTypeHandler/Image.php b/bundle/Form/FieldTypeHandler/Image.php new file mode 100644 index 00000000..f8f3571b --- /dev/null +++ b/bundle/Form/FieldTypeHandler/Image.php @@ -0,0 +1,62 @@ + $data->getRealPath(), + 'fileName' => $data->getClientOriginalName(), + 'fileSize' => $data->getSize(), + ]; + + return new ImageValue($imageData); + } + + protected function buildFieldForm( + FormBuilderInterface $formBuilder, + FieldDefinition $fieldDefinition, + string $languageCode, + ?Content $content = null + ): void { + $options = $this->getDefaultFieldOptions($fieldDefinition, $languageCode, $content); + + $maxFileSize = $fieldDefinition->validatorConfiguration['FileSizeValidator']['maxFileSize'] ?? false; + + if ($maxFileSize !== false) { + $options['constraints'][] = new Constraints\File( + [ + 'maxSize' => $maxFileSize, + ] + ); + } + + // Image should not be erased (updated as empty) if nothing is selected in file input + $this->skipEmptyUpdate($formBuilder, $fieldDefinition->identifier); + + $options['block_name'] = 'ibexa_forms_image'; + + $formBuilder->add($fieldDefinition->identifier, FileType::class, $options); + } +} diff --git a/bundle/Form/FieldTypeHandler/IntegerHandler.php b/bundle/Form/FieldTypeHandler/IntegerHandler.php new file mode 100644 index 00000000..6f00834d --- /dev/null +++ b/bundle/Form/FieldTypeHandler/IntegerHandler.php @@ -0,0 +1,74 @@ +fieldHelper = $fieldHelper; + } + + public function convertFieldValueToForm(Value $value, ?FieldDefinition $fieldDefinition = null): int + { + return (int) $value->value; + } + + public function convertFieldValueFromForm($data): IntegerValue\Value + { + if (!is_int($data)) { + $data = null; + } + + return new IntegerValue\Value($data); + } + + protected function buildFieldForm( + FormBuilderInterface $formBuilder, + FieldDefinition $fieldDefinition, + string $languageCode, + ?Content $content = null + ): void { + $options = $this->getDefaultFieldOptions($fieldDefinition, $languageCode, $content); + + if (!$content instanceof Content && $fieldDefinition->defaultValue instanceof IntegerValue\Value) { + $options['data'] = (int) $fieldDefinition->defaultValue->value; + } + + if (!empty($fieldDefinition->getValidatorConfiguration()['IntegerValueValidator'])) { + $rangeConstraints = []; + + $min = $fieldDefinition->getValidatorConfiguration()['IntegerValueValidator']['minIntegerValue']; + $max = $fieldDefinition->getValidatorConfiguration()['IntegerValueValidator']['maxIntegerValue']; + + if ($min !== null) { + $rangeConstraints['min'] = $min; + } + + if ($max !== null) { + $rangeConstraints['max'] = $max; + } + + if (!empty($rangeConstraints)) { + $options['constraints'][] = new Assert\Range($rangeConstraints); + } + } + + $formBuilder->add($fieldDefinition->identifier, IntegerType::class, $options); + } +} diff --git a/bundle/Form/FieldTypeHandler/Isbn.php b/bundle/Form/FieldTypeHandler/Isbn.php new file mode 100644 index 00000000..c104f871 --- /dev/null +++ b/bundle/Form/FieldTypeHandler/Isbn.php @@ -0,0 +1,52 @@ +isbn; + } + + public function convertFieldValueFromForm($data): IsbnValue + { + if (empty($data)) { + $data = ''; + } + + return new IsbnValue($data); + } + + protected function buildFieldForm( + FormBuilderInterface $formBuilder, + FieldDefinition $fieldDefinition, + string $languageCode, + ?Content $content = null + ): void { + $options = $this->getDefaultFieldOptions($fieldDefinition, $languageCode, $content); + + if ($fieldDefinition->fieldSettings['isISBN13'] ?? true) { + $options['constraints'][] = new Constraints\Isbn( + [ + 'type' => 'isbn13', + ] + ); + } else { + $options['constraints'][] = new Constraints\Isbn(); + } + + $formBuilder->add($fieldDefinition->identifier, TextType::class, $options); + } +} diff --git a/bundle/Form/FieldTypeHandler/MapLocation.php b/bundle/Form/FieldTypeHandler/MapLocation.php new file mode 100644 index 00000000..5301947b --- /dev/null +++ b/bundle/Form/FieldTypeHandler/MapLocation.php @@ -0,0 +1,54 @@ + empty($value->latitude) ? null : $value->latitude, + 'longitude' => empty($value->longitude) ? null : $value->longitude, + 'address' => empty($value->address) ? null : $value->address, + ]; + } + + public function convertFieldValueFromForm($data): ?MapLocationValue\Value + { + if (!is_array($data)) { + return null; + } + + return new MapLocationValue\Value( + [ + 'latitude' => $data['latitude'], + 'longitude' => $data['longitude'], + 'address' => $data['address'], + ] + ); + } + + protected function buildFieldForm( + FormBuilderInterface $formBuilder, + FieldDefinition $fieldDefinition, + string $languageCode, + ?Content $content = null + ): void { + $options = $this->getDefaultFieldOptions($fieldDefinition, $languageCode, $content); + + $options['block_name'] = 'ibexa_forms_map'; + + $formBuilder->add($fieldDefinition->identifier, MapType::class, $options); + } +} diff --git a/bundle/Form/FieldTypeHandler/Relation.php b/bundle/Form/FieldTypeHandler/Relation.php new file mode 100644 index 00000000..d9304055 --- /dev/null +++ b/bundle/Form/FieldTypeHandler/Relation.php @@ -0,0 +1,63 @@ +repository = $repository; + } + + public function convertFieldValueToForm(Value $value, ?FieldDefinition $fieldDefinition = null) + { + if (empty($value->destinationContentId)) { + return null; + } + + return $value->destinationContentId; + } + + protected function buildFieldForm( + FormBuilderInterface $formBuilder, + FieldDefinition $fieldDefinition, + string $languageCode, + ?Content $content = null + ): void { + $selectionRoot = $fieldDefinition->getFieldSettings()['selectionRoot']; + + if (empty($selectionRoot)) { + throw new InvalidArgumentException('SelectionRoot must be defined'); + } + + $locationService = $this->repository->getLocationService(); + $location = $locationService->loadLocation($selectionRoot); + $locationList = $locationService->loadLocationChildren($location); + + $choices = []; + foreach ($locationList->locations as $child) { + /* @var Location $child */ + $choices[$child->getContent()->getName()] = $child->contentInfo->id; + } + + $formBuilder->add($fieldDefinition->identifier, ChoiceType::class, [ + 'choices' => $choices, + 'expanded' => false, + 'multiple' => false, + ]); + } +} diff --git a/bundle/Form/FieldTypeHandler/RelationList.php b/bundle/Form/FieldTypeHandler/RelationList.php new file mode 100644 index 00000000..b5a28921 --- /dev/null +++ b/bundle/Form/FieldTypeHandler/RelationList.php @@ -0,0 +1,105 @@ +repository = $repository; + } + + public function convertFieldValueToForm(Value $value, ?FieldDefinition $fieldDefinition = null): ?array + { + if (empty($value->destinationContentIds)) { + return null; + } + + return $value->destinationContentIds; + } + + public function convertFieldValueFromForm($data): RelationListValue + { + return new RelationListValue($data); + } + + protected function buildFieldForm( + FormBuilderInterface $formBuilder, + FieldDefinition $fieldDefinition, + string $languageCode, + ?Content $content = null + ): void { + $options = $this->getDefaultFieldOptions($fieldDefinition, $languageCode, $content); + + $fieldSettings = $fieldDefinition->getFieldSettings(); + + $selectionMethod = $fieldSettings['selectionMethod']; + + $defaultLocation = $fieldSettings['selectionDefaultLocation']; + $contentTypes = $fieldSettings['selectionContentTypes']; + + /* TODO: implement different selection methods */ + switch ($fieldSettings['selectionMethod']) { + case self::MULTIPLE_SELECTION: + $locationService = $this->repository->getLocationService(); + $location = $locationService->loadLocation($defaultLocation ?: 2); + $locationList = $locationService->loadLocationChildren($location); + + $choices = []; + + /** @var \Ibexa\Contracts\Core\Repository\Values\Content\Location $child */ + foreach ($locationList->locations as $child) { + $choices[$child->getContent()->getName()] = $child->contentInfo->id; + } + + $formBuilder->add($fieldDefinition->identifier, ChoiceType::class, [ + 'choices' => $choices, + 'expanded' => false, + 'multiple' => true, + ] + $options); + + break; + + default: + $locationService = $this->repository->getLocationService(); + $location = $locationService->loadLocation($defaultLocation ?: 2); + $locationList = $locationService->loadLocationChildren($location); + + $choices = []; + + /** @var \Ibexa\Contracts\Core\Repository\Values\Content\Location $child */ + foreach ($locationList->locations as $child) { + $choices[$child->getContent()->getName()] = $child->contentInfo->id; + } + + $formBuilder->add($fieldDefinition->identifier, ChoiceType::class, [ + 'choices' => $choices, + 'expanded' => false, + 'multiple' => false, + ] + $options); + + break; + } + } +} diff --git a/bundle/Form/FieldTypeHandler/Selection.php b/bundle/Form/FieldTypeHandler/Selection.php new file mode 100644 index 00000000..431245cd --- /dev/null +++ b/bundle/Form/FieldTypeHandler/Selection.php @@ -0,0 +1,59 @@ +getFieldSettings(); + $isMultiple = $fieldSettings['isMultiple']; + } + + if (!$isMultiple) { + if (empty($value->selection)) { + return ''; + } + + return $value->selection[0]; + } + + return $value->selection; + } + + protected function buildFieldForm( + FormBuilderInterface $formBuilder, + FieldDefinition $fieldDefinition, + string $languageCode, + ?Content $content = null + ): void { + $options = $this->getDefaultFieldOptions($fieldDefinition, $languageCode, $content); + + $values = $fieldDefinition->getFieldSettings()['options']; + + $options['expanded'] = false; + $options['multiple'] = $fieldDefinition->getFieldSettings()['isMultiple']; + + $options['choices'] = array_flip($values); + + $formBuilder->add($fieldDefinition->identifier, ChoiceType::class, $options); + } +} diff --git a/bundle/Form/FieldTypeHandler/TextBlock.php b/bundle/Form/FieldTypeHandler/TextBlock.php new file mode 100644 index 00000000..2b7aef34 --- /dev/null +++ b/bundle/Form/FieldTypeHandler/TextBlock.php @@ -0,0 +1,43 @@ +text; + } + + public function convertFieldValueFromForm($data): TextBlockValue + { + if (empty($data)) { + $data = ''; + } + + return new TextBlockValue($data); + } + + protected function buildFieldForm( + FormBuilderInterface $formBuilder, + FieldDefinition $fieldDefinition, + string $languageCode, + ?Content $content = null + ): void { + $options = $this->getDefaultFieldOptions($fieldDefinition, $languageCode, $content); + + $options['attr']['rows'] = $fieldDefinition->fieldSettings['textRows']; + + $formBuilder->add($fieldDefinition->identifier, TextareaType::class, $options); + } +} diff --git a/bundle/Form/FieldTypeHandler/TextLine.php b/bundle/Form/FieldTypeHandler/TextLine.php new file mode 100644 index 00000000..22b0bbe6 --- /dev/null +++ b/bundle/Form/FieldTypeHandler/TextLine.php @@ -0,0 +1,61 @@ +text; + } + + public function convertFieldValueFromForm($data): TextLineValue + { + if (empty($data)) { + $data = ''; + } + + return new TextLineValue($data); + } + + protected function buildFieldForm( + FormBuilderInterface $formBuilder, + FieldDefinition $fieldDefinition, + string $languageCode, + ?Content $content = null + ): void { + $options = $this->getDefaultFieldOptions($fieldDefinition, $languageCode, $content); + + if (!empty($fieldDefinition->validatorConfiguration['StringLengthValidator'])) { + $lengthConstraints = []; + + $minStringLength = $fieldDefinition->validatorConfiguration['StringLengthValidator']['minStringLength']; + $maxStringLength = $fieldDefinition->validatorConfiguration['StringLengthValidator']['maxStringLength']; + + if (!empty($minStringLength)) { + $lengthConstraints['min'] = $minStringLength; + } + + if (!empty($maxStringLength)) { + $lengthConstraints['max'] = $maxStringLength; + } + + if (!empty($lengthConstraints)) { + $options['constraints'][] = new Constraints\Length($lengthConstraints); + } + } + + $formBuilder->add($fieldDefinition->identifier, TextType::class, $options); + } +} diff --git a/bundle/Form/FieldTypeHandler/Time.php b/bundle/Form/FieldTypeHandler/Time.php new file mode 100644 index 00000000..fd5afb3d --- /dev/null +++ b/bundle/Form/FieldTypeHandler/Time.php @@ -0,0 +1,59 @@ +time; + if (is_int($time)) { + return new DateTime("@{$time}"); + } + + return new DateTime(); + } + + public function convertFieldValueFromForm($data): TimeValue + { + if ($data instanceof DateTime) { + return TimeValue::fromDateTime($data); + } + + if (is_int($data)) { + return new TimeValue($data); + } + + return new TimeValue(null); + } + + protected function buildFieldForm( + FormBuilderInterface $formBuilder, + FieldDefinition $fieldDefinition, + string $languageCode, + ?Content $content = null + ): void { + $options = $this->getDefaultFieldOptions($fieldDefinition, $languageCode, $content); + + $useSeconds = $fieldDefinition->getFieldSettings()['useSeconds']; + $options['input'] = 'datetime'; + $options['widget'] = 'choice'; + $options['with_seconds'] = $useSeconds; + $options['constraints'][] = new Assert\Time(); + + $formBuilder->add($fieldDefinition->identifier, TimeType::class, $options); + } +} diff --git a/bundle/Form/FieldTypeHandler/Url.php b/bundle/Form/FieldTypeHandler/Url.php new file mode 100644 index 00000000..51c5abd7 --- /dev/null +++ b/bundle/Form/FieldTypeHandler/Url.php @@ -0,0 +1,44 @@ + $value->link, 'text' => $value->text]; + } + + public function convertFieldValueFromForm($data): UrlValue\Value + { + if (!is_array($data)) { + $data = []; + $data['url'] = null; + $data['text'] = null; + } + + return new UrlValue\Value($data['url'], $data['text']); + } + + protected function buildFieldForm( + FormBuilderInterface $formBuilder, + FieldDefinition $fieldDefinition, + string $languageCode, + ?Content $content = null + ): void { + $options = $this->getDefaultFieldOptions($fieldDefinition, $languageCode, $content); + + $formBuilder->add($fieldDefinition->identifier, UrlType::class, $options); + } +} diff --git a/bundle/Form/FieldTypeHandler/User.php b/bundle/Form/FieldTypeHandler/User.php new file mode 100644 index 00000000..f04595e3 --- /dev/null +++ b/bundle/Form/FieldTypeHandler/User.php @@ -0,0 +1,42 @@ +getDefaultFieldOptions($fieldDefinition, $languageCode); + + $formBuilder->add($fieldDefinition->identifier, UserCreateType::class, $options); + } + + public function buildFieldUpdateForm( + FormBuilderInterface $formBuilder, + FieldDefinition $fieldDefinition, + Content $content, + string $languageCode + ): void { + $options = $this->getDefaultFieldOptions($fieldDefinition, $languageCode, $content); + + $formBuilder->add($fieldDefinition->identifier, UserUpdateType::class, $options); + } +} diff --git a/bundle/Form/FieldTypeHandlerInterface.php b/bundle/Form/FieldTypeHandlerInterface.php new file mode 100644 index 00000000..a623c9f2 --- /dev/null +++ b/bundle/Form/FieldTypeHandlerInterface.php @@ -0,0 +1,57 @@ +map = $map; + } + + /** + * Register a $service for FieldType $identifier. + * + * @param \Netgen\Bundle\InformationCollectionBundle\Form\FieldTypeHandlerInterface|callable $handler + */ + public function register(string $identifier, $handler): void + { + $this->map[$identifier] = $handler; + } + + /** + * Returns a FieldTypeHandlerInterface for FieldType $identifier. + * + * @throws \OutOfBoundsException + * @throws \RuntimeException When type is not a FieldTypeHandlerInterface instance nor a callable factory + */ + public function get(string $identifier): FieldTypeHandlerInterface + { + if (!isset($this->map[$identifier])) { + throw new OutOfBoundsException("No handler registered for FieldType '{$identifier}'."); + } + if (!$this->map[$identifier] instanceof FieldTypeHandlerInterface) { + if (!is_callable($this->map[$identifier])) { + throw new RuntimeException("FieldTypeHandler '{$identifier}' is not callable nor instance"); + } + + $factory = $this->map[$identifier]; + $this->map[$identifier] = $factory(); + + if (!$this->map[$identifier] instanceof FieldTypeHandlerInterface) { + throw new RuntimeException( + "FieldTypeHandler '{$identifier}' callable did not return a FieldTypeHandlerInterface instance, " . + 'instead: ' . gettype($this->map[$identifier]) + ); + } + } + + return $this->map[$identifier]; + } +} diff --git a/bundle/Form/InformationCollectionUpdateType.php b/bundle/Form/InformationCollectionUpdateType.php index 69aefb03..80fa898d 100644 --- a/bundle/Form/InformationCollectionUpdateType.php +++ b/bundle/Form/InformationCollectionUpdateType.php @@ -6,10 +6,8 @@ use eZ\Publish\API\Repository\Values\ContentType\ContentType; use Ibexa\Contracts\Core\SiteAccess\ConfigResolverInterface; -use Netgen\Bundle\IbexaFormsBundle\Form\DataWrapper; -use Netgen\Bundle\IbexaFormsBundle\Form\FieldTypeHandlerRegistry; -use Netgen\Bundle\IbexaFormsBundle\Form\Payload\InformationCollectionStruct; -use Netgen\Bundle\IbexaFormsBundle\Form\Type\AbstractContentType; +use Netgen\Bundle\InformationCollectionBundle\Form\Payload\InformationCollectionStruct; +use Netgen\Bundle\InformationCollectionBundle\Form\Type\AbstractContentType; use Netgen\InformationCollection\API\Value\Collection; use RuntimeException; use Symfony\Component\Form\DataMapperInterface; diff --git a/bundle/Form/Payload/InformationCollectionStruct.php b/bundle/Form/Payload/InformationCollectionStruct.php new file mode 100644 index 00000000..3a7e36a0 --- /dev/null +++ b/bundle/Form/Payload/InformationCollectionStruct.php @@ -0,0 +1,41 @@ +collectedData[$fieldDefIdentifier] ?? null; + } + + /** + * This method returns the complete fields collection. + */ + public function getCollectedFields(): array + { + return $this->collectedData; + } + + /** + * Sets value for $fieldDefIdentifier. + * + * @param mixed $value + */ + public function setCollectedFieldValue(string $fieldDefIdentifier, $value): void + { + $this->collectedData[$fieldDefIdentifier] = $value; + } +} diff --git a/bundle/Form/Type/AbstractContentType.php b/bundle/Form/Type/AbstractContentType.php new file mode 100644 index 00000000..2c624ff2 --- /dev/null +++ b/bundle/Form/Type/AbstractContentType.php @@ -0,0 +1,22 @@ +fieldTypeHandlerRegistry = $fieldTypeHandlerRegistry; + $this->dataMapper = $dataMapper; + } +} diff --git a/bundle/Form/Type/FieldType/UserCreateType.php b/bundle/Form/Type/FieldType/UserCreateType.php new file mode 100644 index 00000000..269ee27c --- /dev/null +++ b/bundle/Form/Type/FieldType/UserCreateType.php @@ -0,0 +1,57 @@ + 'E-mail address', + 'constraints' => [ + new Constraints\NotBlank(), + new Constraints\Email(), + ], + ]; + + $usernameOptions = [ + 'label' => 'Username', + 'constraints' => [ + new Constraints\NotBlank(), + ], + ]; + + $passwordOptions = [ + 'type' => PasswordType::class, + 'invalid_message' => 'Both passwords must match.', + 'options' => [ + 'constraints' => $this->getPasswordConstraints($options['ibexa_forms']['fielddefinition'] ?? null), + ], + 'first_options' => [ + 'label' => 'Password', + ], + 'second_options' => [ + 'label' => 'Repeat password', + ], + ]; + + $builder + ->add('email', EmailType::class, $emailOptions) + ->add('username', TextType::class, $usernameOptions) + ->add('password', RepeatedType::class, $passwordOptions); + } + + public function getBlockPrefix(): string + { + return 'ibexa_forms_ezuser_create'; + } +} diff --git a/bundle/Form/Type/FieldType/UserType.php b/bundle/Form/Type/FieldType/UserType.php new file mode 100644 index 00000000..40a05cb2 --- /dev/null +++ b/bundle/Form/Type/FieldType/UserType.php @@ -0,0 +1,73 @@ +validatorConfiguration['PasswordValueValidator']; + + if ($passwordValidator['requireAtLeastOneUpperCaseCharacter'] ?? false) { + $passwordConstraints[] = new Constraints\Regex( + [ + 'pattern' => '/[A-Z]+/', + 'message' => 'Password must contain at least one upper-case character', + ] + ); + } + + if ($passwordValidator['requireAtLeastOneLowerCaseCharacter'] ?? false) { + $passwordConstraints[] = new Constraints\Regex( + [ + 'pattern' => '/[a-z]+/', + 'message' => 'Password must contain at least one lower-case character', + ] + ); + } + + if ($passwordValidator['requireAtLeastOneNumericCharacter'] ?? false) { + $passwordConstraints[] = new Constraints\Regex( + [ + 'pattern' => '/\d+/', + 'message' => 'Password must contain at least one numeric character', + ] + ); + } + + if ($passwordValidator['requireAtLeastOneNonAlphanumericCharacter'] ?? false) { + $passwordConstraints[] = new Constraints\Regex( + [ + 'pattern' => '/\W+/', + 'message' => 'Password must contain at least one non-alphanumeric character', + ] + ); + } + + if (($passwordValidator['minLength'] ?? 0) > 0) { + $passwordConstraints[] = new Constraints\Length( + [ + 'min' => $passwordValidator['minLength'], + ] + ); + } + + return $passwordConstraints; + } +} diff --git a/bundle/Form/Type/FieldType/UserUpdateType.php b/bundle/Form/Type/FieldType/UserUpdateType.php new file mode 100644 index 00000000..d6fe2857 --- /dev/null +++ b/bundle/Form/Type/FieldType/UserUpdateType.php @@ -0,0 +1,50 @@ + 'E-mail address', + 'constraints' => [ + new Constraints\NotBlank(), + new Constraints\Email(), + ], + ]; + + $passwordOptions = [ + 'type' => PasswordType::class, + // Setting required to false enables passing empty passwords for no update + 'required' => false, + 'invalid_message' => 'Both passwords must match.', + 'options' => [ + 'constraints' => $this->getPasswordConstraints($options['ibexa_forms']['fielddefinition'] ?? null, false), + ], + 'first_options' => [ + 'label' => 'New password (leave empty to keep current password)', + ], + 'second_options' => [ + 'label' => 'Repeat new password', + ], + ]; + + $builder + ->add('email', EmailType::class, $emailOptions) + ->add('password', RepeatedType::class, $passwordOptions); + } + + public function getBlockPrefix(): string + { + return 'ibexa_forms_ezuser_update'; + } +} diff --git a/bundle/Form/Type/MapType.php b/bundle/Form/Type/MapType.php new file mode 100644 index 00000000..d5b33647 --- /dev/null +++ b/bundle/Form/Type/MapType.php @@ -0,0 +1,33 @@ +add('address', TextType::class, [ + 'label' => 'ibexa_forms.form.map.address.label', + ]); + + $builder->add('latitude', NumberType::class, [ + 'label' => 'ibexa_forms.form.map.latitude.label', + ]); + + $builder->add('longitude', NumberType::class, [ + 'label' => 'ibexa_forms.form.map.longitude.label', + ]); + } + + public function getBlockPrefix(): string + { + return 'ibexa_forms_map'; + } +} diff --git a/bundle/Form/Type/UrlType.php b/bundle/Form/Type/UrlType.php new file mode 100644 index 00000000..31a628a1 --- /dev/null +++ b/bundle/Form/Type/UrlType.php @@ -0,0 +1,32 @@ +add( + 'url', + CoreUrlType::class, + [ + 'constraints' => new Assert\Url(), + ] + ); + + $builder->add('text', TextType::class); + } + + public function getBlockPrefix(): string + { + return 'ibexa_forms_url'; + } +} diff --git a/composer.json b/composer.json index 01e27a72..595f74b6 100644 --- a/composer.json +++ b/composer.json @@ -29,7 +29,6 @@ "ibexa/admin-ui": "^4.0", "ibexa/content-forms": "^4.0", "ibexa/core": "^4.0", - "netgen/ibexa-forms-bundle": "^4.0", "symfony/swiftmailer-bundle": "^3.4", "twig/twig": "^3.0", "google/recaptcha": "^1.2", diff --git a/doc/cookbook/override_something_on_form.rst b/doc/cookbook/override_something_on_form.rst index 4e266eee..2c3d07dd 100644 --- a/doc/cookbook/override_something_on_form.rst +++ b/doc/cookbook/override_something_on_form.rst @@ -10,7 +10,7 @@ How to override something on info collector form namespace Acme\Form; use Acme\Validator\Constraints\MyValidator; - use Netgen\Bundle\IbexaFormsBundle\Form\Type\InformationCollectionType; + use Netgen\Bundle\InformationCollectionBundle\Form\Type\InformationCollectionType; use Netgen\Bundle\EzPlatformSiteApiBundle\View\ContentValueView; use Symfony\Component\Form\AbstractTypeExtension; use Symfony\Component\Form\Extension\Core\Type\TextType; @@ -63,4 +63,4 @@ How to override something on info collector form arguments: - '@request_stack' tags: - - { name: form.type_extension, extended_type: Netgen\Bundle\IbexaFormsBundle\Form\Type\InformationCollectionType } + - { name: form.type_extension, extended_type: Netgen\Bundle\InformationCollectionBundle\Form\Type\InformationCollectionType } diff --git a/tests/old/Controller/InformationCollectionControllerTest.php b/tests/old/Controller/InformationCollectionControllerTest.php index 9cf5b375..c832a699 100644 --- a/tests/old/Controller/InformationCollectionControllerTest.php +++ b/tests/old/Controller/InformationCollectionControllerTest.php @@ -4,8 +4,8 @@ use Ibexa\Core\MVC\Symfony\View\ContentView; use Ibexa\Core\Repository\Values\Content\Location; -use Netgen\Bundle\IbexaFormsBundle\Form\DataWrapper; -use Netgen\Bundle\IbexaFormsBundle\Form\Payload\InformationCollectionStruct; +use Netgen\Bundle\InformationCollectionBundle\Form\DataWrapper; +use Netgen\Bundle\InformationCollectionBundle\Form\Payload\InformationCollectionStruct; use Netgen\Bundle\InformationCollectionBundle\Controller\InformationCollectionController; use Netgen\Bundle\InformationCollectionBundle\Form\Builder\FormBuilder; use Netgen\Bundle\InformationCollectionBundle\Tests\ContentViewStub; diff --git a/tests/old/Factory/EmailDataFactoryTest.php b/tests/old/Factory/EmailDataFactoryTest.php index d54000c5..2b42d25b 100644 --- a/tests/old/Factory/EmailDataFactoryTest.php +++ b/tests/old/Factory/EmailDataFactoryTest.php @@ -13,8 +13,8 @@ use Ibexa\Core\Repository\Values\Content\Location; use Ibexa\Core\Repository\Values\Content\VersionInfo; use Ibexa\Core\Repository\Values\ContentType\ContentType; -use Netgen\Bundle\IbexaFormsBundle\Form\DataWrapper; -use Netgen\Bundle\IbexaFormsBundle\Form\Payload\InformationCollectionStruct; +use Netgen\Bundle\InformationCollectionBundle\Form\DataWrapper; +use Netgen\Bundle\InformationCollectionBundle\Form\Payload\InformationCollectionStruct; use Netgen\Bundle\InformationCollectionBundle\Event\InformationCollected; use Netgen\Bundle\InformationCollectionBundle\Factory\EmailDataFactory; use Netgen\Bundle\InformationCollectionBundle\Value\EmailData; From 6f0f39444d41a469dfe2da5591a8e9e13514cf4d Mon Sep 17 00:00:00 2001 From: Marijan Klaric Date: Mon, 18 Mar 2024 12:02:22 +0100 Subject: [PATCH 41/87] CED-1124 set right arguments --- lib/Resources/config/admin.yml | 4 ++-- lib/Resources/config/services.yml | 3 +++ 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/Resources/config/admin.yml b/lib/Resources/config/admin.yml index 5b94b19b..5eaff537 100644 --- a/lib/Resources/config/admin.yml +++ b/lib/Resources/config/admin.yml @@ -63,13 +63,13 @@ services: class: Netgen\Bundle\InformationCollectionBundle\Form\DataMapper\InformationCollectionUpdateMapper public: false arguments: - - "@netgen.ibexa_forms.form.fieldtype_handler_registry" + - "@netgen_information_collection.form.fieldtype_handler_registry" netgen_information_collection.form.type.information_collection_update: class: Netgen\Bundle\InformationCollectionBundle\Form\InformationCollectionUpdateType # public: false arguments: - - "@netgen.ibexa_forms.form.fieldtype_handler_registry" + - "@netgen_information_collection.form.fieldtype_handler_registry" - "@netgen_information_collection.form.data_mapper.info_collection_update" - "@ibexa.config.resolver" tags: diff --git a/lib/Resources/config/services.yml b/lib/Resources/config/services.yml index cdbe316c..de18f5c1 100644 --- a/lib/Resources/config/services.yml +++ b/lib/Resources/config/services.yml @@ -116,3 +116,6 @@ services: - '@netgen_information_collection.captcha.service' tags: - { name: twig.runtime } + + netgen_information_collection.form.fieldtype_handler_registry: + class: Netgen\Bundle\InformationCollectionBundle\Form\FieldTypeHandlerRegistry From 760b953bfc28a36e922ebb74c2cd1be650e5a64e Mon Sep 17 00:00:00 2001 From: Marijan Klaric Date: Mon, 18 Mar 2024 14:07:45 +0100 Subject: [PATCH 42/87] CED-1124 add form_fieldtype_handlers.yaml --- .../config/form_fieldtype_handlers.yaml | 104 ++++++++++++++++++ 1 file changed, 104 insertions(+) create mode 100644 lib/Resources/config/form_fieldtype_handlers.yaml diff --git a/lib/Resources/config/form_fieldtype_handlers.yaml b/lib/Resources/config/form_fieldtype_handlers.yaml new file mode 100644 index 00000000..ec786356 --- /dev/null +++ b/lib/Resources/config/form_fieldtype_handlers.yaml @@ -0,0 +1,104 @@ +services: + netgen_information_collection.form.fieldtype_handler.ezimage: + class: Netgen\Bundle\InformationCollection\Form\FieldTypeHandler\Image + tags: + - { name: netgen_information_collection.form.fieldtype_handler, alias: ezimage } + + netgen_information_collection.form.fieldtype_handler.ezstring: + class: Netgen\Bundle\InformationCollection\Form\FieldTypeHandler\TextLine + tags: + - { name: netgen_information_collection.form.fieldtype_handler, alias: ezstring } + + netgen_information_collection.form.fieldtype_handler.eztext: + class: Netgen\Bundle\InformationCollection\Form\FieldTypeHandler\TextBlock + tags: + - { name: netgen_information_collection.form.fieldtype_handler, alias: eztext } + + netgen_information_collection.form.fieldtype_handler.ezuser: + class: Netgen\Bundle\InformationCollection\Form\FieldTypeHandler\User + tags: + - { name: netgen_information_collection.form.fieldtype_handler, alias: ezuser } + + netgen_information_collection.form.fieldtype_handler.ezemail: + class: Netgen\Bundle\InformationCollection\Form\FieldTypeHandler\Email + tags: + - { name: netgen_information_collection.form.fieldtype_handler, alias: ezemail } + + netgen_information_collection.form.fieldtype_handler.ezselection: + class: Netgen\Bundle\InformationCollection\Form\FieldTypeHandler\Selection + tags: + - { name: netgen_information_collection.form.fieldtype_handler, alias: ezselection } + + netgen_information_collection.form.fieldtype_handler.ezboolean: + class: Netgen\Bundle\InformationCollection\Form\FieldTypeHandler\Checkbox + arguments: [ "@Ibexa\\Core\\Helper\\FieldHelper" ] + tags: + - { name: netgen_information_collection.form.fieldtype_handler, alias: ezboolean } + + netgen_information_collection.form.fieldtype_handler.ezdate: + class: Netgen\Bundle\InformationCollection\Form\FieldTypeHandler\Date + tags: + - { name: netgen_information_collection.form.fieldtype_handler, alias: ezdate } + + netgen_information_collection.form.fieldtype_handler.ezdatetime: + class: Netgen\Bundle\IbexaFormsBundle\Form\FieldTypeHandler\DateAndTime + tags: + - { name: netgen_information_collection.form.fieldtype_handler, alias: ezdatetime } + + netgen_information_collection.form.fieldtype_handler.ezinteger: + class: Netgen\Bundle\IbexaFormsBundle\Form\FieldTypeHandler\IntegerHandler + arguments: [ "@Ibexa\\Core\\Helper\\FieldHelper" ] + tags: + - {name: netgen_information_collection.form.fieldtype_handler, alias: ezinteger} + + netgen_information_collection.form.fieldtype_handler.ezfloat: + class: Netgen\Bundle\IbexaFormsBundle\Form\FieldTypeHandler\FloatHandler + arguments: [ "@Ibexa\\Core\\Helper\\FieldHelper" ] + tags: + - { name: netgen_information_collection.form.fieldtype_handler, alias: ezfloat } + + netgen_information_collection.form.fieldtype_handler.ezurl: + class: Netgen\Bundle\IbexaFormsBundle\Form\FieldTypeHandler\Url + tags: + - { name: netgen_information_collection.form.fieldtype_handler, alias: ezurl } + + netgen_information_collection.form.fieldtype_handler.ezcountry: + class: Netgen\Bundle\IbexaFormsBundle\Form\FieldTypeHandler\Country + arguments: + - "%ibexa.field_type.country.data%" + tags: + - { name: netgen_information_collection.form.fieldtype_handler, alias: ezcountry } + + netgen_information_collection.form.fieldtype_handler.eztime: + class: Netgen\Bundle\IbexaFormsBundle\Form\FieldTypeHandler\Time + tags: + - { name: netgen_information_collection.form.fieldtype_handler, alias: eztime } + + netgen_information_collection.form.fieldtype_handler.ezisbn: + class: Netgen\Bundle\IbexaFormsBundle\Form\FieldTypeHandler\Isbn + tags: + - { name: netgen_information_collection.form.fieldtype_handler, alias: ezisbn } + + netgen_information_collection.form.fieldtype_handler.ezbinaryfile: + class: Netgen\Bundle\IbexaFormsBundle\Form\FieldTypeHandler\BinaryFile + tags: + - { name: netgen_information_collection.form.fieldtype_handler, alias: ezbinaryfile } + + netgen_information_collection.form.fieldtype_handler.ezgmaplocation: + class: Netgen\Bundle\IbexaFormsBundle\Form\FieldTypeHandler\MapLocation + tags: + - { name: netgen_information_collection.form.fieldtype_handler, alias: ezgmaplocation } + + netgen_information_collection.form.fieldtype_handler.ezobjectrelation: + class: Netgen\Bundle\IbexaFormsBundle\Form\FieldTypeHandler\Relation + arguments: + - "@ibexa.api.repository" + tags: + - { name: netgen_information_collection.form.fieldtype_handler, alias: ezobjectrelation } + + netgen_information_collection.form.fieldtype_handler.ezobjectrelationlist: + class: Netgen\Bundle\IbexaFormsBundle\Form\FieldTypeHandler\RelationList + arguments: + - "@ibexa.api.repository" + tags: + - { name: netgen_information_collection.form.fieldtype_handler, alias: ezobjectrelationlist } From 1deef6bc71f12179d81c16a5157ef7b46dbedd8f Mon Sep 17 00:00:00 2001 From: Marijan Klaric Date: Mon, 18 Mar 2024 14:46:45 +0100 Subject: [PATCH 43/87] CED-1124 add FieldTypeHandlerRegistryPass.php --- .../Compiler/FieldTypeHandlerRegistryPass.php | 41 +++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 bundle/DependencyInjection/Compiler/FieldTypeHandlerRegistryPass.php diff --git a/bundle/DependencyInjection/Compiler/FieldTypeHandlerRegistryPass.php b/bundle/DependencyInjection/Compiler/FieldTypeHandlerRegistryPass.php new file mode 100644 index 00000000..23c4ce7e --- /dev/null +++ b/bundle/DependencyInjection/Compiler/FieldTypeHandlerRegistryPass.php @@ -0,0 +1,41 @@ +hasDefinition('netgen_information_collection.form.fieldtype_handler_registry')) { + return; + } + + $registry = $container->getDefinition('netgen_information_collection.form.fieldtype_handler_registry'); + + foreach ($container->findTaggedServiceIds('netgen_information_collection.form.fieldtype_handler') as $id => $attributes) { + foreach ($attributes as $attribute) { + if (!isset($attribute['alias'])) { + throw new LogicException( + "'netgen_information_collection.form.fieldtype_handler' service tag " . + "needs an 'alias' attribute to identify the field type. None given." + ); + } + + $registry->addMethodCall( + 'register', + [ + $attribute['alias'], + new Reference($id), + ] + ); + } + } + } +} From 852d03a26453e29b6c6b422ae24eb352abd4c48d Mon Sep 17 00:00:00 2001 From: Marijan Klaric Date: Mon, 18 Mar 2024 14:57:28 +0100 Subject: [PATCH 44/87] CED-1124 register FieldTypeHandlerRegistryPass.php --- bundle/NetgenInformationCollectionBundle.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/bundle/NetgenInformationCollectionBundle.php b/bundle/NetgenInformationCollectionBundle.php index b11eaedf..c638babe 100644 --- a/bundle/NetgenInformationCollectionBundle.php +++ b/bundle/NetgenInformationCollectionBundle.php @@ -3,6 +3,7 @@ namespace Netgen\Bundle\InformationCollectionBundle; use Ibexa\Bundle\Core\DependencyInjection\IbexaCoreExtension; +use Netgen\Bundle\InformationCollectionBundle\DependencyInjection\Compiler\FieldTypeHandlerRegistryPass; use Netgen\Bundle\InformationCollectionBundle\Ibexa\PolicyProvider\InformationCollectionPolicyProvider; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\HttpKernel\Bundle\Bundle; @@ -11,6 +12,7 @@ class NetgenInformationCollectionBundle extends Bundle { public function build(ContainerBuilder $container): void { + $container->addCompilerPass(new FieldTypeHandlerRegistryPass()); parent::build($container); $ibexaExtension = $container->getExtension('ibexa'); From bdf85a97fdd17abbb572ae2825cfc72c6a292e4c Mon Sep 17 00:00:00 2001 From: Marijan Klaric Date: Tue, 19 Mar 2024 10:26:21 +0100 Subject: [PATCH 45/87] CED-1124 adjustments to work with old FieldTypeHandler --- .../Compiler/FieldTypeHandlerRegistryPass.php | 4 +- bundle/Form/FieldTypeHandlerRegistry.php | 7 +- .../config/form_fieldtype_handlers.yaml | 80 +++++++++---------- lib/Resources/config/services.yml | 1 + 4 files changed, 47 insertions(+), 45 deletions(-) diff --git a/bundle/DependencyInjection/Compiler/FieldTypeHandlerRegistryPass.php b/bundle/DependencyInjection/Compiler/FieldTypeHandlerRegistryPass.php index 23c4ce7e..e9a63e9c 100644 --- a/bundle/DependencyInjection/Compiler/FieldTypeHandlerRegistryPass.php +++ b/bundle/DependencyInjection/Compiler/FieldTypeHandlerRegistryPass.php @@ -19,11 +19,11 @@ public function process(ContainerBuilder $container): void $registry = $container->getDefinition('netgen_information_collection.form.fieldtype_handler_registry'); - foreach ($container->findTaggedServiceIds('netgen_information_collection.form.fieldtype_handler') as $id => $attributes) { + foreach ($container->findTaggedServiceIds('netgen.ibexa_forms.form.fieldtype_handler') as $id => $attributes) { foreach ($attributes as $attribute) { if (!isset($attribute['alias'])) { throw new LogicException( - "'netgen_information_collection.form.fieldtype_handler' service tag " . + "'netgen.ibexa_forms.form.fieldtype_handler' service tag " . "needs an 'alias' attribute to identify the field type. None given." ); } diff --git a/bundle/Form/FieldTypeHandlerRegistry.php b/bundle/Form/FieldTypeHandlerRegistry.php index 01281162..ae251dfe 100644 --- a/bundle/Form/FieldTypeHandlerRegistry.php +++ b/bundle/Form/FieldTypeHandlerRegistry.php @@ -43,12 +43,13 @@ public function register(string $identifier, $handler): void * @throws \OutOfBoundsException * @throws \RuntimeException When type is not a FieldTypeHandlerInterface instance nor a callable factory */ - public function get(string $identifier): FieldTypeHandlerInterface + public function get(string $identifier): FieldTypeHandlerInterface|\Netgen\Bundle\IbexaFormsBundle\Form\FieldTypeHandlerInterface { if (!isset($this->map[$identifier])) { throw new OutOfBoundsException("No handler registered for FieldType '{$identifier}'."); } - if (!$this->map[$identifier] instanceof FieldTypeHandlerInterface) { + if (!$this->map[$identifier] instanceof FieldTypeHandlerInterface && !$this->map[$identifier] instanceof \Netgen\Bundle\IbexaFormsBundle\Form\FieldTypeHandlerInterface) { + if (!is_callable($this->map[$identifier])) { throw new RuntimeException("FieldTypeHandler '{$identifier}' is not callable nor instance"); } @@ -56,7 +57,7 @@ public function get(string $identifier): FieldTypeHandlerInterface $factory = $this->map[$identifier]; $this->map[$identifier] = $factory(); - if (!$this->map[$identifier] instanceof FieldTypeHandlerInterface) { + if (!$this->map[$identifier] instanceof FieldTypeHandlerInterface && !$this->map[$identifier] instanceof \Netgen\Bundle\IbexaFormsBundle\Form\FieldTypeHandlerInterface) { throw new RuntimeException( "FieldTypeHandler '{$identifier}' callable did not return a FieldTypeHandlerInterface instance, " . 'instead: ' . gettype($this->map[$identifier]) diff --git a/lib/Resources/config/form_fieldtype_handlers.yaml b/lib/Resources/config/form_fieldtype_handlers.yaml index ec786356..84eee398 100644 --- a/lib/Resources/config/form_fieldtype_handlers.yaml +++ b/lib/Resources/config/form_fieldtype_handlers.yaml @@ -1,104 +1,104 @@ services: netgen_information_collection.form.fieldtype_handler.ezimage: - class: Netgen\Bundle\InformationCollection\Form\FieldTypeHandler\Image + class: Netgen\Bundle\InformationCollectionBundle\Form\FieldTypeHandler\Image tags: - - { name: netgen_information_collection.form.fieldtype_handler, alias: ezimage } + - { name: netgen.ibexa_forms.form.fieldtype_handler, alias: ezimage } netgen_information_collection.form.fieldtype_handler.ezstring: - class: Netgen\Bundle\InformationCollection\Form\FieldTypeHandler\TextLine + class: Netgen\Bundle\InformationCollectionBundle\Form\FieldTypeHandler\TextLine tags: - - { name: netgen_information_collection.form.fieldtype_handler, alias: ezstring } + - { name: netgen.ibexa_forms.form.fieldtype_handler, alias: ezstring } netgen_information_collection.form.fieldtype_handler.eztext: - class: Netgen\Bundle\InformationCollection\Form\FieldTypeHandler\TextBlock + class: Netgen\Bundle\InformationCollectionBundle\Form\FieldTypeHandler\TextBlock tags: - - { name: netgen_information_collection.form.fieldtype_handler, alias: eztext } + - { name: netgen.ibexa_forms.form.fieldtype_handler, alias: eztext } netgen_information_collection.form.fieldtype_handler.ezuser: - class: Netgen\Bundle\InformationCollection\Form\FieldTypeHandler\User + class: Netgen\Bundle\InformationCollectionBundle\Form\FieldTypeHandler\User tags: - - { name: netgen_information_collection.form.fieldtype_handler, alias: ezuser } + - { name: netgen.ibexa_forms.form.fieldtype_handler, alias: ezuser } netgen_information_collection.form.fieldtype_handler.ezemail: - class: Netgen\Bundle\InformationCollection\Form\FieldTypeHandler\Email + class: Netgen\Bundle\InformationCollectionBundle\Form\FieldTypeHandler\Email tags: - - { name: netgen_information_collection.form.fieldtype_handler, alias: ezemail } + - { name: netgen.ibexa_forms.form.fieldtype_handler, alias: ezemail } netgen_information_collection.form.fieldtype_handler.ezselection: - class: Netgen\Bundle\InformationCollection\Form\FieldTypeHandler\Selection + class: Netgen\Bundle\InformationCollectionBundle\Form\FieldTypeHandler\Selection tags: - - { name: netgen_information_collection.form.fieldtype_handler, alias: ezselection } + - { name: netgen.ibexa_forms.form.fieldtype_handler, alias: ezselection } netgen_information_collection.form.fieldtype_handler.ezboolean: - class: Netgen\Bundle\InformationCollection\Form\FieldTypeHandler\Checkbox + class: Netgen\Bundle\InformationCollectionBundle\Form\FieldTypeHandler\Checkbox arguments: [ "@Ibexa\\Core\\Helper\\FieldHelper" ] tags: - - { name: netgen_information_collection.form.fieldtype_handler, alias: ezboolean } + - { name: netgen.ibexa_forms.form.fieldtype_handler, alias: ezboolean } netgen_information_collection.form.fieldtype_handler.ezdate: - class: Netgen\Bundle\InformationCollection\Form\FieldTypeHandler\Date + class: Netgen\Bundle\InformationCollectionBundle\Form\FieldTypeHandler\Date tags: - - { name: netgen_information_collection.form.fieldtype_handler, alias: ezdate } + - { name: netgen.ibexa_forms.form.fieldtype_handler, alias: ezdate } netgen_information_collection.form.fieldtype_handler.ezdatetime: - class: Netgen\Bundle\IbexaFormsBundle\Form\FieldTypeHandler\DateAndTime + class: Netgen\Bundle\InformationCollectionBundle\Form\FieldTypeHandler\DateAndTime tags: - - { name: netgen_information_collection.form.fieldtype_handler, alias: ezdatetime } + - { name: netgen.ibexa_forms.form.fieldtype_handler, alias: ezdatetime } netgen_information_collection.form.fieldtype_handler.ezinteger: - class: Netgen\Bundle\IbexaFormsBundle\Form\FieldTypeHandler\IntegerHandler + class: Netgen\Bundle\InformationCollectionBundle\Form\FieldTypeHandler\IntegerHandler arguments: [ "@Ibexa\\Core\\Helper\\FieldHelper" ] tags: - - {name: netgen_information_collection.form.fieldtype_handler, alias: ezinteger} + - {name: netgen.ibexa_forms.form.fieldtype_handler, alias: ezinteger} netgen_information_collection.form.fieldtype_handler.ezfloat: - class: Netgen\Bundle\IbexaFormsBundle\Form\FieldTypeHandler\FloatHandler + class: Netgen\Bundle\InformationCollectionBundle\Form\FieldTypeHandler\FloatHandler arguments: [ "@Ibexa\\Core\\Helper\\FieldHelper" ] tags: - - { name: netgen_information_collection.form.fieldtype_handler, alias: ezfloat } + - { name: netgen.ibexa_forms.form.fieldtype_handler, alias: ezfloat } netgen_information_collection.form.fieldtype_handler.ezurl: - class: Netgen\Bundle\IbexaFormsBundle\Form\FieldTypeHandler\Url + class: Netgen\Bundle\InformationCollectionBundle\Form\FieldTypeHandler\Url tags: - - { name: netgen_information_collection.form.fieldtype_handler, alias: ezurl } + - { name: netgen.ibexa_forms.form.fieldtype_handler, alias: ezurl } netgen_information_collection.form.fieldtype_handler.ezcountry: - class: Netgen\Bundle\IbexaFormsBundle\Form\FieldTypeHandler\Country + class: Netgen\Bundle\InformationCollectionBundle\Form\FieldTypeHandler\Country arguments: - "%ibexa.field_type.country.data%" tags: - - { name: netgen_information_collection.form.fieldtype_handler, alias: ezcountry } + - { name: netgen.ibexa_forms.form.fieldtype_handler, alias: ezcountry } netgen_information_collection.form.fieldtype_handler.eztime: - class: Netgen\Bundle\IbexaFormsBundle\Form\FieldTypeHandler\Time + class: Netgen\Bundle\InformationCollectionBundle\Form\FieldTypeHandler\Time tags: - - { name: netgen_information_collection.form.fieldtype_handler, alias: eztime } + - { name: netgen.ibexa_forms.form.fieldtype_handler, alias: eztime } netgen_information_collection.form.fieldtype_handler.ezisbn: - class: Netgen\Bundle\IbexaFormsBundle\Form\FieldTypeHandler\Isbn + class: Netgen\Bundle\InformationCollectionBundle\Form\FieldTypeHandler\Isbn tags: - - { name: netgen_information_collection.form.fieldtype_handler, alias: ezisbn } + - { name: netgen.ibexa_forms.form.fieldtype_handler, alias: ezisbn } netgen_information_collection.form.fieldtype_handler.ezbinaryfile: - class: Netgen\Bundle\IbexaFormsBundle\Form\FieldTypeHandler\BinaryFile + class: Netgen\Bundle\InformationCollectionBundle\Form\FieldTypeHandler\BinaryFile tags: - - { name: netgen_information_collection.form.fieldtype_handler, alias: ezbinaryfile } + - { name: netgen.ibexa_forms.form.fieldtype_handler, alias: ezbinaryfile } netgen_information_collection.form.fieldtype_handler.ezgmaplocation: - class: Netgen\Bundle\IbexaFormsBundle\Form\FieldTypeHandler\MapLocation + class: Netgen\Bundle\InformationCollectionBundle\Form\FieldTypeHandler\MapLocation tags: - - { name: netgen_information_collection.form.fieldtype_handler, alias: ezgmaplocation } + - { name: netgen.ibexa_forms.form.fieldtype_handler, alias: ezgmaplocation } netgen_information_collection.form.fieldtype_handler.ezobjectrelation: - class: Netgen\Bundle\IbexaFormsBundle\Form\FieldTypeHandler\Relation + class: Netgen\Bundle\InformationCollectionBundle\Form\FieldTypeHandler\Relation arguments: - - "@ibexa.api.repository" + - "@ibexa.api.repository" tags: - - { name: netgen_information_collection.form.fieldtype_handler, alias: ezobjectrelation } + - { name: netgen.ibexa_forms.form.fieldtype_handler, alias: ezobjectrelation } netgen_information_collection.form.fieldtype_handler.ezobjectrelationlist: - class: Netgen\Bundle\IbexaFormsBundle\Form\FieldTypeHandler\RelationList + class: Netgen\Bundle\InformationCollectionBundle\Form\FieldTypeHandler\RelationList arguments: - - "@ibexa.api.repository" + - "@ibexa.api.repository" tags: - - { name: netgen_information_collection.form.fieldtype_handler, alias: ezobjectrelationlist } + - { name: netgen.ibexa_forms.form.fieldtype_handler, alias: ezobjectrelationlist } diff --git a/lib/Resources/config/services.yml b/lib/Resources/config/services.yml index de18f5c1..d25bd9d8 100644 --- a/lib/Resources/config/services.yml +++ b/lib/Resources/config/services.yml @@ -7,6 +7,7 @@ imports: - { resource: admin.yml } - { resource: anonymizers.yml } - { resource: ibexa_admin.yml } + - { resource: form_fieldtype_handlers.yaml } parameters: From d42fe13491ea2735682a4240df22add7faa65921 Mon Sep 17 00:00:00 2001 From: Marijan Klaric Date: Tue, 19 Mar 2024 16:14:24 +0100 Subject: [PATCH 46/87] CED-1124 clean up DataMapper.php --- bundle/Form/DataMapper.php | 25 ++++--------------------- 1 file changed, 4 insertions(+), 21 deletions(-) diff --git a/bundle/Form/DataMapper.php b/bundle/Form/DataMapper.php index b867d65e..5670e31b 100644 --- a/bundle/Form/DataMapper.php +++ b/bundle/Form/DataMapper.php @@ -4,13 +4,13 @@ namespace Netgen\Bundle\InformationCollectionBundle\Form; -use DateTime; use Symfony\Component\Form\DataMapperInterface; use Symfony\Component\Form\Exception\UnexpectedTypeException; use Symfony\Component\Form\FormInterface; use Symfony\Component\PropertyAccess\PropertyAccess; use Symfony\Component\PropertyAccess\PropertyAccessorInterface; use Symfony\Component\PropertyAccess\PropertyPathInterface; + use function is_array; use function is_object; @@ -34,7 +34,7 @@ public function __construct( $this->propertyAccessor = $propertyAccessor ?: PropertyAccess::createPropertyAccessor(); } - public function mapDataToForms($data, $forms): void + public function mapDataToForms($data, \Traversable $forms): void { $empty = null === $data || [] === $data; @@ -57,7 +57,7 @@ public function mapDataToForms($data, $forms): void } } - public function mapFormsToData($forms, &$data): void + public function mapFormsToData(\Traversable $forms, &$data): void { if (null === $data) { return; @@ -86,7 +86,6 @@ public function mapFormsToData($forms, &$data): void // If $data is out ContentCreateStruct, we need to map it to the corresponding field // in the struct if ($data instanceof DataWrapper) { - /* @var $data \Netgen\Bundle\InformationCollectionBundle\Form\DataWrapper */ $this->mapFromForm($form, $data, $propertyPath); continue; @@ -95,7 +94,7 @@ public function mapFormsToData($forms, &$data): void // If the field is of type DateTime and the data is the same skip the update to // keep the original object hash if ( - $form->getData() instanceof DateTime + $form->getData() instanceof \DateTimeImmutable && $form->getData() === $this->propertyAccessor->getValue($data, $propertyPath) ) { continue; @@ -132,20 +131,4 @@ abstract protected function mapFromForm( DataWrapper $data, PropertyPathInterface $propertyPath ): void; - - /** - * Returns if the update should be skipped for empty value. - * - * @param mixed $value - */ - protected function shouldSkipForEmptyUpdate(FormInterface $form, $value, string $fieldDefinitionIdentifier): bool - { - return - $value === null - && ( - $form->getRoot()->has("ibexa_forms_skip_empty_update_{$fieldDefinitionIdentifier}") - && $form->getRoot()->get("ibexa_forms_skip_empty_update_{$fieldDefinitionIdentifier}")->getData() === 'yes' - ) - ; - } } From 12dcfa75b16b85e3f3e285d9284e85e2182fc2a7 Mon Sep 17 00:00:00 2001 From: Marijan Klaric Date: Tue, 19 Mar 2024 16:17:26 +0100 Subject: [PATCH 47/87] CED-1124 clean up FieldTypeHandler.php --- bundle/Form/FieldTypeHandler.php | 22 ++-------------------- 1 file changed, 2 insertions(+), 20 deletions(-) diff --git a/bundle/Form/FieldTypeHandler.php b/bundle/Form/FieldTypeHandler.php index 1a7a6507..4c6f92c9 100644 --- a/bundle/Form/FieldTypeHandler.php +++ b/bundle/Form/FieldTypeHandler.php @@ -14,9 +14,9 @@ abstract class FieldTypeHandler implements FieldTypeHandlerInterface { - abstract public function convertFieldValueToForm(Value $value, ?FieldDefinition $fieldDefinition = null); + abstract public function convertFieldValueToForm(Value $value, ?FieldDefinition $fieldDefinition = null): mixed; - public function convertFieldValueFromForm($data) + public function convertFieldValueFromForm(mixed $data): mixed { return $data; } @@ -91,22 +91,4 @@ protected function getDefaultFieldOptions( return $options; } - - /** - * Adds a hidden field to the from, indicating that empty value passed - * for update should be ignored. - */ - protected function skipEmptyUpdate(FormBuilderInterface $formBuilder, string $fieldDefinitionIdentifier): void - { - $options = [ - 'mapped' => false, - 'data' => 'yes', - ]; - - $formBuilder->add( - "ibexa_forms_skip_empty_update_{$fieldDefinitionIdentifier}", - HiddenType::class, - $options - ); - } } From b540b6f58f988196b59faa2959ba192634c67a85 Mon Sep 17 00:00:00 2001 From: Marijan Klaric Date: Tue, 19 Mar 2024 16:18:47 +0100 Subject: [PATCH 48/87] CED-1124 clean up Checkbox.php --- bundle/Form/FieldTypeHandler/Checkbox.php | 1 + 1 file changed, 1 insertion(+) diff --git a/bundle/Form/FieldTypeHandler/Checkbox.php b/bundle/Form/FieldTypeHandler/Checkbox.php index 908e7cc9..9ce83f61 100644 --- a/bundle/Form/FieldTypeHandler/Checkbox.php +++ b/bundle/Form/FieldTypeHandler/Checkbox.php @@ -24,6 +24,7 @@ public function __construct(FieldHelper $fieldHelper) public function convertFieldValueToForm(Value $value, ?FieldDefinition $fieldDefinition = null): bool { + /** @var $value CheckboxValue\Value */ return $value->bool; } From 691a39abdb4a2748b783786e3306542c3b89aac4 Mon Sep 17 00:00:00 2001 From: Marijan Klaric Date: Tue, 19 Mar 2024 16:19:10 +0100 Subject: [PATCH 49/87] CED-1124 clean up Country.php --- bundle/Form/FieldTypeHandler/Country.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/bundle/Form/FieldTypeHandler/Country.php b/bundle/Form/FieldTypeHandler/Country.php index 8400f54e..659a0258 100644 --- a/bundle/Form/FieldTypeHandler/Country.php +++ b/bundle/Form/FieldTypeHandler/Country.php @@ -38,7 +38,7 @@ public function __construct(array $countryData) } } - public function convertFieldValueToForm(Value $value, ?FieldDefinition $fieldDefinition = null) + public function convertFieldValueToForm(Value $value, ?FieldDefinition $fieldDefinition = null): mixed { $isMultiple = true; if ($fieldDefinition !== null) { @@ -56,6 +56,7 @@ public function convertFieldValueToForm(Value $value, ?FieldDefinition $fieldDef return reset($keys); } + /** @var $value CountryValue */ return array_keys($value->countries); } From bba42738fd5da21d2154cd1307f3929c39348e84 Mon Sep 17 00:00:00 2001 From: Marijan Klaric Date: Tue, 19 Mar 2024 16:19:35 +0100 Subject: [PATCH 50/87] CED-1124 clean up Selection.php --- bundle/Form/FieldTypeHandler/Selection.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/bundle/Form/FieldTypeHandler/Selection.php b/bundle/Form/FieldTypeHandler/Selection.php index 431245cd..6ea242dd 100644 --- a/bundle/Form/FieldTypeHandler/Selection.php +++ b/bundle/Form/FieldTypeHandler/Selection.php @@ -15,7 +15,7 @@ final class Selection extends FieldTypeHandler { - public function convertFieldValueFromForm($value): SelectionValue\Value + public function convertFieldValueFromForm(mixed $value): SelectionValue\Value { return new SelectionValue\Value((array) $value); } @@ -36,6 +36,7 @@ public function convertFieldValueToForm(Value $value, ?FieldDefinition $fieldDef return $value->selection[0]; } + /** @var $value SelectionValue\Value */ return $value->selection; } From 5a1554d178ee27cb35d6337bba0c57e928df1c8a Mon Sep 17 00:00:00 2001 From: Marijan Klaric Date: Tue, 19 Mar 2024 16:20:20 +0100 Subject: [PATCH 51/87] CED-1124 clean up FieldTypeHandlerInterface.php --- bundle/Form/FieldTypeHandlerInterface.php | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/bundle/Form/FieldTypeHandlerInterface.php b/bundle/Form/FieldTypeHandlerInterface.php index a623c9f2..fac828fd 100644 --- a/bundle/Form/FieldTypeHandlerInterface.php +++ b/bundle/Form/FieldTypeHandlerInterface.php @@ -20,9 +20,8 @@ interface FieldTypeHandlerInterface * @see buildFieldCreateForm * @see buildFieldUpdateForm * - * @return mixed */ - public function convertFieldValueToForm(Value $value, ?FieldDefinition $fieldDefinition = null); + public function convertFieldValueToForm(Value $value, ?FieldDefinition $fieldDefinition = null): mixed; /** * Converts the form data to a format that can be accepted by Ibexa Platform FieldType. @@ -30,11 +29,8 @@ public function convertFieldValueToForm(Value $value, ?FieldDefinition $fieldDef * @see buildFieldCreateForm * @see buildFieldUpdateForm * - * @param mixed $data - * - * @return mixed */ - public function convertFieldValueFromForm($data); + public function convertFieldValueFromForm(mixed $data): mixed; /** * Builds the form the given $fieldDefinition and $languageCode for creating. From 65ef5387d3750d16f3253263c8aa0c21d5639836 Mon Sep 17 00:00:00 2001 From: Marijan Klaric Date: Tue, 19 Mar 2024 16:21:25 +0100 Subject: [PATCH 52/87] CED-1124 clean up field type handlers --- bundle/Form/FieldTypeHandler/BinaryFile.php | 2 -- bundle/Form/FieldTypeHandler/Date.php | 1 + bundle/Form/FieldTypeHandler/DateAndTime.php | 1 + bundle/Form/FieldTypeHandler/Email.php | 1 + bundle/Form/FieldTypeHandler/FloatHandler.php | 1 + bundle/Form/FieldTypeHandler/Image.php | 3 --- bundle/Form/FieldTypeHandler/IntegerHandler.php | 1 + bundle/Form/FieldTypeHandler/Isbn.php | 1 + bundle/Form/FieldTypeHandler/TextBlock.php | 1 + bundle/Form/FieldTypeHandler/TextLine.php | 1 + bundle/Form/FieldTypeHandler/Time.php | 1 + bundle/Form/FieldTypeHandler/Url.php | 1 + 12 files changed, 10 insertions(+), 5 deletions(-) diff --git a/bundle/Form/FieldTypeHandler/BinaryFile.php b/bundle/Form/FieldTypeHandler/BinaryFile.php index df0c1161..e59a25c1 100644 --- a/bundle/Form/FieldTypeHandler/BinaryFile.php +++ b/bundle/Form/FieldTypeHandler/BinaryFile.php @@ -54,8 +54,6 @@ protected function buildFieldForm( ); } - // File should not be erased (updated as empty) if nothing is selected in file input - $this->skipEmptyUpdate($formBuilder, $fieldDefinition->identifier); // Used with update for displaying current file $options['block_name'] = 'ibexa_forms_binary_file'; diff --git a/bundle/Form/FieldTypeHandler/Date.php b/bundle/Form/FieldTypeHandler/Date.php index edbbcfc0..1e688fa3 100644 --- a/bundle/Form/FieldTypeHandler/Date.php +++ b/bundle/Form/FieldTypeHandler/Date.php @@ -18,6 +18,7 @@ final class Date extends FieldTypeHandler { public function convertFieldValueToForm(Value $value, ?FieldDefinition $fieldDefinition = null): DateTime { + /** @var $value DateValue\Value */ return $value->date; } diff --git a/bundle/Form/FieldTypeHandler/DateAndTime.php b/bundle/Form/FieldTypeHandler/DateAndTime.php index a27afa6b..05a439a9 100644 --- a/bundle/Form/FieldTypeHandler/DateAndTime.php +++ b/bundle/Form/FieldTypeHandler/DateAndTime.php @@ -18,6 +18,7 @@ final class DateAndTime extends FieldTypeHandler { public function convertFieldValueToForm(Value $value, ?FieldDefinition $fieldDefinition = null): DateTime { + /** @var $value DTValue\Value */ return $value->value; } diff --git a/bundle/Form/FieldTypeHandler/Email.php b/bundle/Form/FieldTypeHandler/Email.php index 1de4e6bf..8f1effd9 100644 --- a/bundle/Form/FieldTypeHandler/Email.php +++ b/bundle/Form/FieldTypeHandler/Email.php @@ -17,6 +17,7 @@ final class Email extends FieldTypeHandler { public function convertFieldValueToForm(Value $value, ?FieldDefinition $fieldDefinition = null): string { + /** @var $value EmailAddress\Value */ return $value->email; } diff --git a/bundle/Form/FieldTypeHandler/FloatHandler.php b/bundle/Form/FieldTypeHandler/FloatHandler.php index 1a710ce9..2215a5cc 100644 --- a/bundle/Form/FieldTypeHandler/FloatHandler.php +++ b/bundle/Form/FieldTypeHandler/FloatHandler.php @@ -26,6 +26,7 @@ public function __construct(FieldHelper $fieldHelper) public function convertFieldValueToForm(Value $value, ?FieldDefinition $fieldDefinition = null): float { + /** @var $value FloatValue */ return $value->value; } diff --git a/bundle/Form/FieldTypeHandler/Image.php b/bundle/Form/FieldTypeHandler/Image.php index f8f3571b..0004f429 100644 --- a/bundle/Form/FieldTypeHandler/Image.php +++ b/bundle/Form/FieldTypeHandler/Image.php @@ -52,9 +52,6 @@ protected function buildFieldForm( ); } - // Image should not be erased (updated as empty) if nothing is selected in file input - $this->skipEmptyUpdate($formBuilder, $fieldDefinition->identifier); - $options['block_name'] = 'ibexa_forms_image'; $formBuilder->add($fieldDefinition->identifier, FileType::class, $options); diff --git a/bundle/Form/FieldTypeHandler/IntegerHandler.php b/bundle/Form/FieldTypeHandler/IntegerHandler.php index 6f00834d..e91f34a4 100644 --- a/bundle/Form/FieldTypeHandler/IntegerHandler.php +++ b/bundle/Form/FieldTypeHandler/IntegerHandler.php @@ -26,6 +26,7 @@ public function __construct(FieldHelper $fieldHelper) public function convertFieldValueToForm(Value $value, ?FieldDefinition $fieldDefinition = null): int { + /** @var $value IntegerValue\Value */ return (int) $value->value; } diff --git a/bundle/Form/FieldTypeHandler/Isbn.php b/bundle/Form/FieldTypeHandler/Isbn.php index c104f871..5f8bf45d 100644 --- a/bundle/Form/FieldTypeHandler/Isbn.php +++ b/bundle/Form/FieldTypeHandler/Isbn.php @@ -17,6 +17,7 @@ final class Isbn extends FieldTypeHandler { public function convertFieldValueToForm(Value $value, ?FieldDefinition $fieldDefinition = null): string { + /** @var $value IsbnValue */ return $value->isbn; } diff --git a/bundle/Form/FieldTypeHandler/TextBlock.php b/bundle/Form/FieldTypeHandler/TextBlock.php index 2b7aef34..763bd8cd 100644 --- a/bundle/Form/FieldTypeHandler/TextBlock.php +++ b/bundle/Form/FieldTypeHandler/TextBlock.php @@ -16,6 +16,7 @@ final class TextBlock extends FieldTypeHandler { public function convertFieldValueToForm(Value $value, ?FieldDefinition $fieldDefinition = null): string { + /** @var $value TextBlockValue */ return $value->text; } diff --git a/bundle/Form/FieldTypeHandler/TextLine.php b/bundle/Form/FieldTypeHandler/TextLine.php index 22b0bbe6..cfea45f8 100644 --- a/bundle/Form/FieldTypeHandler/TextLine.php +++ b/bundle/Form/FieldTypeHandler/TextLine.php @@ -17,6 +17,7 @@ final class TextLine extends FieldTypeHandler { public function convertFieldValueToForm(Value $value, ?FieldDefinition $fieldDefinition = null): string { + /** @var $value TextLineValue */ return $value->text; } diff --git a/bundle/Form/FieldTypeHandler/Time.php b/bundle/Form/FieldTypeHandler/Time.php index fd5afb3d..0c0434ac 100644 --- a/bundle/Form/FieldTypeHandler/Time.php +++ b/bundle/Form/FieldTypeHandler/Time.php @@ -19,6 +19,7 @@ final class Time extends FieldTypeHandler { public function convertFieldValueToForm(Value $value, ?FieldDefinition $fieldDefinition = null): DateTime { + /** @var $value TimeValue */ $time = $value->time; if (is_int($time)) { return new DateTime("@{$time}"); diff --git a/bundle/Form/FieldTypeHandler/Url.php b/bundle/Form/FieldTypeHandler/Url.php index 51c5abd7..1307df31 100644 --- a/bundle/Form/FieldTypeHandler/Url.php +++ b/bundle/Form/FieldTypeHandler/Url.php @@ -17,6 +17,7 @@ final class Url extends FieldTypeHandler { public function convertFieldValueToForm(Value $value, ?FieldDefinition $fieldDefinition = null): array { + /** @var $value UrlValue\Value */ return ['url' => $value->link, 'text' => $value->text]; } From 932f3035cc3514a84ed89b044ab179cf630bcbed Mon Sep 17 00:00:00 2001 From: Marijan Klaric Date: Tue, 19 Mar 2024 16:30:55 +0100 Subject: [PATCH 53/87] CED-1124 remove User.php class --- bundle/Form/FieldTypeHandler/User.php | 42 --------------------------- 1 file changed, 42 deletions(-) delete mode 100644 bundle/Form/FieldTypeHandler/User.php diff --git a/bundle/Form/FieldTypeHandler/User.php b/bundle/Form/FieldTypeHandler/User.php deleted file mode 100644 index f04595e3..00000000 --- a/bundle/Form/FieldTypeHandler/User.php +++ /dev/null @@ -1,42 +0,0 @@ -getDefaultFieldOptions($fieldDefinition, $languageCode); - - $formBuilder->add($fieldDefinition->identifier, UserCreateType::class, $options); - } - - public function buildFieldUpdateForm( - FormBuilderInterface $formBuilder, - FieldDefinition $fieldDefinition, - Content $content, - string $languageCode - ): void { - $options = $this->getDefaultFieldOptions($fieldDefinition, $languageCode, $content); - - $formBuilder->add($fieldDefinition->identifier, UserUpdateType::class, $options); - } -} From 8aa266124fa52e4cbbf3e6edd8185df404175de0 Mon Sep 17 00:00:00 2001 From: Marijan Klaric Date: Tue, 19 Mar 2024 16:31:14 +0100 Subject: [PATCH 54/87] CED-1124 remove User from field type config --- lib/Resources/config/form_fieldtype_handlers.yaml | 5 ----- 1 file changed, 5 deletions(-) diff --git a/lib/Resources/config/form_fieldtype_handlers.yaml b/lib/Resources/config/form_fieldtype_handlers.yaml index 84eee398..c49b1f3c 100644 --- a/lib/Resources/config/form_fieldtype_handlers.yaml +++ b/lib/Resources/config/form_fieldtype_handlers.yaml @@ -14,11 +14,6 @@ services: tags: - { name: netgen.ibexa_forms.form.fieldtype_handler, alias: eztext } - netgen_information_collection.form.fieldtype_handler.ezuser: - class: Netgen\Bundle\InformationCollectionBundle\Form\FieldTypeHandler\User - tags: - - { name: netgen.ibexa_forms.form.fieldtype_handler, alias: ezuser } - netgen_information_collection.form.fieldtype_handler.ezemail: class: Netgen\Bundle\InformationCollectionBundle\Form\FieldTypeHandler\Email tags: From a0d2b5eb40ee866d1f72e1d1532c015b2c2cd661 Mon Sep 17 00:00:00 2001 From: Marijan Klaric Date: Tue, 19 Mar 2024 16:32:18 +0100 Subject: [PATCH 55/87] CED-1124 fix BinaryFile return type --- bundle/Form/FieldTypeHandler/BinaryFile.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bundle/Form/FieldTypeHandler/BinaryFile.php b/bundle/Form/FieldTypeHandler/BinaryFile.php index e59a25c1..a16caadd 100644 --- a/bundle/Form/FieldTypeHandler/BinaryFile.php +++ b/bundle/Form/FieldTypeHandler/BinaryFile.php @@ -15,7 +15,7 @@ final class BinaryFile extends FieldTypeHandler { - public function convertFieldValueToForm(Value $value, ?FieldDefinition $fieldDefinition = null): void + public function convertFieldValueToForm(Value $value, ?FieldDefinition $fieldDefinition = null): mixed { } From 83093de547a158c3489dec91eef7d527989a25c2 Mon Sep 17 00:00:00 2001 From: Marijan Klaric Date: Wed, 20 Mar 2024 09:57:36 +0100 Subject: [PATCH 56/87] CED-1124 sync parameter name with interface in mapDataToForms method --- bundle/Form/DataMapper.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/bundle/Form/DataMapper.php b/bundle/Form/DataMapper.php index 5670e31b..863d8cce 100644 --- a/bundle/Form/DataMapper.php +++ b/bundle/Form/DataMapper.php @@ -34,19 +34,19 @@ public function __construct( $this->propertyAccessor = $propertyAccessor ?: PropertyAccess::createPropertyAccessor(); } - public function mapDataToForms($data, \Traversable $forms): void + public function mapDataToForms($viewData, \Traversable $forms): void { - $empty = null === $data || [] === $data; + $empty = null === $viewData || [] === $viewData; - if (!$empty && !is_array($data) && !is_object($data)) { - throw new UnexpectedTypeException($data, 'object, array or empty'); + if (!$empty && !is_array($viewData) && !is_object($viewData)) { + throw new UnexpectedTypeException($viewData, 'object, array or empty'); } foreach ($forms as $form) { $propertyPath = $form->getPropertyPath(); $config = $form->getConfig(); - if ($data instanceof DataWrapper && null !== $propertyPath && $config->getMapped()) { + if ($viewData instanceof DataWrapper && null !== $propertyPath && $config->getMapped()) { /* @var $data \Netgen\Bundle\InformationCollectionBundle\Form\DataWrapper */ $this->mapToForm($form, $data, $propertyPath); } elseif (!$empty && null !== $propertyPath && $config->getMapped()) { From 6580c585ea77248bc45b891a0f8242d6f6277672 Mon Sep 17 00:00:00 2001 From: Marijan Klaric Date: Wed, 20 Mar 2024 09:58:38 +0100 Subject: [PATCH 57/87] CED-1124 sync parameter name with interface in mapFormsToData method --- bundle/Form/DataMapper.php | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/bundle/Form/DataMapper.php b/bundle/Form/DataMapper.php index 863d8cce..5cd58bb1 100644 --- a/bundle/Form/DataMapper.php +++ b/bundle/Form/DataMapper.php @@ -57,14 +57,14 @@ public function mapDataToForms($viewData, \Traversable $forms): void } } - public function mapFormsToData(\Traversable $forms, &$data): void + public function mapFormsToData(\Traversable $forms, &$viewData): void { - if (null === $data) { + if (null === $viewData) { return; } - if (!is_array($data) && !is_object($data)) { - throw new UnexpectedTypeException($data, 'object, array or empty'); + if (!is_array($viewData) && !is_object($viewData)) { + throw new UnexpectedTypeException($viewData, 'object, array or empty'); } foreach ($forms as $form) { @@ -85,8 +85,8 @@ public function mapFormsToData(\Traversable $forms, &$data): void // If $data is out ContentCreateStruct, we need to map it to the corresponding field // in the struct - if ($data instanceof DataWrapper) { - $this->mapFromForm($form, $data, $propertyPath); + if ($viewData instanceof DataWrapper) { + $this->mapFromForm($form, $viewData, $propertyPath); continue; } @@ -95,7 +95,7 @@ public function mapFormsToData(\Traversable $forms, &$data): void // keep the original object hash if ( $form->getData() instanceof \DateTimeImmutable - && $form->getData() === $this->propertyAccessor->getValue($data, $propertyPath) + && $form->getData() === $this->propertyAccessor->getValue($viewData, $propertyPath) ) { continue; } @@ -103,14 +103,14 @@ public function mapFormsToData(\Traversable $forms, &$data): void // If the data is identical to the value in $data, we are // dealing with a reference if ( - is_object($data) + is_object($viewData) && $config->getByReference() - && $form->getData() === $this->propertyAccessor->getValue($data, $propertyPath) + && $form->getData() === $this->propertyAccessor->getValue($viewData, $propertyPath) ) { continue; } - $this->propertyAccessor->setValue($data, $propertyPath, $form->getData()); + $this->propertyAccessor->setValue($viewData, $propertyPath, $form->getData()); } } From f5744574b6ecb8a4b3db0b88b5fc3f7e0f8930d0 Mon Sep 17 00:00:00 2001 From: Marijan Klaric Date: Wed, 20 Mar 2024 10:18:53 +0100 Subject: [PATCH 58/87] CED-1124 fix alias in Checkbox.php --- bundle/Form/FieldTypeHandler/Checkbox.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/bundle/Form/FieldTypeHandler/Checkbox.php b/bundle/Form/FieldTypeHandler/Checkbox.php index 9ce83f61..48a9eed8 100644 --- a/bundle/Form/FieldTypeHandler/Checkbox.php +++ b/bundle/Form/FieldTypeHandler/Checkbox.php @@ -7,7 +7,7 @@ use Ibexa\Contracts\Core\FieldType\Value; use Ibexa\Contracts\Core\Repository\Values\Content\Content; use Ibexa\Contracts\Core\Repository\Values\ContentType\FieldDefinition; -use Ibexa\Core\FieldType\Checkbox as CheckboxValue; +use Ibexa\Core\FieldType\Checkbox\Value as CheckboxValue; use Ibexa\Core\Helper\FieldHelper; use Netgen\Bundle\InformationCollectionBundle\Form\FieldTypeHandler; use Symfony\Component\Form\Extension\Core\Type\CheckboxType; @@ -24,13 +24,13 @@ public function __construct(FieldHelper $fieldHelper) public function convertFieldValueToForm(Value $value, ?FieldDefinition $fieldDefinition = null): bool { - /** @var $value CheckboxValue\Value */ + /** @var $value \Ibexa\Core\FieldType\Checkbox\Value */ return $value->bool; } - public function convertFieldValueFromForm($data): CheckBoxValue\Value + public function convertFieldValueFromForm($data): CheckboxValue { - return new CheckboxValue\Value($data); + return new CheckboxValue($data); } protected function buildFieldForm( @@ -41,7 +41,7 @@ protected function buildFieldForm( ): void { $options = $this->getDefaultFieldOptions($fieldDefinition, $languageCode, $content); - if (!$content instanceof Content && $fieldDefinition->defaultValue instanceof CheckboxValue\Value) { + if (!$content instanceof Content && $fieldDefinition->defaultValue instanceof CheckboxValue) { $options['data'] = $fieldDefinition->defaultValue->bool; } From 75d831cb9d4351bcba8040ab893c4405036de590 Mon Sep 17 00:00:00 2001 From: Marijan Klaric Date: Wed, 20 Mar 2024 10:54:46 +0100 Subject: [PATCH 59/87] CED-1124 fix aliases and return types in field type handlers --- bundle/Form/FieldTypeHandler/Country.php | 2 +- bundle/Form/FieldTypeHandler/Date.php | 8 ++++---- bundle/Form/FieldTypeHandler/DateAndTime.php | 8 ++++---- bundle/Form/FieldTypeHandler/Email.php | 8 ++++---- bundle/Form/FieldTypeHandler/FloatHandler.php | 2 +- bundle/Form/FieldTypeHandler/Image.php | 2 +- bundle/Form/FieldTypeHandler/IntegerHandler.php | 10 +++++----- bundle/Form/FieldTypeHandler/Isbn.php | 2 +- bundle/Form/FieldTypeHandler/MapLocation.php | 6 +++--- bundle/Form/FieldTypeHandler/Relation.php | 3 ++- bundle/Form/FieldTypeHandler/RelationList.php | 1 + bundle/Form/FieldTypeHandler/Selection.php | 10 +++++----- bundle/Form/FieldTypeHandler/TextBlock.php | 2 +- bundle/Form/FieldTypeHandler/TextLine.php | 2 +- bundle/Form/FieldTypeHandler/Url.php | 8 ++++---- 15 files changed, 38 insertions(+), 36 deletions(-) diff --git a/bundle/Form/FieldTypeHandler/Country.php b/bundle/Form/FieldTypeHandler/Country.php index 659a0258..b9fa893b 100644 --- a/bundle/Form/FieldTypeHandler/Country.php +++ b/bundle/Form/FieldTypeHandler/Country.php @@ -56,7 +56,7 @@ public function convertFieldValueToForm(Value $value, ?FieldDefinition $fieldDef return reset($keys); } - /** @var $value CountryValue */ + /** @var $value \Ibexa\Core\FieldType\Country\Value */ return array_keys($value->countries); } diff --git a/bundle/Form/FieldTypeHandler/Date.php b/bundle/Form/FieldTypeHandler/Date.php index 1e688fa3..5833a294 100644 --- a/bundle/Form/FieldTypeHandler/Date.php +++ b/bundle/Form/FieldTypeHandler/Date.php @@ -8,7 +8,7 @@ use Ibexa\Contracts\Core\FieldType\Value; use Ibexa\Contracts\Core\Repository\Values\Content\Content; use Ibexa\Contracts\Core\Repository\Values\ContentType\FieldDefinition; -use Ibexa\Core\FieldType\Date as DateValue; +use Ibexa\Core\FieldType\Date\Value as DateValue; use Netgen\Bundle\InformationCollectionBundle\Form\FieldTypeHandler; use Symfony\Component\Form\Extension\Core\Type\DateType; use Symfony\Component\Form\FormBuilderInterface; @@ -18,13 +18,13 @@ final class Date extends FieldTypeHandler { public function convertFieldValueToForm(Value $value, ?FieldDefinition $fieldDefinition = null): DateTime { - /** @var $value DateValue\Value */ + /** @var $value DateValue */ return $value->date; } - public function convertFieldValueFromForm($data): DateValue\Value + public function convertFieldValueFromForm($data): DateValue { - return new DateValue\Value($data); + return new DateValue($data); } protected function buildFieldForm( diff --git a/bundle/Form/FieldTypeHandler/DateAndTime.php b/bundle/Form/FieldTypeHandler/DateAndTime.php index 05a439a9..46743696 100644 --- a/bundle/Form/FieldTypeHandler/DateAndTime.php +++ b/bundle/Form/FieldTypeHandler/DateAndTime.php @@ -8,7 +8,7 @@ use Ibexa\Contracts\Core\FieldType\Value; use Ibexa\Contracts\Core\Repository\Values\Content\Content; use Ibexa\Contracts\Core\Repository\Values\ContentType\FieldDefinition; -use Ibexa\Core\FieldType\DateAndTime as DTValue; +use Ibexa\Core\FieldType\DateAndTime\Value as DTValue; use Netgen\Bundle\InformationCollectionBundle\Form\FieldTypeHandler; use Symfony\Component\Form\Extension\Core\Type\DateTimeType; use Symfony\Component\Form\FormBuilderInterface; @@ -18,13 +18,13 @@ final class DateAndTime extends FieldTypeHandler { public function convertFieldValueToForm(Value $value, ?FieldDefinition $fieldDefinition = null): DateTime { - /** @var $value DTValue\Value */ + /** @var $value \Ibexa\Core\FieldType\DateAndTime\Value */ return $value->value; } - public function convertFieldValueFromForm($data): DTValue\Value + public function convertFieldValueFromForm($data): DTValue { - return new DTValue\Value($data); + return new DTValue($data); } protected function buildFieldForm( diff --git a/bundle/Form/FieldTypeHandler/Email.php b/bundle/Form/FieldTypeHandler/Email.php index 8f1effd9..306677cf 100644 --- a/bundle/Form/FieldTypeHandler/Email.php +++ b/bundle/Form/FieldTypeHandler/Email.php @@ -7,7 +7,7 @@ use Ibexa\Contracts\Core\FieldType\Value; use Ibexa\Contracts\Core\Repository\Values\Content\Content; use Ibexa\Contracts\Core\Repository\Values\ContentType\FieldDefinition; -use Ibexa\Core\FieldType\EmailAddress; +use Ibexa\Core\FieldType\EmailAddress\Value as EmailAddressValue; use Netgen\Bundle\InformationCollectionBundle\Form\FieldTypeHandler; use Symfony\Component\Form\Extension\Core\Type\EmailType; use Symfony\Component\Form\FormBuilderInterface; @@ -17,13 +17,13 @@ final class Email extends FieldTypeHandler { public function convertFieldValueToForm(Value $value, ?FieldDefinition $fieldDefinition = null): string { - /** @var $value EmailAddress\Value */ + /** @var $value \Ibexa\Core\FieldType\EmailAddress\Value */ return $value->email; } - public function convertFieldValueFromForm($data): EmailAddress\Value + public function convertFieldValueFromForm($data): EmailAddressValue { - return new EmailAddress\Value($data); + return new EmailAddressValue($data); } protected function buildFieldForm( diff --git a/bundle/Form/FieldTypeHandler/FloatHandler.php b/bundle/Form/FieldTypeHandler/FloatHandler.php index 2215a5cc..688defd1 100644 --- a/bundle/Form/FieldTypeHandler/FloatHandler.php +++ b/bundle/Form/FieldTypeHandler/FloatHandler.php @@ -26,7 +26,7 @@ public function __construct(FieldHelper $fieldHelper) public function convertFieldValueToForm(Value $value, ?FieldDefinition $fieldDefinition = null): float { - /** @var $value FloatValue */ + /** @var $value \Ibexa\Core\FieldType\Float\Value */ return $value->value; } diff --git a/bundle/Form/FieldTypeHandler/Image.php b/bundle/Form/FieldTypeHandler/Image.php index 0004f429..550d9faa 100644 --- a/bundle/Form/FieldTypeHandler/Image.php +++ b/bundle/Form/FieldTypeHandler/Image.php @@ -15,7 +15,7 @@ final class Image extends FieldTypeHandler { - public function convertFieldValueToForm(Value $value, ?FieldDefinition $fieldDefinition = null): void + public function convertFieldValueToForm(Value $value, ?FieldDefinition $fieldDefinition = null): mixed { } diff --git a/bundle/Form/FieldTypeHandler/IntegerHandler.php b/bundle/Form/FieldTypeHandler/IntegerHandler.php index e91f34a4..9d1e7e81 100644 --- a/bundle/Form/FieldTypeHandler/IntegerHandler.php +++ b/bundle/Form/FieldTypeHandler/IntegerHandler.php @@ -7,7 +7,7 @@ use Ibexa\Contracts\Core\FieldType\Value; use Ibexa\Contracts\Core\Repository\Values\Content\Content; use Ibexa\Contracts\Core\Repository\Values\ContentType\FieldDefinition; -use Ibexa\Core\FieldType\Integer as IntegerValue; +use Ibexa\Core\FieldType\Integer\Value as IntegerValue; use Ibexa\Core\Helper\FieldHelper; use Netgen\Bundle\InformationCollectionBundle\Form\FieldTypeHandler; use Symfony\Component\Form\Extension\Core\Type\IntegerType; @@ -26,17 +26,17 @@ public function __construct(FieldHelper $fieldHelper) public function convertFieldValueToForm(Value $value, ?FieldDefinition $fieldDefinition = null): int { - /** @var $value IntegerValue\Value */ + /** @var $value \Ibexa\Core\FieldType\Integer\Value */ return (int) $value->value; } - public function convertFieldValueFromForm($data): IntegerValue\Value + public function convertFieldValueFromForm($data): IntegerValue { if (!is_int($data)) { $data = null; } - return new IntegerValue\Value($data); + return new IntegerValue($data); } protected function buildFieldForm( @@ -47,7 +47,7 @@ protected function buildFieldForm( ): void { $options = $this->getDefaultFieldOptions($fieldDefinition, $languageCode, $content); - if (!$content instanceof Content && $fieldDefinition->defaultValue instanceof IntegerValue\Value) { + if (!$content instanceof Content && $fieldDefinition->defaultValue instanceof IntegerValue) { $options['data'] = (int) $fieldDefinition->defaultValue->value; } diff --git a/bundle/Form/FieldTypeHandler/Isbn.php b/bundle/Form/FieldTypeHandler/Isbn.php index 5f8bf45d..1c8207c2 100644 --- a/bundle/Form/FieldTypeHandler/Isbn.php +++ b/bundle/Form/FieldTypeHandler/Isbn.php @@ -17,7 +17,7 @@ final class Isbn extends FieldTypeHandler { public function convertFieldValueToForm(Value $value, ?FieldDefinition $fieldDefinition = null): string { - /** @var $value IsbnValue */ + /** @var $value \Ibexa\Core\FieldType\ISBN\Value */ return $value->isbn; } diff --git a/bundle/Form/FieldTypeHandler/MapLocation.php b/bundle/Form/FieldTypeHandler/MapLocation.php index 5301947b..42e90b46 100644 --- a/bundle/Form/FieldTypeHandler/MapLocation.php +++ b/bundle/Form/FieldTypeHandler/MapLocation.php @@ -7,7 +7,7 @@ use Ibexa\Contracts\Core\FieldType\Value; use Ibexa\Contracts\Core\Repository\Values\Content\Content; use Ibexa\Contracts\Core\Repository\Values\ContentType\FieldDefinition; -use Ibexa\Core\FieldType\MapLocation as MapLocationValue; +use Ibexa\Core\FieldType\MapLocation\Value as MapLocationValue; use Netgen\Bundle\InformationCollectionBundle\Form\FieldTypeHandler; use Netgen\Bundle\InformationCollectionBundle\Form\Type\MapType; use Symfony\Component\Form\FormBuilderInterface; @@ -24,13 +24,13 @@ public function convertFieldValueToForm(Value $value, ?FieldDefinition $fieldDef ]; } - public function convertFieldValueFromForm($data): ?MapLocationValue\Value + public function convertFieldValueFromForm($data): ?MapLocationValue { if (!is_array($data)) { return null; } - return new MapLocationValue\Value( + return new MapLocationValue( [ 'latitude' => $data['latitude'], 'longitude' => $data['longitude'], diff --git a/bundle/Form/FieldTypeHandler/Relation.php b/bundle/Form/FieldTypeHandler/Relation.php index d9304055..1ca5dd69 100644 --- a/bundle/Form/FieldTypeHandler/Relation.php +++ b/bundle/Form/FieldTypeHandler/Relation.php @@ -23,12 +23,13 @@ public function __construct(Repository $repository) $this->repository = $repository; } - public function convertFieldValueToForm(Value $value, ?FieldDefinition $fieldDefinition = null) + public function convertFieldValueToForm(Value $value, ?FieldDefinition $fieldDefinition = null): mixed { if (empty($value->destinationContentId)) { return null; } + /** @var $value \Ibexa\Core\FieldType\Relation\Value */ return $value->destinationContentId; } diff --git a/bundle/Form/FieldTypeHandler/RelationList.php b/bundle/Form/FieldTypeHandler/RelationList.php index b5a28921..a25cf66d 100644 --- a/bundle/Form/FieldTypeHandler/RelationList.php +++ b/bundle/Form/FieldTypeHandler/RelationList.php @@ -36,6 +36,7 @@ public function convertFieldValueToForm(Value $value, ?FieldDefinition $fieldDef return null; } + /** @var $value \Ibexa\Core\FieldType\RelationList\Value */ return $value->destinationContentIds; } diff --git a/bundle/Form/FieldTypeHandler/Selection.php b/bundle/Form/FieldTypeHandler/Selection.php index 6ea242dd..c19dd429 100644 --- a/bundle/Form/FieldTypeHandler/Selection.php +++ b/bundle/Form/FieldTypeHandler/Selection.php @@ -7,7 +7,7 @@ use Ibexa\Contracts\Core\FieldType\Value; use Ibexa\Contracts\Core\Repository\Values\Content\Content; use Ibexa\Contracts\Core\Repository\Values\ContentType\FieldDefinition; -use Ibexa\Core\FieldType\Selection as SelectionValue; +use Ibexa\Core\FieldType\Selection\Value as SelectionValue; use Netgen\Bundle\InformationCollectionBundle\Form\FieldTypeHandler; use Symfony\Component\Form\Extension\Core\Type\ChoiceType; use Symfony\Component\Form\FormBuilderInterface; @@ -15,12 +15,12 @@ final class Selection extends FieldTypeHandler { - public function convertFieldValueFromForm(mixed $value): SelectionValue\Value + public function convertFieldValueFromForm(mixed $value): SelectionValue { - return new SelectionValue\Value((array) $value); + return new SelectionValue((array) $value); } - public function convertFieldValueToForm(Value $value, ?FieldDefinition $fieldDefinition = null) + public function convertFieldValueToForm(Value $value, ?FieldDefinition $fieldDefinition = null): mixed { $isMultiple = true; if ($fieldDefinition !== null) { @@ -36,7 +36,7 @@ public function convertFieldValueToForm(Value $value, ?FieldDefinition $fieldDef return $value->selection[0]; } - /** @var $value SelectionValue\Value */ + /** @var $value \Ibexa\Core\FieldType\Selection\Value */ return $value->selection; } diff --git a/bundle/Form/FieldTypeHandler/TextBlock.php b/bundle/Form/FieldTypeHandler/TextBlock.php index 763bd8cd..1fdfb79b 100644 --- a/bundle/Form/FieldTypeHandler/TextBlock.php +++ b/bundle/Form/FieldTypeHandler/TextBlock.php @@ -16,7 +16,7 @@ final class TextBlock extends FieldTypeHandler { public function convertFieldValueToForm(Value $value, ?FieldDefinition $fieldDefinition = null): string { - /** @var $value TextBlockValue */ + /** @var $value \Ibexa\Core\FieldType\TextBlock\Value */ return $value->text; } diff --git a/bundle/Form/FieldTypeHandler/TextLine.php b/bundle/Form/FieldTypeHandler/TextLine.php index cfea45f8..013b241d 100644 --- a/bundle/Form/FieldTypeHandler/TextLine.php +++ b/bundle/Form/FieldTypeHandler/TextLine.php @@ -17,7 +17,7 @@ final class TextLine extends FieldTypeHandler { public function convertFieldValueToForm(Value $value, ?FieldDefinition $fieldDefinition = null): string { - /** @var $value TextLineValue */ + /** @var $value \Ibexa\Core\FieldType\TextLine\Value */ return $value->text; } diff --git a/bundle/Form/FieldTypeHandler/Url.php b/bundle/Form/FieldTypeHandler/Url.php index 1307df31..27876185 100644 --- a/bundle/Form/FieldTypeHandler/Url.php +++ b/bundle/Form/FieldTypeHandler/Url.php @@ -7,7 +7,7 @@ use Ibexa\Contracts\Core\FieldType\Value; use Ibexa\Contracts\Core\Repository\Values\Content\Content; use Ibexa\Contracts\Core\Repository\Values\ContentType\FieldDefinition; -use Ibexa\Core\FieldType\Url as UrlValue; +use Ibexa\Core\FieldType\Url\Value as UrlValue; use Netgen\Bundle\InformationCollectionBundle\Form\FieldTypeHandler; use Netgen\Bundle\InformationCollectionBundle\Form\Type\UrlType; use Symfony\Component\Form\FormBuilderInterface; @@ -17,11 +17,11 @@ final class Url extends FieldTypeHandler { public function convertFieldValueToForm(Value $value, ?FieldDefinition $fieldDefinition = null): array { - /** @var $value UrlValue\Value */ + /** @var $value \Ibexa\Core\FieldType\Url\Value */ return ['url' => $value->link, 'text' => $value->text]; } - public function convertFieldValueFromForm($data): UrlValue\Value + public function convertFieldValueFromForm($data): UrlValue { if (!is_array($data)) { $data = []; @@ -29,7 +29,7 @@ public function convertFieldValueFromForm($data): UrlValue\Value $data['text'] = null; } - return new UrlValue\Value($data['url'], $data['text']); + return new UrlValue($data['url'], $data['text']); } protected function buildFieldForm( From fac3dfd348bdfb62487dfa05660f967911bb5a33 Mon Sep 17 00:00:00 2001 From: Marijan Klaric Date: Wed, 20 Mar 2024 11:25:35 +0100 Subject: [PATCH 60/87] CED-1124 add docblock type hint to Country.php --- bundle/Form/FieldTypeHandler/Country.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/bundle/Form/FieldTypeHandler/Country.php b/bundle/Form/FieldTypeHandler/Country.php index b9fa893b..3225c093 100644 --- a/bundle/Form/FieldTypeHandler/Country.php +++ b/bundle/Form/FieldTypeHandler/Country.php @@ -38,6 +38,9 @@ public function __construct(array $countryData) } } + /** + * @param \Ibexa\Core\FieldType\Country\Value $value + */ public function convertFieldValueToForm(Value $value, ?FieldDefinition $fieldDefinition = null): mixed { $isMultiple = true; @@ -56,7 +59,6 @@ public function convertFieldValueToForm(Value $value, ?FieldDefinition $fieldDef return reset($keys); } - /** @var $value \Ibexa\Core\FieldType\Country\Value */ return array_keys($value->countries); } From e0905a8c658f84a010e7678a30e2376ece76b6ea Mon Sep 17 00:00:00 2001 From: Marijan Klaric Date: Wed, 20 Mar 2024 11:28:11 +0100 Subject: [PATCH 61/87] CED-1124 match variable with interface Selection.php --- bundle/Form/FieldTypeHandler/Selection.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bundle/Form/FieldTypeHandler/Selection.php b/bundle/Form/FieldTypeHandler/Selection.php index c19dd429..ce7cde24 100644 --- a/bundle/Form/FieldTypeHandler/Selection.php +++ b/bundle/Form/FieldTypeHandler/Selection.php @@ -15,9 +15,9 @@ final class Selection extends FieldTypeHandler { - public function convertFieldValueFromForm(mixed $value): SelectionValue + public function convertFieldValueFromForm(mixed $data): SelectionValue { - return new SelectionValue((array) $value); + return new SelectionValue((array) $data); } public function convertFieldValueToForm(Value $value, ?FieldDefinition $fieldDefinition = null): mixed From df6111a2170ef5584ca4cdb7e54b14ebf5adc22c Mon Sep 17 00:00:00 2001 From: Marijan Klaric Date: Wed, 20 Mar 2024 12:10:05 +0100 Subject: [PATCH 62/87] CED-1124 add docblock type hint to field type handler --- bundle/Form/FieldTypeHandler/Checkbox.php | 5 ++++- bundle/Form/FieldTypeHandler/Date.php | 4 +++- bundle/Form/FieldTypeHandler/DateAndTime.php | 4 +++- bundle/Form/FieldTypeHandler/Email.php | 4 +++- bundle/Form/FieldTypeHandler/FloatHandler.php | 4 +++- bundle/Form/FieldTypeHandler/IntegerHandler.php | 4 +++- bundle/Form/FieldTypeHandler/Isbn.php | 4 +++- bundle/Form/FieldTypeHandler/Relation.php | 4 +++- bundle/Form/FieldTypeHandler/Selection.php | 4 +++- bundle/Form/FieldTypeHandler/TextBlock.php | 4 +++- bundle/Form/FieldTypeHandler/TextLine.php | 4 +++- bundle/Form/FieldTypeHandler/Time.php | 3 +++ bundle/Form/FieldTypeHandler/Url.php | 4 +++- 13 files changed, 40 insertions(+), 12 deletions(-) diff --git a/bundle/Form/FieldTypeHandler/Checkbox.php b/bundle/Form/FieldTypeHandler/Checkbox.php index 48a9eed8..ad152f95 100644 --- a/bundle/Form/FieldTypeHandler/Checkbox.php +++ b/bundle/Form/FieldTypeHandler/Checkbox.php @@ -22,9 +22,12 @@ public function __construct(FieldHelper $fieldHelper) $this->fieldHelper = $fieldHelper; } + + /** + * @param \Ibexa\Core\FieldType\Checkbox\Value $value + */ public function convertFieldValueToForm(Value $value, ?FieldDefinition $fieldDefinition = null): bool { - /** @var $value \Ibexa\Core\FieldType\Checkbox\Value */ return $value->bool; } diff --git a/bundle/Form/FieldTypeHandler/Date.php b/bundle/Form/FieldTypeHandler/Date.php index 5833a294..3a61b13d 100644 --- a/bundle/Form/FieldTypeHandler/Date.php +++ b/bundle/Form/FieldTypeHandler/Date.php @@ -16,9 +16,11 @@ final class Date extends FieldTypeHandler { + /** + * @param \Ibexa\Core\FieldType\Date\Value $value + */ public function convertFieldValueToForm(Value $value, ?FieldDefinition $fieldDefinition = null): DateTime { - /** @var $value DateValue */ return $value->date; } diff --git a/bundle/Form/FieldTypeHandler/DateAndTime.php b/bundle/Form/FieldTypeHandler/DateAndTime.php index 46743696..a19c2da9 100644 --- a/bundle/Form/FieldTypeHandler/DateAndTime.php +++ b/bundle/Form/FieldTypeHandler/DateAndTime.php @@ -16,9 +16,11 @@ final class DateAndTime extends FieldTypeHandler { + /** + * @param \Ibexa\Core\FieldType\DateAndTime\Value $value + */ public function convertFieldValueToForm(Value $value, ?FieldDefinition $fieldDefinition = null): DateTime { - /** @var $value \Ibexa\Core\FieldType\DateAndTime\Value */ return $value->value; } diff --git a/bundle/Form/FieldTypeHandler/Email.php b/bundle/Form/FieldTypeHandler/Email.php index 306677cf..068dba55 100644 --- a/bundle/Form/FieldTypeHandler/Email.php +++ b/bundle/Form/FieldTypeHandler/Email.php @@ -15,9 +15,11 @@ final class Email extends FieldTypeHandler { + /** + * @param \Ibexa\Core\FieldType\EmailAddress\Value $value + */ public function convertFieldValueToForm(Value $value, ?FieldDefinition $fieldDefinition = null): string { - /** @var $value \Ibexa\Core\FieldType\EmailAddress\Value */ return $value->email; } diff --git a/bundle/Form/FieldTypeHandler/FloatHandler.php b/bundle/Form/FieldTypeHandler/FloatHandler.php index 688defd1..7c813fdd 100644 --- a/bundle/Form/FieldTypeHandler/FloatHandler.php +++ b/bundle/Form/FieldTypeHandler/FloatHandler.php @@ -24,9 +24,11 @@ public function __construct(FieldHelper $fieldHelper) $this->fieldHelper = $fieldHelper; } + /** + * @param \Ibexa\Core\FieldType\Float\Value $value + */ public function convertFieldValueToForm(Value $value, ?FieldDefinition $fieldDefinition = null): float { - /** @var $value \Ibexa\Core\FieldType\Float\Value */ return $value->value; } diff --git a/bundle/Form/FieldTypeHandler/IntegerHandler.php b/bundle/Form/FieldTypeHandler/IntegerHandler.php index 9d1e7e81..4297cbbc 100644 --- a/bundle/Form/FieldTypeHandler/IntegerHandler.php +++ b/bundle/Form/FieldTypeHandler/IntegerHandler.php @@ -24,9 +24,11 @@ public function __construct(FieldHelper $fieldHelper) $this->fieldHelper = $fieldHelper; } + /** + * @param \Ibexa\Core\FieldType\Integer\Value $value + */ public function convertFieldValueToForm(Value $value, ?FieldDefinition $fieldDefinition = null): int { - /** @var $value \Ibexa\Core\FieldType\Integer\Value */ return (int) $value->value; } diff --git a/bundle/Form/FieldTypeHandler/Isbn.php b/bundle/Form/FieldTypeHandler/Isbn.php index 1c8207c2..d14d2ab9 100644 --- a/bundle/Form/FieldTypeHandler/Isbn.php +++ b/bundle/Form/FieldTypeHandler/Isbn.php @@ -15,9 +15,11 @@ final class Isbn extends FieldTypeHandler { + /** + * @param \Ibexa\Core\FieldType\ISBN\Value $value + */ public function convertFieldValueToForm(Value $value, ?FieldDefinition $fieldDefinition = null): string { - /** @var $value \Ibexa\Core\FieldType\ISBN\Value */ return $value->isbn; } diff --git a/bundle/Form/FieldTypeHandler/Relation.php b/bundle/Form/FieldTypeHandler/Relation.php index 1ca5dd69..1915a588 100644 --- a/bundle/Form/FieldTypeHandler/Relation.php +++ b/bundle/Form/FieldTypeHandler/Relation.php @@ -23,13 +23,15 @@ public function __construct(Repository $repository) $this->repository = $repository; } + /** + * @param \Ibexa\Core\FieldType\Relation\Value $value + */ public function convertFieldValueToForm(Value $value, ?FieldDefinition $fieldDefinition = null): mixed { if (empty($value->destinationContentId)) { return null; } - /** @var $value \Ibexa\Core\FieldType\Relation\Value */ return $value->destinationContentId; } diff --git a/bundle/Form/FieldTypeHandler/Selection.php b/bundle/Form/FieldTypeHandler/Selection.php index ce7cde24..e5cddea6 100644 --- a/bundle/Form/FieldTypeHandler/Selection.php +++ b/bundle/Form/FieldTypeHandler/Selection.php @@ -20,6 +20,9 @@ public function convertFieldValueFromForm(mixed $data): SelectionValue return new SelectionValue((array) $data); } + /** + * @param \Ibexa\Core\FieldType\Selection\Value $value + */ public function convertFieldValueToForm(Value $value, ?FieldDefinition $fieldDefinition = null): mixed { $isMultiple = true; @@ -36,7 +39,6 @@ public function convertFieldValueToForm(Value $value, ?FieldDefinition $fieldDef return $value->selection[0]; } - /** @var $value \Ibexa\Core\FieldType\Selection\Value */ return $value->selection; } diff --git a/bundle/Form/FieldTypeHandler/TextBlock.php b/bundle/Form/FieldTypeHandler/TextBlock.php index 1fdfb79b..da9c4190 100644 --- a/bundle/Form/FieldTypeHandler/TextBlock.php +++ b/bundle/Form/FieldTypeHandler/TextBlock.php @@ -14,9 +14,11 @@ final class TextBlock extends FieldTypeHandler { + /** + * @param \Ibexa\Core\FieldType\TextBlock\Value $value + */ public function convertFieldValueToForm(Value $value, ?FieldDefinition $fieldDefinition = null): string { - /** @var $value \Ibexa\Core\FieldType\TextBlock\Value */ return $value->text; } diff --git a/bundle/Form/FieldTypeHandler/TextLine.php b/bundle/Form/FieldTypeHandler/TextLine.php index 013b241d..21baaf7e 100644 --- a/bundle/Form/FieldTypeHandler/TextLine.php +++ b/bundle/Form/FieldTypeHandler/TextLine.php @@ -15,9 +15,11 @@ final class TextLine extends FieldTypeHandler { + /** + * @param \Ibexa\Core\FieldType\TextLine\Value $value + */ public function convertFieldValueToForm(Value $value, ?FieldDefinition $fieldDefinition = null): string { - /** @var $value \Ibexa\Core\FieldType\TextLine\Value */ return $value->text; } diff --git a/bundle/Form/FieldTypeHandler/Time.php b/bundle/Form/FieldTypeHandler/Time.php index 0c0434ac..32cc2f20 100644 --- a/bundle/Form/FieldTypeHandler/Time.php +++ b/bundle/Form/FieldTypeHandler/Time.php @@ -17,6 +17,9 @@ final class Time extends FieldTypeHandler { + /** + * @param \Ibexa\Core\FieldType\Time\Value $value + */ public function convertFieldValueToForm(Value $value, ?FieldDefinition $fieldDefinition = null): DateTime { /** @var $value TimeValue */ diff --git a/bundle/Form/FieldTypeHandler/Url.php b/bundle/Form/FieldTypeHandler/Url.php index 27876185..f0ec9750 100644 --- a/bundle/Form/FieldTypeHandler/Url.php +++ b/bundle/Form/FieldTypeHandler/Url.php @@ -15,9 +15,11 @@ final class Url extends FieldTypeHandler { + /** + * @param \Ibexa\Core\FieldType\Url\Value $value + */ public function convertFieldValueToForm(Value $value, ?FieldDefinition $fieldDefinition = null): array { - /** @var $value \Ibexa\Core\FieldType\Url\Value */ return ['url' => $value->link, 'text' => $value->text]; } From 6bec7a9835db4f6925d6e5fa95c1ab92d268880a Mon Sep 17 00:00:00 2001 From: Marijan Klaric Date: Wed, 20 Mar 2024 12:25:04 +0100 Subject: [PATCH 63/87] CED-1124 update code to PHP 8.1 standards --- bundle/Form/DataMapper.php | 4 ++-- bundle/Form/FieldTypeHandler/BinaryFile.php | 2 +- bundle/Form/FieldTypeHandler/Checkbox.php | 2 +- bundle/Form/FieldTypeHandler/Country.php | 2 +- bundle/Form/FieldTypeHandler/Date.php | 2 +- bundle/Form/FieldTypeHandler/DateAndTime.php | 2 +- bundle/Form/FieldTypeHandler/Email.php | 2 +- bundle/Form/FieldTypeHandler/FloatHandler.php | 2 +- bundle/Form/FieldTypeHandler/Image.php | 2 +- bundle/Form/FieldTypeHandler/IntegerHandler.php | 2 +- bundle/Form/FieldTypeHandler/Isbn.php | 2 +- bundle/Form/FieldTypeHandler/MapLocation.php | 2 +- bundle/Form/FieldTypeHandler/RelationList.php | 2 +- bundle/Form/FieldTypeHandler/TextBlock.php | 2 +- bundle/Form/FieldTypeHandler/TextLine.php | 2 +- bundle/Form/FieldTypeHandler/Time.php | 2 +- bundle/Form/FieldTypeHandler/Url.php | 2 +- 17 files changed, 18 insertions(+), 18 deletions(-) diff --git a/bundle/Form/DataMapper.php b/bundle/Form/DataMapper.php index 5cd58bb1..e1a07288 100644 --- a/bundle/Form/DataMapper.php +++ b/bundle/Form/DataMapper.php @@ -34,7 +34,7 @@ public function __construct( $this->propertyAccessor = $propertyAccessor ?: PropertyAccess::createPropertyAccessor(); } - public function mapDataToForms($viewData, \Traversable $forms): void + public function mapDataToForms(mixed $viewData, \Traversable $forms): void { $empty = null === $viewData || [] === $viewData; @@ -57,7 +57,7 @@ public function mapDataToForms($viewData, \Traversable $forms): void } } - public function mapFormsToData(\Traversable $forms, &$viewData): void + public function mapFormsToData(\Traversable $forms, mixed &$viewData): void { if (null === $viewData) { return; diff --git a/bundle/Form/FieldTypeHandler/BinaryFile.php b/bundle/Form/FieldTypeHandler/BinaryFile.php index a16caadd..454b63cd 100644 --- a/bundle/Form/FieldTypeHandler/BinaryFile.php +++ b/bundle/Form/FieldTypeHandler/BinaryFile.php @@ -22,7 +22,7 @@ public function convertFieldValueToForm(Value $value, ?FieldDefinition $fieldDef /** * @param \Symfony\Component\HttpFoundation\File\UploadedFile|null $data */ - public function convertFieldValueFromForm($data): ?FileValue + public function convertFieldValueFromForm(mixed $data): ?FileValue { if ($data === null) { return null; diff --git a/bundle/Form/FieldTypeHandler/Checkbox.php b/bundle/Form/FieldTypeHandler/Checkbox.php index ad152f95..5e87388e 100644 --- a/bundle/Form/FieldTypeHandler/Checkbox.php +++ b/bundle/Form/FieldTypeHandler/Checkbox.php @@ -31,7 +31,7 @@ public function convertFieldValueToForm(Value $value, ?FieldDefinition $fieldDef return $value->bool; } - public function convertFieldValueFromForm($data): CheckboxValue + public function convertFieldValueFromForm(mixed $data): CheckboxValue { return new CheckboxValue($data); } diff --git a/bundle/Form/FieldTypeHandler/Country.php b/bundle/Form/FieldTypeHandler/Country.php index 3225c093..77fe150f 100644 --- a/bundle/Form/FieldTypeHandler/Country.php +++ b/bundle/Form/FieldTypeHandler/Country.php @@ -62,7 +62,7 @@ public function convertFieldValueToForm(Value $value, ?FieldDefinition $fieldDef return array_keys($value->countries); } - public function convertFieldValueFromForm($data): CountryValue + public function convertFieldValueFromForm(mixed $data): CountryValue { $country = []; diff --git a/bundle/Form/FieldTypeHandler/Date.php b/bundle/Form/FieldTypeHandler/Date.php index 3a61b13d..b7f5f436 100644 --- a/bundle/Form/FieldTypeHandler/Date.php +++ b/bundle/Form/FieldTypeHandler/Date.php @@ -24,7 +24,7 @@ public function convertFieldValueToForm(Value $value, ?FieldDefinition $fieldDef return $value->date; } - public function convertFieldValueFromForm($data): DateValue + public function convertFieldValueFromForm(mixed $data): DateValue { return new DateValue($data); } diff --git a/bundle/Form/FieldTypeHandler/DateAndTime.php b/bundle/Form/FieldTypeHandler/DateAndTime.php index a19c2da9..157772c1 100644 --- a/bundle/Form/FieldTypeHandler/DateAndTime.php +++ b/bundle/Form/FieldTypeHandler/DateAndTime.php @@ -24,7 +24,7 @@ public function convertFieldValueToForm(Value $value, ?FieldDefinition $fieldDef return $value->value; } - public function convertFieldValueFromForm($data): DTValue + public function convertFieldValueFromForm(mixed $data): DTValue { return new DTValue($data); } diff --git a/bundle/Form/FieldTypeHandler/Email.php b/bundle/Form/FieldTypeHandler/Email.php index 068dba55..169854fc 100644 --- a/bundle/Form/FieldTypeHandler/Email.php +++ b/bundle/Form/FieldTypeHandler/Email.php @@ -23,7 +23,7 @@ public function convertFieldValueToForm(Value $value, ?FieldDefinition $fieldDef return $value->email; } - public function convertFieldValueFromForm($data): EmailAddressValue + public function convertFieldValueFromForm(mixed $data): EmailAddressValue { return new EmailAddressValue($data); } diff --git a/bundle/Form/FieldTypeHandler/FloatHandler.php b/bundle/Form/FieldTypeHandler/FloatHandler.php index 7c813fdd..33fb1e3f 100644 --- a/bundle/Form/FieldTypeHandler/FloatHandler.php +++ b/bundle/Form/FieldTypeHandler/FloatHandler.php @@ -32,7 +32,7 @@ public function convertFieldValueToForm(Value $value, ?FieldDefinition $fieldDef return $value->value; } - public function convertFieldValueFromForm($data): FloatValue + public function convertFieldValueFromForm(mixed $data): FloatValue { if (!is_numeric($data)) { $data = null; diff --git a/bundle/Form/FieldTypeHandler/Image.php b/bundle/Form/FieldTypeHandler/Image.php index 550d9faa..7e117879 100644 --- a/bundle/Form/FieldTypeHandler/Image.php +++ b/bundle/Form/FieldTypeHandler/Image.php @@ -19,7 +19,7 @@ public function convertFieldValueToForm(Value $value, ?FieldDefinition $fieldDef { } - public function convertFieldValueFromForm($data): ?ImageValue + public function convertFieldValueFromForm(mixed $data): ?ImageValue { if ($data === null) { return null; diff --git a/bundle/Form/FieldTypeHandler/IntegerHandler.php b/bundle/Form/FieldTypeHandler/IntegerHandler.php index 4297cbbc..0e79a17b 100644 --- a/bundle/Form/FieldTypeHandler/IntegerHandler.php +++ b/bundle/Form/FieldTypeHandler/IntegerHandler.php @@ -32,7 +32,7 @@ public function convertFieldValueToForm(Value $value, ?FieldDefinition $fieldDef return (int) $value->value; } - public function convertFieldValueFromForm($data): IntegerValue + public function convertFieldValueFromForm(mixed $data): IntegerValue { if (!is_int($data)) { $data = null; diff --git a/bundle/Form/FieldTypeHandler/Isbn.php b/bundle/Form/FieldTypeHandler/Isbn.php index d14d2ab9..a3c9a460 100644 --- a/bundle/Form/FieldTypeHandler/Isbn.php +++ b/bundle/Form/FieldTypeHandler/Isbn.php @@ -23,7 +23,7 @@ public function convertFieldValueToForm(Value $value, ?FieldDefinition $fieldDef return $value->isbn; } - public function convertFieldValueFromForm($data): IsbnValue + public function convertFieldValueFromForm(mixed $data): IsbnValue { if (empty($data)) { $data = ''; diff --git a/bundle/Form/FieldTypeHandler/MapLocation.php b/bundle/Form/FieldTypeHandler/MapLocation.php index 42e90b46..254bf057 100644 --- a/bundle/Form/FieldTypeHandler/MapLocation.php +++ b/bundle/Form/FieldTypeHandler/MapLocation.php @@ -24,7 +24,7 @@ public function convertFieldValueToForm(Value $value, ?FieldDefinition $fieldDef ]; } - public function convertFieldValueFromForm($data): ?MapLocationValue + public function convertFieldValueFromForm(mixed $data): ?MapLocationValue { if (!is_array($data)) { return null; diff --git a/bundle/Form/FieldTypeHandler/RelationList.php b/bundle/Form/FieldTypeHandler/RelationList.php index a25cf66d..47722e69 100644 --- a/bundle/Form/FieldTypeHandler/RelationList.php +++ b/bundle/Form/FieldTypeHandler/RelationList.php @@ -40,7 +40,7 @@ public function convertFieldValueToForm(Value $value, ?FieldDefinition $fieldDef return $value->destinationContentIds; } - public function convertFieldValueFromForm($data): RelationListValue + public function convertFieldValueFromForm(mixed $data): RelationListValue { return new RelationListValue($data); } diff --git a/bundle/Form/FieldTypeHandler/TextBlock.php b/bundle/Form/FieldTypeHandler/TextBlock.php index da9c4190..419e7f10 100644 --- a/bundle/Form/FieldTypeHandler/TextBlock.php +++ b/bundle/Form/FieldTypeHandler/TextBlock.php @@ -22,7 +22,7 @@ public function convertFieldValueToForm(Value $value, ?FieldDefinition $fieldDef return $value->text; } - public function convertFieldValueFromForm($data): TextBlockValue + public function convertFieldValueFromForm(mixed $data): TextBlockValue { if (empty($data)) { $data = ''; diff --git a/bundle/Form/FieldTypeHandler/TextLine.php b/bundle/Form/FieldTypeHandler/TextLine.php index 21baaf7e..12481deb 100644 --- a/bundle/Form/FieldTypeHandler/TextLine.php +++ b/bundle/Form/FieldTypeHandler/TextLine.php @@ -23,7 +23,7 @@ public function convertFieldValueToForm(Value $value, ?FieldDefinition $fieldDef return $value->text; } - public function convertFieldValueFromForm($data): TextLineValue + public function convertFieldValueFromForm(mixed $data): TextLineValue { if (empty($data)) { $data = ''; diff --git a/bundle/Form/FieldTypeHandler/Time.php b/bundle/Form/FieldTypeHandler/Time.php index 32cc2f20..7531d944 100644 --- a/bundle/Form/FieldTypeHandler/Time.php +++ b/bundle/Form/FieldTypeHandler/Time.php @@ -31,7 +31,7 @@ public function convertFieldValueToForm(Value $value, ?FieldDefinition $fieldDef return new DateTime(); } - public function convertFieldValueFromForm($data): TimeValue + public function convertFieldValueFromForm(mixed $data): TimeValue { if ($data instanceof DateTime) { return TimeValue::fromDateTime($data); diff --git a/bundle/Form/FieldTypeHandler/Url.php b/bundle/Form/FieldTypeHandler/Url.php index f0ec9750..b64a2383 100644 --- a/bundle/Form/FieldTypeHandler/Url.php +++ b/bundle/Form/FieldTypeHandler/Url.php @@ -23,7 +23,7 @@ public function convertFieldValueToForm(Value $value, ?FieldDefinition $fieldDef return ['url' => $value->link, 'text' => $value->text]; } - public function convertFieldValueFromForm($data): UrlValue + public function convertFieldValueFromForm(mixed $data): UrlValue { if (!is_array($data)) { $data = []; From 37edb6fffe72d0fe0814f9783e75b6b957fd27eb Mon Sep 17 00:00:00 2001 From: Marijan Klaric Date: Wed, 20 Mar 2024 12:48:58 +0100 Subject: [PATCH 64/87] CED-1124 change name of variable in DataMapper.php --- bundle/Form/DataMapper.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bundle/Form/DataMapper.php b/bundle/Form/DataMapper.php index e1a07288..52325cda 100644 --- a/bundle/Form/DataMapper.php +++ b/bundle/Form/DataMapper.php @@ -47,8 +47,8 @@ public function mapDataToForms(mixed $viewData, \Traversable $forms): void $config = $form->getConfig(); if ($viewData instanceof DataWrapper && null !== $propertyPath && $config->getMapped()) { - /* @var $data \Netgen\Bundle\InformationCollectionBundle\Form\DataWrapper */ - $this->mapToForm($form, $data, $propertyPath); + /* @var $viewData \Netgen\Bundle\InformationCollectionBundle\Form\DataWrapper */ + $this->mapToForm($form, $viewData, $propertyPath); } elseif (!$empty && null !== $propertyPath && $config->getMapped()) { $form->setData($this->propertyAccessor->getValue($data, $propertyPath)); } else { From bc480a8d6d07e18c9f7be94a12ea24ef414aee1f Mon Sep 17 00:00:00 2001 From: Marijan Klaric Date: Wed, 20 Mar 2024 13:21:17 +0100 Subject: [PATCH 65/87] CED-1124 remove redundant inline type hint --- bundle/Form/FieldTypeHandler/RelationList.php | 1 - 1 file changed, 1 deletion(-) diff --git a/bundle/Form/FieldTypeHandler/RelationList.php b/bundle/Form/FieldTypeHandler/RelationList.php index 47722e69..8a2305a5 100644 --- a/bundle/Form/FieldTypeHandler/RelationList.php +++ b/bundle/Form/FieldTypeHandler/RelationList.php @@ -89,7 +89,6 @@ protected function buildFieldForm( $choices = []; - /** @var \Ibexa\Contracts\Core\Repository\Values\Content\Location $child */ foreach ($locationList->locations as $child) { $choices[$child->getContent()->getName()] = $child->contentInfo->id; } From 90f8ad95265e2441b1fcf54e2a097b111a1ca9cb Mon Sep 17 00:00:00 2001 From: Marijan Klaric Date: Wed, 20 Mar 2024 13:21:38 +0100 Subject: [PATCH 66/87] CED-1124 remove redundant inline type hint --- bundle/Form/FieldTypeHandler/RelationList.php | 1 - 1 file changed, 1 deletion(-) diff --git a/bundle/Form/FieldTypeHandler/RelationList.php b/bundle/Form/FieldTypeHandler/RelationList.php index 8a2305a5..614a99b9 100644 --- a/bundle/Form/FieldTypeHandler/RelationList.php +++ b/bundle/Form/FieldTypeHandler/RelationList.php @@ -69,7 +69,6 @@ protected function buildFieldForm( $choices = []; - /** @var \Ibexa\Contracts\Core\Repository\Values\Content\Location $child */ foreach ($locationList->locations as $child) { $choices[$child->getContent()->getName()] = $child->contentInfo->id; } From 54aa2657d520b1e8989074740070cba903ff6128 Mon Sep 17 00:00:00 2001 From: Marijan Klaric Date: Wed, 20 Mar 2024 13:23:37 +0100 Subject: [PATCH 67/87] CED-1124 add return type to getCollectedValue method --- bundle/Form/Payload/InformationCollectionStruct.php | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/bundle/Form/Payload/InformationCollectionStruct.php b/bundle/Form/Payload/InformationCollectionStruct.php index 3a7e36a0..d92e31a2 100644 --- a/bundle/Form/Payload/InformationCollectionStruct.php +++ b/bundle/Form/Payload/InformationCollectionStruct.php @@ -13,10 +13,8 @@ final class InformationCollectionStruct /** * Returns value for $fieldDefIdentifier. - * - * @return mixed */ - public function getCollectedFieldValue(string $fieldDefIdentifier) + public function getCollectedFieldValue(string $fieldDefIdentifier): mixed { return $this->collectedData[$fieldDefIdentifier] ?? null; } From cc986d9eab48470c880feca947cb9078dfeb268b Mon Sep 17 00:00:00 2001 From: Marijan Klaric Date: Wed, 20 Mar 2024 13:27:39 +0100 Subject: [PATCH 68/87] CED-1124 add return type for value variable in setCollectedValue method --- bundle/Form/Payload/InformationCollectionStruct.php | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/bundle/Form/Payload/InformationCollectionStruct.php b/bundle/Form/Payload/InformationCollectionStruct.php index d92e31a2..374a609c 100644 --- a/bundle/Form/Payload/InformationCollectionStruct.php +++ b/bundle/Form/Payload/InformationCollectionStruct.php @@ -29,10 +29,8 @@ public function getCollectedFields(): array /** * Sets value for $fieldDefIdentifier. - * - * @param mixed $value */ - public function setCollectedFieldValue(string $fieldDefIdentifier, $value): void + public function setCollectedFieldValue(string $fieldDefIdentifier, mixed $value): void { $this->collectedData[$fieldDefIdentifier] = $value; } From aec51ebec8db64bba5e1a11b8c3499d11e975786 Mon Sep 17 00:00:00 2001 From: Marijan Klaric Date: Wed, 20 Mar 2024 13:49:13 +0100 Subject: [PATCH 69/87] CED-1124 change alias in DateAndTime.php --- bundle/Form/FieldTypeHandler/DateAndTime.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/bundle/Form/FieldTypeHandler/DateAndTime.php b/bundle/Form/FieldTypeHandler/DateAndTime.php index 157772c1..71d87589 100644 --- a/bundle/Form/FieldTypeHandler/DateAndTime.php +++ b/bundle/Form/FieldTypeHandler/DateAndTime.php @@ -8,7 +8,7 @@ use Ibexa\Contracts\Core\FieldType\Value; use Ibexa\Contracts\Core\Repository\Values\Content\Content; use Ibexa\Contracts\Core\Repository\Values\ContentType\FieldDefinition; -use Ibexa\Core\FieldType\DateAndTime\Value as DTValue; +use Ibexa\Core\FieldType\DateAndTime\Value as DateTimeValue; use Netgen\Bundle\InformationCollectionBundle\Form\FieldTypeHandler; use Symfony\Component\Form\Extension\Core\Type\DateTimeType; use Symfony\Component\Form\FormBuilderInterface; @@ -24,9 +24,9 @@ public function convertFieldValueToForm(Value $value, ?FieldDefinition $fieldDef return $value->value; } - public function convertFieldValueFromForm(mixed $data): DTValue + public function convertFieldValueFromForm(mixed $data): DateTimeValue { - return new DTValue($data); + return new DateTimeValue($data); } protected function buildFieldForm( From a6d9a0e3746b6b7002fc0c8090a8dfb66b7ba2c4 Mon Sep 17 00:00:00 2001 From: Marijan Klaric Date: Wed, 20 Mar 2024 13:55:13 +0100 Subject: [PATCH 70/87] CED-1124 fixed wrong variable name in DataMapper.php --- bundle/Form/DataMapper.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bundle/Form/DataMapper.php b/bundle/Form/DataMapper.php index 52325cda..711b59d9 100644 --- a/bundle/Form/DataMapper.php +++ b/bundle/Form/DataMapper.php @@ -50,7 +50,7 @@ public function mapDataToForms(mixed $viewData, \Traversable $forms): void /* @var $viewData \Netgen\Bundle\InformationCollectionBundle\Form\DataWrapper */ $this->mapToForm($form, $viewData, $propertyPath); } elseif (!$empty && null !== $propertyPath && $config->getMapped()) { - $form->setData($this->propertyAccessor->getValue($data, $propertyPath)); + $form->setData($this->propertyAccessor->getValue($viewData, $propertyPath)); } else { $form->setData($form->getConfig()->getData()); } From 1ab8f5d6f73d154856a353f10b2334c452060325 Mon Sep 17 00:00:00 2001 From: Marijan Klaric Date: Wed, 20 Mar 2024 13:58:46 +0100 Subject: [PATCH 71/87] CED-1124 remove UserType.php --- bundle/Form/Type/FieldType/UserType.php | 73 ------------------------- 1 file changed, 73 deletions(-) delete mode 100644 bundle/Form/Type/FieldType/UserType.php diff --git a/bundle/Form/Type/FieldType/UserType.php b/bundle/Form/Type/FieldType/UserType.php deleted file mode 100644 index 40a05cb2..00000000 --- a/bundle/Form/Type/FieldType/UserType.php +++ /dev/null @@ -1,73 +0,0 @@ -validatorConfiguration['PasswordValueValidator']; - - if ($passwordValidator['requireAtLeastOneUpperCaseCharacter'] ?? false) { - $passwordConstraints[] = new Constraints\Regex( - [ - 'pattern' => '/[A-Z]+/', - 'message' => 'Password must contain at least one upper-case character', - ] - ); - } - - if ($passwordValidator['requireAtLeastOneLowerCaseCharacter'] ?? false) { - $passwordConstraints[] = new Constraints\Regex( - [ - 'pattern' => '/[a-z]+/', - 'message' => 'Password must contain at least one lower-case character', - ] - ); - } - - if ($passwordValidator['requireAtLeastOneNumericCharacter'] ?? false) { - $passwordConstraints[] = new Constraints\Regex( - [ - 'pattern' => '/\d+/', - 'message' => 'Password must contain at least one numeric character', - ] - ); - } - - if ($passwordValidator['requireAtLeastOneNonAlphanumericCharacter'] ?? false) { - $passwordConstraints[] = new Constraints\Regex( - [ - 'pattern' => '/\W+/', - 'message' => 'Password must contain at least one non-alphanumeric character', - ] - ); - } - - if (($passwordValidator['minLength'] ?? 0) > 0) { - $passwordConstraints[] = new Constraints\Length( - [ - 'min' => $passwordValidator['minLength'], - ] - ); - } - - return $passwordConstraints; - } -} From 7822313dddf2e8ccc3a49f6743fdc0293f4b2363 Mon Sep 17 00:00:00 2001 From: Marijan Klaric Date: Wed, 20 Mar 2024 14:00:08 +0100 Subject: [PATCH 72/87] CED-1124 remove UserUpdateType.php --- bundle/Form/Type/FieldType/UserUpdateType.php | 50 ------------------- 1 file changed, 50 deletions(-) delete mode 100644 bundle/Form/Type/FieldType/UserUpdateType.php diff --git a/bundle/Form/Type/FieldType/UserUpdateType.php b/bundle/Form/Type/FieldType/UserUpdateType.php deleted file mode 100644 index d6fe2857..00000000 --- a/bundle/Form/Type/FieldType/UserUpdateType.php +++ /dev/null @@ -1,50 +0,0 @@ - 'E-mail address', - 'constraints' => [ - new Constraints\NotBlank(), - new Constraints\Email(), - ], - ]; - - $passwordOptions = [ - 'type' => PasswordType::class, - // Setting required to false enables passing empty passwords for no update - 'required' => false, - 'invalid_message' => 'Both passwords must match.', - 'options' => [ - 'constraints' => $this->getPasswordConstraints($options['ibexa_forms']['fielddefinition'] ?? null, false), - ], - 'first_options' => [ - 'label' => 'New password (leave empty to keep current password)', - ], - 'second_options' => [ - 'label' => 'Repeat new password', - ], - ]; - - $builder - ->add('email', EmailType::class, $emailOptions) - ->add('password', RepeatedType::class, $passwordOptions); - } - - public function getBlockPrefix(): string - { - return 'ibexa_forms_ezuser_update'; - } -} From bfce0ac71aca87e849c4117b23ec8aec6eca52ab Mon Sep 17 00:00:00 2001 From: Marijan Klaric Date: Wed, 20 Mar 2024 14:00:45 +0100 Subject: [PATCH 73/87] CED-1124 remove UserCreateType.php --- bundle/Form/Type/FieldType/UserCreateType.php | 57 ------------------- 1 file changed, 57 deletions(-) delete mode 100644 bundle/Form/Type/FieldType/UserCreateType.php diff --git a/bundle/Form/Type/FieldType/UserCreateType.php b/bundle/Form/Type/FieldType/UserCreateType.php deleted file mode 100644 index 269ee27c..00000000 --- a/bundle/Form/Type/FieldType/UserCreateType.php +++ /dev/null @@ -1,57 +0,0 @@ - 'E-mail address', - 'constraints' => [ - new Constraints\NotBlank(), - new Constraints\Email(), - ], - ]; - - $usernameOptions = [ - 'label' => 'Username', - 'constraints' => [ - new Constraints\NotBlank(), - ], - ]; - - $passwordOptions = [ - 'type' => PasswordType::class, - 'invalid_message' => 'Both passwords must match.', - 'options' => [ - 'constraints' => $this->getPasswordConstraints($options['ibexa_forms']['fielddefinition'] ?? null), - ], - 'first_options' => [ - 'label' => 'Password', - ], - 'second_options' => [ - 'label' => 'Repeat password', - ], - ]; - - $builder - ->add('email', EmailType::class, $emailOptions) - ->add('username', TextType::class, $usernameOptions) - ->add('password', RepeatedType::class, $passwordOptions); - } - - public function getBlockPrefix(): string - { - return 'ibexa_forms_ezuser_create'; - } -} From 626615432be32efea565d49e868be50b43222802 Mon Sep 17 00:00:00 2001 From: Marijan Klaric Date: Wed, 20 Mar 2024 14:16:18 +0100 Subject: [PATCH 74/87] CED-1124 add type hints to DataWrapper.php --- bundle/Form/DataWrapper.php | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/bundle/Form/DataWrapper.php b/bundle/Form/DataWrapper.php index d1c46044..da6d0b43 100644 --- a/bundle/Form/DataWrapper.php +++ b/bundle/Form/DataWrapper.php @@ -8,19 +8,16 @@ final class DataWrapper { /** * One of the Ibexa Platform structs, like ContentCreateStruct, UserUpdateStruct and so on. - * - * @var mixed */ - public $payload; + public mixed $payload; /** * Definition of the target. * * In case of Content or User target, this must be the corresponding ContentType. * - * @var mixed|null */ - public $definition; + public mixed $definition; /** * The target struct that applies to. E.g. Content, User, Section object and so on. @@ -28,9 +25,8 @@ final class DataWrapper * This target makes sense only in update context, when creating target does not * exist (yet to be created). * - * @var mixed|null */ - public $target; + public mixed $target; /** * Construct from payload, target and definition. @@ -39,7 +35,7 @@ final class DataWrapper * @param mixed|null $target * @param mixed|null $definition */ - public function __construct($payload, $definition = null, $target = null) + public function __construct(mixed $payload, mixed $definition = null, mixed $target = null) { $this->payload = $payload; $this->definition = $definition; From 4ccfd43d72b6ceb0a48c9c1dcb5cb2f42cee1e54 Mon Sep 17 00:00:00 2001 From: Marijan Klaric Date: Wed, 20 Mar 2024 14:17:55 +0100 Subject: [PATCH 75/87] CED-1124 update docs in DataWrapper.php --- bundle/Form/DataWrapper.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/bundle/Form/DataWrapper.php b/bundle/Form/DataWrapper.php index da6d0b43..03267981 100644 --- a/bundle/Form/DataWrapper.php +++ b/bundle/Form/DataWrapper.php @@ -7,20 +7,20 @@ final class DataWrapper { /** - * One of the Ibexa Platform structs, like ContentCreateStruct, UserUpdateStruct and so on. + * One of the Ibexa Platform structs, like ContentCreateStruct and so on. */ public mixed $payload; /** * Definition of the target. * - * In case of Content or User target, this must be the corresponding ContentType. + * In case of Content target, this must be the corresponding ContentType. * */ public mixed $definition; /** - * The target struct that applies to. E.g. Content, User, Section object and so on. + * The target struct that applies to. E.g. Content, Section object and so on. * * This target makes sense only in update context, when creating target does not * exist (yet to be created). From 706fed57230d8458d7ba96ae27125d203d351627 Mon Sep 17 00:00:00 2001 From: Marijan Klaric Date: Wed, 20 Mar 2024 14:51:11 +0100 Subject: [PATCH 76/87] CED-1124 remove callable from parameter docs in FieldTypeHandlerRegistry.php --- bundle/Form/FieldTypeHandlerRegistry.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bundle/Form/FieldTypeHandlerRegistry.php b/bundle/Form/FieldTypeHandlerRegistry.php index ae251dfe..1c0759aa 100644 --- a/bundle/Form/FieldTypeHandlerRegistry.php +++ b/bundle/Form/FieldTypeHandlerRegistry.php @@ -30,7 +30,7 @@ public function __construct(array $map = []) /** * Register a $service for FieldType $identifier. * - * @param \Netgen\Bundle\InformationCollectionBundle\Form\FieldTypeHandlerInterface|callable $handler + * @param \Netgen\Bundle\InformationCollectionBundle\Form\FieldTypeHandlerInterface $handler */ public function register(string $identifier, $handler): void { From d2abeb6a45a1728de584a2ceb699af30c5472ed1 Mon Sep 17 00:00:00 2001 From: Marijan Klaric Date: Wed, 20 Mar 2024 14:52:28 +0100 Subject: [PATCH 77/87] CED-1124 type hint FieldTypeHandlerInterface in register method --- bundle/Form/FieldTypeHandlerRegistry.php | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/bundle/Form/FieldTypeHandlerRegistry.php b/bundle/Form/FieldTypeHandlerRegistry.php index 1c0759aa..e8511fe9 100644 --- a/bundle/Form/FieldTypeHandlerRegistry.php +++ b/bundle/Form/FieldTypeHandlerRegistry.php @@ -29,10 +29,8 @@ public function __construct(array $map = []) /** * Register a $service for FieldType $identifier. - * - * @param \Netgen\Bundle\InformationCollectionBundle\Form\FieldTypeHandlerInterface $handler */ - public function register(string $identifier, $handler): void + public function register(string $identifier, FieldTypeHandlerInterface $handler): void { $this->map[$identifier] = $handler; } From 38530c5f9adffd77d45fbbc641d5c6f01bec9558 Mon Sep 17 00:00:00 2001 From: Marijan Klaric Date: Wed, 20 Mar 2024 14:54:24 +0100 Subject: [PATCH 78/87] CED-1124 remove handling callable from get method in FieldTypeHandlerRegistry.php --- bundle/Form/FieldTypeHandlerRegistry.php | 4 ---- 1 file changed, 4 deletions(-) diff --git a/bundle/Form/FieldTypeHandlerRegistry.php b/bundle/Form/FieldTypeHandlerRegistry.php index e8511fe9..65888426 100644 --- a/bundle/Form/FieldTypeHandlerRegistry.php +++ b/bundle/Form/FieldTypeHandlerRegistry.php @@ -48,10 +48,6 @@ public function get(string $identifier): FieldTypeHandlerInterface|\Netgen\Bundl } if (!$this->map[$identifier] instanceof FieldTypeHandlerInterface && !$this->map[$identifier] instanceof \Netgen\Bundle\IbexaFormsBundle\Form\FieldTypeHandlerInterface) { - if (!is_callable($this->map[$identifier])) { - throw new RuntimeException("FieldTypeHandler '{$identifier}' is not callable nor instance"); - } - $factory = $this->map[$identifier]; $this->map[$identifier] = $factory(); From 49dc73ca7e6ceb94d1183e721db1c39d20dce58a Mon Sep 17 00:00:00 2001 From: Marijan Klaric Date: Wed, 20 Mar 2024 15:03:48 +0100 Subject: [PATCH 79/87] CED-1124 move form types to Type folder --- bundle/Controller/Admin/Export/Export.php | 2 +- bundle/Form/Builder/FormBuilder.php | 3 +-- bundle/Form/{ => Type}/CaptchaType.php | 2 +- bundle/Form/{ => Type}/ExportType.php | 6 +++--- bundle/Form/{ => Type}/InformationCollectionUpdateType.php | 6 +++--- bundle/Ibexa/ContentForms/InformationCollectionType.php | 2 +- 6 files changed, 10 insertions(+), 11 deletions(-) rename bundle/Form/{ => Type}/CaptchaType.php (96%) rename bundle/Form/{ => Type}/ExportType.php (98%) rename bundle/Form/{ => Type}/InformationCollectionUpdateType.php (94%) diff --git a/bundle/Controller/Admin/Export/Export.php b/bundle/Controller/Admin/Export/Export.php index acfc0cad..be878557 100644 --- a/bundle/Controller/Admin/Export/Export.php +++ b/bundle/Controller/Admin/Export/Export.php @@ -6,7 +6,7 @@ use Ibexa\Contracts\Core\Repository\ContentService; use Ibexa\Core\MVC\Symfony\Security\Authorization\Attribute; -use Netgen\Bundle\InformationCollectionBundle\Form\ExportType; +use Netgen\Bundle\InformationCollectionBundle\Form\Type\ExportType; use Netgen\InformationCollection\API\Service\Exporter; use Netgen\InformationCollection\API\Value\Export\ExportCriteria; use Netgen\InformationCollection\Core\Export\ExportResponseFormatterRegistry; diff --git a/bundle/Form/Builder/FormBuilder.php b/bundle/Form/Builder/FormBuilder.php index d16e11f2..4827e7a9 100644 --- a/bundle/Form/Builder/FormBuilder.php +++ b/bundle/Form/Builder/FormBuilder.php @@ -10,7 +10,7 @@ use Ibexa\Core\Repository\SiteAccessAware\ContentTypeService; use Netgen\Bundle\InformationCollectionBundle\Form\DataWrapper; use Netgen\Bundle\InformationCollectionBundle\Form\Payload\InformationCollectionStruct; -use Netgen\Bundle\InformationCollectionBundle\Form\InformationCollectionUpdateType; +use Netgen\Bundle\InformationCollectionBundle\Form\Type\InformationCollectionUpdateType; use Netgen\InformationCollection\API\FieldHandler\CustomLegacyFieldHandlerInterface; use Netgen\InformationCollection\API\Value\Attribute; use Netgen\InformationCollection\API\Value\Collection; @@ -20,7 +20,6 @@ use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\Form\FormFactoryInterface; use Symfony\Component\Routing\RouterInterface; - use function sprintf; class FormBuilder diff --git a/bundle/Form/CaptchaType.php b/bundle/Form/Type/CaptchaType.php similarity index 96% rename from bundle/Form/CaptchaType.php rename to bundle/Form/Type/CaptchaType.php index 43de5d84..696a9deb 100644 --- a/bundle/Form/CaptchaType.php +++ b/bundle/Form/Type/CaptchaType.php @@ -1,6 +1,6 @@ Date: Wed, 20 Mar 2024 15:23:32 +0100 Subject: [PATCH 80/87] CED-1124 adapt tag name for form_fieldtype_handlers.yaml --- .../config/form_fieldtype_handlers.yaml | 36 +++++++++---------- 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/lib/Resources/config/form_fieldtype_handlers.yaml b/lib/Resources/config/form_fieldtype_handlers.yaml index c49b1f3c..032dab57 100644 --- a/lib/Resources/config/form_fieldtype_handlers.yaml +++ b/lib/Resources/config/form_fieldtype_handlers.yaml @@ -2,98 +2,98 @@ services: netgen_information_collection.form.fieldtype_handler.ezimage: class: Netgen\Bundle\InformationCollectionBundle\Form\FieldTypeHandler\Image tags: - - { name: netgen.ibexa_forms.form.fieldtype_handler, alias: ezimage } + - { name: netgen_information_collection.form.fieldtype_handler, alias: ezimage } netgen_information_collection.form.fieldtype_handler.ezstring: class: Netgen\Bundle\InformationCollectionBundle\Form\FieldTypeHandler\TextLine tags: - - { name: netgen.ibexa_forms.form.fieldtype_handler, alias: ezstring } + - { name: netgen_information_collection.form.fieldtype_handler, alias: ezstring } netgen_information_collection.form.fieldtype_handler.eztext: class: Netgen\Bundle\InformationCollectionBundle\Form\FieldTypeHandler\TextBlock tags: - - { name: netgen.ibexa_forms.form.fieldtype_handler, alias: eztext } + - { name: netgen_information_collection.form.fieldtype_handler, alias: eztext } netgen_information_collection.form.fieldtype_handler.ezemail: class: Netgen\Bundle\InformationCollectionBundle\Form\FieldTypeHandler\Email tags: - - { name: netgen.ibexa_forms.form.fieldtype_handler, alias: ezemail } + - { name: netgen_information_collection.form.fieldtype_handler, alias: ezemail } netgen_information_collection.form.fieldtype_handler.ezselection: class: Netgen\Bundle\InformationCollectionBundle\Form\FieldTypeHandler\Selection tags: - - { name: netgen.ibexa_forms.form.fieldtype_handler, alias: ezselection } + - { name: netgen_information_collection.form.fieldtype_handler, alias: ezselection } netgen_information_collection.form.fieldtype_handler.ezboolean: class: Netgen\Bundle\InformationCollectionBundle\Form\FieldTypeHandler\Checkbox arguments: [ "@Ibexa\\Core\\Helper\\FieldHelper" ] tags: - - { name: netgen.ibexa_forms.form.fieldtype_handler, alias: ezboolean } + - { name: netgen_information_collection.form.fieldtype_handler, alias: ezboolean } netgen_information_collection.form.fieldtype_handler.ezdate: class: Netgen\Bundle\InformationCollectionBundle\Form\FieldTypeHandler\Date tags: - - { name: netgen.ibexa_forms.form.fieldtype_handler, alias: ezdate } + - { name: netgen_information_collection.form.fieldtype_handler, alias: ezdate } netgen_information_collection.form.fieldtype_handler.ezdatetime: class: Netgen\Bundle\InformationCollectionBundle\Form\FieldTypeHandler\DateAndTime tags: - - { name: netgen.ibexa_forms.form.fieldtype_handler, alias: ezdatetime } + - { name: netgen_information_collection.form.fieldtype_handler, alias: ezdatetime } netgen_information_collection.form.fieldtype_handler.ezinteger: class: Netgen\Bundle\InformationCollectionBundle\Form\FieldTypeHandler\IntegerHandler arguments: [ "@Ibexa\\Core\\Helper\\FieldHelper" ] tags: - - {name: netgen.ibexa_forms.form.fieldtype_handler, alias: ezinteger} + - {name: netgen_information_collection.form.fieldtype_handler, alias: ezinteger} netgen_information_collection.form.fieldtype_handler.ezfloat: class: Netgen\Bundle\InformationCollectionBundle\Form\FieldTypeHandler\FloatHandler arguments: [ "@Ibexa\\Core\\Helper\\FieldHelper" ] tags: - - { name: netgen.ibexa_forms.form.fieldtype_handler, alias: ezfloat } + - { name: netgen_information_collection.form.fieldtype_handler, alias: ezfloat } netgen_information_collection.form.fieldtype_handler.ezurl: class: Netgen\Bundle\InformationCollectionBundle\Form\FieldTypeHandler\Url tags: - - { name: netgen.ibexa_forms.form.fieldtype_handler, alias: ezurl } + - { name: netgen_information_collection.form.fieldtype_handler, alias: ezurl } netgen_information_collection.form.fieldtype_handler.ezcountry: class: Netgen\Bundle\InformationCollectionBundle\Form\FieldTypeHandler\Country arguments: - "%ibexa.field_type.country.data%" tags: - - { name: netgen.ibexa_forms.form.fieldtype_handler, alias: ezcountry } + - { name: netgen_information_collection.form.fieldtype_handler, alias: ezcountry } netgen_information_collection.form.fieldtype_handler.eztime: class: Netgen\Bundle\InformationCollectionBundle\Form\FieldTypeHandler\Time tags: - - { name: netgen.ibexa_forms.form.fieldtype_handler, alias: eztime } + - { name: netgen_information_collection.form.fieldtype_handler, alias: eztime } netgen_information_collection.form.fieldtype_handler.ezisbn: class: Netgen\Bundle\InformationCollectionBundle\Form\FieldTypeHandler\Isbn tags: - - { name: netgen.ibexa_forms.form.fieldtype_handler, alias: ezisbn } + - { name: netgen_information_collection.form.fieldtype_handler, alias: ezisbn } netgen_information_collection.form.fieldtype_handler.ezbinaryfile: class: Netgen\Bundle\InformationCollectionBundle\Form\FieldTypeHandler\BinaryFile tags: - - { name: netgen.ibexa_forms.form.fieldtype_handler, alias: ezbinaryfile } + - { name: netgen_information_collection.form.fieldtype_handler, alias: ezbinaryfile } netgen_information_collection.form.fieldtype_handler.ezgmaplocation: class: Netgen\Bundle\InformationCollectionBundle\Form\FieldTypeHandler\MapLocation tags: - - { name: netgen.ibexa_forms.form.fieldtype_handler, alias: ezgmaplocation } + - { name: netgen_information_collection.form.fieldtype_handler, alias: ezgmaplocation } netgen_information_collection.form.fieldtype_handler.ezobjectrelation: class: Netgen\Bundle\InformationCollectionBundle\Form\FieldTypeHandler\Relation arguments: - "@ibexa.api.repository" tags: - - { name: netgen.ibexa_forms.form.fieldtype_handler, alias: ezobjectrelation } + - { name: netgen_information_collection.form.fieldtype_handler, alias: ezobjectrelation } netgen_information_collection.form.fieldtype_handler.ezobjectrelationlist: class: Netgen\Bundle\InformationCollectionBundle\Form\FieldTypeHandler\RelationList arguments: - "@ibexa.api.repository" tags: - - { name: netgen.ibexa_forms.form.fieldtype_handler, alias: ezobjectrelationlist } + - { name: netgen_information_collections.form.fieldtype_handler, alias: ezobjectrelationlist } From 9f5610302a2e92243e706c120f62442711c0fb8c Mon Sep 17 00:00:00 2001 From: Marijan Klaric Date: Wed, 20 Mar 2024 15:23:57 +0100 Subject: [PATCH 81/87] CED-1124 adapt tag in FieldTypeHandlerRegistryPass.php --- .../Compiler/FieldTypeHandlerRegistryPass.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bundle/DependencyInjection/Compiler/FieldTypeHandlerRegistryPass.php b/bundle/DependencyInjection/Compiler/FieldTypeHandlerRegistryPass.php index e9a63e9c..23c4ce7e 100644 --- a/bundle/DependencyInjection/Compiler/FieldTypeHandlerRegistryPass.php +++ b/bundle/DependencyInjection/Compiler/FieldTypeHandlerRegistryPass.php @@ -19,11 +19,11 @@ public function process(ContainerBuilder $container): void $registry = $container->getDefinition('netgen_information_collection.form.fieldtype_handler_registry'); - foreach ($container->findTaggedServiceIds('netgen.ibexa_forms.form.fieldtype_handler') as $id => $attributes) { + foreach ($container->findTaggedServiceIds('netgen_information_collection.form.fieldtype_handler') as $id => $attributes) { foreach ($attributes as $attribute) { if (!isset($attribute['alias'])) { throw new LogicException( - "'netgen.ibexa_forms.form.fieldtype_handler' service tag " . + "'netgen_information_collection.form.fieldtype_handler' service tag " . "needs an 'alias' attribute to identify the field type. None given." ); } From 137ab03a687d3b2e44ab4964407eac4c4202c8bb Mon Sep 17 00:00:00 2001 From: Marijan Klaric Date: Wed, 20 Mar 2024 15:43:45 +0100 Subject: [PATCH 82/87] CED-1124 add Birthday type --- bundle/Form/FieldTypeHandler/Birthday.php | 51 +++++++++++++++++++ lib/Form/Type/FieldType/Birthday/Value.php | 41 +++++++++++++++ .../config/form_fieldtype_handlers.yaml | 5 ++ 3 files changed, 97 insertions(+) create mode 100644 bundle/Form/FieldTypeHandler/Birthday.php create mode 100644 lib/Form/Type/FieldType/Birthday/Value.php diff --git a/bundle/Form/FieldTypeHandler/Birthday.php b/bundle/Form/FieldTypeHandler/Birthday.php new file mode 100644 index 00000000..501ea5f7 --- /dev/null +++ b/bundle/Form/FieldTypeHandler/Birthday.php @@ -0,0 +1,51 @@ +date; + } + + public function convertFieldValueFromForm($data): BirthdayValue + { + if (empty($data)) { + $data = null; + } + + return new BirthdayValue($data); + } + + protected function buildFieldForm( + FormBuilderInterface $formBuilder, + FieldDefinition $fieldDefinition, + string $languageCode, + ?Content $content = null + ): void { + $options = $this->getDefaultFieldOptions($fieldDefinition, $languageCode, $content); + + $options['input'] = 'datetime'; + $options['widget'] = 'choice'; + $options['constraints'][] = new Assert\Date(); + + $formBuilder->add( + $fieldDefinition->identifier, + BirthdayType::class, + $options + ); + } +} \ No newline at end of file diff --git a/lib/Form/Type/FieldType/Birthday/Value.php b/lib/Form/Type/FieldType/Birthday/Value.php new file mode 100644 index 00000000..8de6c33c --- /dev/null +++ b/lib/Form/Type/FieldType/Birthday/Value.php @@ -0,0 +1,41 @@ +date = $date->setTime(0, 0); + } elseif (is_string($date)) { + $this->date = new DateTimeImmutable($date); + } + } + + public function __toString(): string + { + if (!$this->date instanceof DateTimeInterface) { + return ''; + } + + return $this->date->format($this->dateFormat); + } +} \ No newline at end of file diff --git a/lib/Resources/config/form_fieldtype_handlers.yaml b/lib/Resources/config/form_fieldtype_handlers.yaml index 032dab57..09769315 100644 --- a/lib/Resources/config/form_fieldtype_handlers.yaml +++ b/lib/Resources/config/form_fieldtype_handlers.yaml @@ -97,3 +97,8 @@ services: - "@ibexa.api.repository" tags: - { name: netgen_information_collections.form.fieldtype_handler, alias: ezobjectrelationlist } + + netgen_birthday.field_type.form_handler: + class: Netgen\Bundle\InformationCollectionBundle\Form\FieldTypeHandler\Birthday + tags: + - { name: netgen_information_collections.form.fieldtype_handler, alias: ezbirthday } \ No newline at end of file From e46037b4f3affb84bf956bb8fbb520d48214e0d9 Mon Sep 17 00:00:00 2001 From: Marijan Klaric Date: Wed, 20 Mar 2024 15:45:32 +0100 Subject: [PATCH 83/87] CED-1124 remove FieldTypeHandlerInterface from Ibexa Forms bundle in FieldTypeHandlerRegistry.php --- bundle/Form/FieldTypeHandlerRegistry.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/bundle/Form/FieldTypeHandlerRegistry.php b/bundle/Form/FieldTypeHandlerRegistry.php index 65888426..5e84c52a 100644 --- a/bundle/Form/FieldTypeHandlerRegistry.php +++ b/bundle/Form/FieldTypeHandlerRegistry.php @@ -41,17 +41,17 @@ public function register(string $identifier, FieldTypeHandlerInterface $handler) * @throws \OutOfBoundsException * @throws \RuntimeException When type is not a FieldTypeHandlerInterface instance nor a callable factory */ - public function get(string $identifier): FieldTypeHandlerInterface|\Netgen\Bundle\IbexaFormsBundle\Form\FieldTypeHandlerInterface + public function get(string $identifier): FieldTypeHandlerInterface { if (!isset($this->map[$identifier])) { throw new OutOfBoundsException("No handler registered for FieldType '{$identifier}'."); } - if (!$this->map[$identifier] instanceof FieldTypeHandlerInterface && !$this->map[$identifier] instanceof \Netgen\Bundle\IbexaFormsBundle\Form\FieldTypeHandlerInterface) { + if (!$this->map[$identifier] instanceof FieldTypeHandlerInterface) { $factory = $this->map[$identifier]; $this->map[$identifier] = $factory(); - if (!$this->map[$identifier] instanceof FieldTypeHandlerInterface && !$this->map[$identifier] instanceof \Netgen\Bundle\IbexaFormsBundle\Form\FieldTypeHandlerInterface) { + if (!$this->map[$identifier] instanceof FieldTypeHandlerInterface) { throw new RuntimeException( "FieldTypeHandler '{$identifier}' callable did not return a FieldTypeHandlerInterface instance, " . 'instead: ' . gettype($this->map[$identifier]) From 9fb2e010823a018b5457ee5bc048ae4d365546a4 Mon Sep 17 00:00:00 2001 From: Marijan Klaric Date: Wed, 20 Mar 2024 16:20:25 +0100 Subject: [PATCH 84/87] CED-1124 change class namespace in configuration --- lib/Resources/config/admin.yml | 4 ++-- lib/Resources/config/services.yml | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/Resources/config/admin.yml b/lib/Resources/config/admin.yml index 5eaff537..0164a911 100644 --- a/lib/Resources/config/admin.yml +++ b/lib/Resources/config/admin.yml @@ -53,7 +53,7 @@ services: - !tagged_iterator netgen_information_collection.export.formatter netgen_information_collection.form.type.export: - class: Netgen\Bundle\InformationCollectionBundle\Form\ExportType + class: Netgen\Bundle\InformationCollectionBundle\Form\Type\ExportType arguments: - "@netgen_information_collection.core.export.registry" tags: @@ -66,7 +66,7 @@ services: - "@netgen_information_collection.form.fieldtype_handler_registry" netgen_information_collection.form.type.information_collection_update: - class: Netgen\Bundle\InformationCollectionBundle\Form\InformationCollectionUpdateType + class: Netgen\Bundle\InformationCollectionBundle\Form\Type\InformationCollectionUpdateType # public: false arguments: - "@netgen_information_collection.form.fieldtype_handler_registry" diff --git a/lib/Resources/config/services.yml b/lib/Resources/config/services.yml index d25bd9d8..7e86aa27 100644 --- a/lib/Resources/config/services.yml +++ b/lib/Resources/config/services.yml @@ -100,7 +100,7 @@ services: - { name: netgen_information_collection.export.formatter } netgen_information_collection.form.captcha_type: - class: Netgen\Bundle\InformationCollectionBundle\Form\CaptchaType + class: Netgen\Bundle\InformationCollectionBundle\Form\Type\CaptchaType arguments: - '@netgen_information_collection.listener.captcha_validation' tags: From fc5f4d2cd6ef66ada603f4c00e62bc601a8b3f16 Mon Sep 17 00:00:00 2001 From: Marijan Klaric Date: Thu, 21 Mar 2024 09:41:49 +0100 Subject: [PATCH 85/87] CED-1124 add enhanced selection handler --- bundle/Form/FieldTypeHandler/Birthday.php | 3 +- .../FieldTypeHandler/EnhancedSelection.php | 80 +++++++++++++++++++ .../FieldType/EnhancedSelection/Value.php | 31 +++++++ .../config/form_fieldtype_handlers.yaml | 11 ++- 4 files changed, 121 insertions(+), 4 deletions(-) create mode 100644 bundle/Form/FieldTypeHandler/EnhancedSelection.php create mode 100644 lib/Form/Type/FieldType/EnhancedSelection/Value.php diff --git a/bundle/Form/FieldTypeHandler/Birthday.php b/bundle/Form/FieldTypeHandler/Birthday.php index 501ea5f7..3fd3a28a 100644 --- a/bundle/Form/FieldTypeHandler/Birthday.php +++ b/bundle/Form/FieldTypeHandler/Birthday.php @@ -11,6 +11,7 @@ use Symfony\Component\Form\Extension\Core\Type\BirthdayType; use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\Validator\Constraints as Assert; + class Birthday extends FieldTypeHandler { /** @@ -48,4 +49,4 @@ protected function buildFieldForm( $options ); } -} \ No newline at end of file +} diff --git a/bundle/Form/FieldTypeHandler/EnhancedSelection.php b/bundle/Form/FieldTypeHandler/EnhancedSelection.php new file mode 100644 index 00000000..0de9ba1b --- /dev/null +++ b/bundle/Form/FieldTypeHandler/EnhancedSelection.php @@ -0,0 +1,80 @@ +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/lib/Form/Type/FieldType/EnhancedSelection/Value.php b/lib/Form/Type/FieldType/EnhancedSelection/Value.php new file mode 100644 index 00000000..832c2024 --- /dev/null +++ b/lib/Form/Type/FieldType/EnhancedSelection/Value.php @@ -0,0 +1,31 @@ +identifiers = $identifiers; + } + + public function __toString(): string + { + return implode(', ', $this->identifiers); + } +} + diff --git a/lib/Resources/config/form_fieldtype_handlers.yaml b/lib/Resources/config/form_fieldtype_handlers.yaml index 09769315..94cf7bbc 100644 --- a/lib/Resources/config/form_fieldtype_handlers.yaml +++ b/lib/Resources/config/form_fieldtype_handlers.yaml @@ -96,9 +96,14 @@ services: arguments: - "@ibexa.api.repository" tags: - - { name: netgen_information_collections.form.fieldtype_handler, alias: ezobjectrelationlist } + - { name: netgen_information_collection.form.fieldtype_handler, alias: ezobjectrelationlist } - netgen_birthday.field_type.form_handler: + netgen_information_collection.form.fieldtype_handler.ezbirthday: class: Netgen\Bundle\InformationCollectionBundle\Form\FieldTypeHandler\Birthday tags: - - { name: netgen_information_collections.form.fieldtype_handler, alias: ezbirthday } \ No newline at end of file + - { name: netgen_information_collection.form.fieldtype_handler, alias: ezbirthday } + + netgen_information_collection.form.fieldtype_handler.sckenhancedselection: + class: Netgen\Bundle\InformationCollectionBundle\Form\FieldTypeHandler\EnhancedSelection + tags: + - { name: netgen_information_collection.form.fieldtype_handler, alias: sckenhancedselection } From 2c7935708b0debd3a8dfb40b00b41ceae9eeffd2 Mon Sep 17 00:00:00 2001 From: Marijan Klaric Date: Thu, 21 Mar 2024 12:50:26 +0100 Subject: [PATCH 86/87] CED-1124 standardize EnhancedSelection.php and Birthday.php with FieldTypeHandlerInterface --- bundle/Form/FieldTypeHandler/Birthday.php | 2 +- bundle/Form/FieldTypeHandler/EnhancedSelection.php | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/bundle/Form/FieldTypeHandler/Birthday.php b/bundle/Form/FieldTypeHandler/Birthday.php index 3fd3a28a..b7d2956b 100644 --- a/bundle/Form/FieldTypeHandler/Birthday.php +++ b/bundle/Form/FieldTypeHandler/Birthday.php @@ -22,7 +22,7 @@ public function convertFieldValueToForm(Value $value, ?FieldDefinition $fieldDef return $value->date; } - public function convertFieldValueFromForm($data): BirthdayValue + public function convertFieldValueFromForm(mixed $data): BirthdayValue { if (empty($data)) { $data = null; diff --git a/bundle/Form/FieldTypeHandler/EnhancedSelection.php b/bundle/Form/FieldTypeHandler/EnhancedSelection.php index 0de9ba1b..f0f61b28 100644 --- a/bundle/Form/FieldTypeHandler/EnhancedSelection.php +++ b/bundle/Form/FieldTypeHandler/EnhancedSelection.php @@ -14,6 +14,9 @@ final class EnhancedSelection extends FieldTypeHandler { + /** + * @param \Netgen\InformationCollection\Form\Type\FieldType\EnhancedSelection\Value $value + */ public function convertFieldValueToForm(Value $value, ?FieldDefinition $fieldDefinition = null): mixed { $isMultiple = true; @@ -33,7 +36,7 @@ public function convertFieldValueToForm(Value $value, ?FieldDefinition $fieldDef return $value->identifiers; } - public function convertFieldValueFromForm($data): EnhancedSelectionValue + public function convertFieldValueFromForm(mixed $data): EnhancedSelectionValue { if ($data === null) { return new EnhancedSelectionValue(); From ffdd8eb9d3b4aaebc538fc46d344e18746913db8 Mon Sep 17 00:00:00 2001 From: Marijan Klaric Date: Thu, 21 Mar 2024 13:28:05 +0100 Subject: [PATCH 87/87] CED-1124 change input type and remove constraint in Birthday.php --- bundle/Form/FieldTypeHandler/Birthday.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/bundle/Form/FieldTypeHandler/Birthday.php b/bundle/Form/FieldTypeHandler/Birthday.php index b7d2956b..0f5c0aaa 100644 --- a/bundle/Form/FieldTypeHandler/Birthday.php +++ b/bundle/Form/FieldTypeHandler/Birthday.php @@ -39,9 +39,8 @@ protected function buildFieldForm( ): void { $options = $this->getDefaultFieldOptions($fieldDefinition, $languageCode, $content); - $options['input'] = 'datetime'; + $options['input'] = 'datetime_immutable'; $options['widget'] = 'choice'; - $options['constraints'][] = new Assert\Date(); $formBuilder->add( $fieldDefinition->identifier,