From cb07053322c0f0333b5699a87049f366ab4931f0 Mon Sep 17 00:00:00 2001 From: Christoph Leitgeb <98694299+leitge@users.noreply.github.com> Date: Sun, 5 Nov 2023 19:58:09 +0100 Subject: [PATCH 1/5] Update 20_DataObject_Mutations.md --- doc/10_GraphQL/07_Mutation/20_DataObject_Mutations.md | 1 + 1 file changed, 1 insertion(+) diff --git a/doc/10_GraphQL/07_Mutation/20_DataObject_Mutations.md b/doc/10_GraphQL/07_Mutation/20_DataObject_Mutations.md index 5345e6ae..432de25e 100644 --- a/doc/10_GraphQL/07_Mutation/20_DataObject_Mutations.md +++ b/doc/10_GraphQL/07_Mutation/20_DataObject_Mutations.md @@ -35,6 +35,7 @@ Also check out the Pimcore's [data type documentation](https://pimcore.com/docs/ * Image * ImageGallery * Input +* Input Quantity Value * Language * Lastname * Link From 02924a325489ea9532eb83c643bb152abe3447c5 Mon Sep 17 00:00:00 2001 From: Christoph Leitgeb <98694299+leitge@users.noreply.github.com> Date: Sun, 5 Nov 2023 19:58:51 +0100 Subject: [PATCH 2/5] Create InputQuantityValue.php --- .../InputQuantityValue.php | 48 +++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 src/GraphQL/DataObjectInputProcessor/InputQuantityValue.php diff --git a/src/GraphQL/DataObjectInputProcessor/InputQuantityValue.php b/src/GraphQL/DataObjectInputProcessor/InputQuantityValue.php new file mode 100644 index 00000000..976e6d68 --- /dev/null +++ b/src/GraphQL/DataObjectInputProcessor/InputQuantityValue.php @@ -0,0 +1,48 @@ +getAttribute(); + Service::setValue($object, $attribute, function ($container, $setter) use ($newValue) { + if ($newValue) { + $unit = \Pimcore\Model\DataObject\QuantityValue\Unit::getByAbbreviation($newValue['unit']); + $inputQuantityValue = new \Pimcore\Model\DataObject\Data\InputQuantityValue($newValue['value'], $unit); + + return $container->$setter($inputQuantityValue); + } + + return null; + }); + } +} From dc857f8b6ba298535b2bdad4432b4709c171609d Mon Sep 17 00:00:00 2001 From: Christoph Leitgeb <98694299+leitge@users.noreply.github.com> Date: Sun, 5 Nov 2023 20:01:06 +0100 Subject: [PATCH 3/5] Create InputQuantityValue.php --- .../InputQuantityValue.php | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 src/GraphQL/DataObjectMutationFieldConfigGenerator/InputQuantityValue.php diff --git a/src/GraphQL/DataObjectMutationFieldConfigGenerator/InputQuantityValue.php b/src/GraphQL/DataObjectMutationFieldConfigGenerator/InputQuantityValue.php new file mode 100644 index 00000000..8d9b1841 --- /dev/null +++ b/src/GraphQL/DataObjectMutationFieldConfigGenerator/InputQuantityValue.php @@ -0,0 +1,31 @@ +setGraphQLService($this->getGraphQlService()); + + return [ + 'arg' => $this->getGraphQlService()->getDataObjectTypeDefinition('input_quantity_value_input'), + 'processor' => [$processor, 'process'] + ]; + } +} From e267f9b5d8732298dd93ae50378fb65f4b78a79a Mon Sep 17 00:00:00 2001 From: Christoph Leitgeb <98694299+leitge@users.noreply.github.com> Date: Sun, 5 Nov 2023 20:03:04 +0100 Subject: [PATCH 4/5] Create InputQuantityValueInputType.php --- .../InputQuantityValueInputType.php | 51 +++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 src/GraphQL/DataObjectType/InputQuantityValueInputType.php diff --git a/src/GraphQL/DataObjectType/InputQuantityValueInputType.php b/src/GraphQL/DataObjectType/InputQuantityValueInputType.php new file mode 100644 index 00000000..eba4a8cc --- /dev/null +++ b/src/GraphQL/DataObjectType/InputQuantityValueInputType.php @@ -0,0 +1,51 @@ + 'InputQuantityValueInput']) + { + $this->setGraphQLService($graphQlService); + $this->build($config); + parent::__construct($config); + } + + /** + * @param array $config + */ + public function build(&$config) + { + $resolver = new \Pimcore\Bundle\DataHubBundle\GraphQL\Resolver\DataObject($this->getGraphQlService()); + $resolver->setGraphQLService($this->getGraphQlService()); + + $config['fields'] = [ + 'value' => Type::string(), + 'unit' => Type::string(), + ]; + } +} From 700e0e3e2e6e32b363b78cd7b5cce3baf9ba8c41 Mon Sep 17 00:00:00 2001 From: Christoph Leitgeb <98694299+leitge@users.noreply.github.com> Date: Sun, 5 Nov 2023 20:09:58 +0100 Subject: [PATCH 5/5] Update graphql.yml --- src/Resources/config/graphql.yml | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/Resources/config/graphql.yml b/src/Resources/config/graphql.yml index 9a2f23d6..f83a796b 100644 --- a/src/Resources/config/graphql.yml +++ b/src/Resources/config/graphql.yml @@ -37,6 +37,7 @@ services: pimcore.datahub.graphql.dataobjecttype.elementdescriptor_input: '@Pimcore\Bundle\DataHubBundle\GraphQL\DataObjectType\ElementDescriptorInputType' pimcore.datahub.graphql.dataobjecttype.geopoint_input: '@Pimcore\Bundle\DataHubBundle\GraphQL\DataObjectType\GeopointInputType' pimcore.datahub.graphql.dataobjecttype.quantity_value_input: '@Pimcore\Bundle\DataHubBundle\GraphQL\DataObjectType\QuantityValueInputType' + pimcore.datahub.graphql.dataobjecttype.input_quantity_value_input: '@Pimcore\Bundle\DataHubBundle\GraphQL\DataObjectType\InputQuantityValueInputType' pimcore.datahub.graphql.dataobjecttype.object_tree: '@Pimcore\Bundle\DataHubBundle\GraphQL\DataObjectType\ObjectTreeType' pimcore.datahub.graphql.dataobjecttype._object_folder: '@Pimcore\Bundle\DataHubBundle\GraphQL\DataObjectType\ObjectFolderType' @@ -732,6 +733,10 @@ services: tags: - { name: pimcore.datahub.graphql.dataobjecttype, id: input_quantity_value } + Pimcore\Bundle\DataHubBundle\GraphQL\DataObjectType\InputQuantityValueInputType: + tags: + - { name: pimcore.datahub.graphql.dataobjecttype, id: input_quantity_value_input } + Pimcore\Bundle\DataHubBundle\GraphQL\DataObjectType\QuantityValueType: tags: - { name: pimcore.datahub.graphql.dataobjecttype, id: quantity_value } @@ -1000,6 +1005,11 @@ services: tags: - { name: pimcore.datahub.graphql.dataobjectmutationtypegenerator, id: typegenerator_dataobjectmutationdatatype_quantityValue } + pimcore.datahub.graphql.dataobjectmutationtypegenerator_datatype_inputQuantityValue: + class: Pimcore\Bundle\DataHubBundle\GraphQL\DataObjectMutationFieldConfigGenerator\InputQuantityValue + tags: + - { name: pimcore.datahub.graphql.dataobjectmutationtypegenerator, id: typegenerator_dataobjectmutationdatatype_inputQuantityValue } + pimcore.datahub.graphql.dataobjectmutationtypegenerator_datatype_table: class: Pimcore\Bundle\DataHubBundle\GraphQL\DataObjectMutationFieldConfigGenerator\Table tags: