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: