From 5456da0e63bff8b3da18c0592a0b658f8132119b Mon Sep 17 00:00:00 2001 From: Christoph Leitgeb <98694299+leitge@users.noreply.github.com> Date: Thu, 1 Feb 2024 13:53:31 +0100 Subject: [PATCH] Add mutation datatype 'input quantity value' (#812) * Update 20_DataObject_Mutations.md * Create InputQuantityValue.php * Create InputQuantityValue.php * Create InputQuantityValueInputType.php * Update graphql.yml --- .../07_Mutation/20_DataObject_Mutations.md | 1 + .../InputQuantityValue.php | 48 +++++++++++++++++ .../InputQuantityValue.php | 31 +++++++++++ .../InputQuantityValueInputType.php | 51 +++++++++++++++++++ src/Resources/config/graphql.yml | 10 ++++ 5 files changed, 141 insertions(+) create mode 100644 src/GraphQL/DataObjectInputProcessor/InputQuantityValue.php create mode 100644 src/GraphQL/DataObjectMutationFieldConfigGenerator/InputQuantityValue.php create mode 100644 src/GraphQL/DataObjectType/InputQuantityValueInputType.php 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 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; + }); + } +} 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'] + ]; + } +} 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(), + ]; + } +} 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: