From 053f11f6dcfa5016234ca97472a8d23601e5ee38 Mon Sep 17 00:00:00 2001 From: Sebastian Blank Date: Fri, 17 May 2024 09:50:10 +0200 Subject: [PATCH] Fix: Labels get lowercased (#853) * Fix: Labels get lowercased * Fix: Labels get lowercased * Enrich php doc --- .../Base.php | 17 +++++++++++++---- .../Merge.php | 14 -------------- 2 files changed, 13 insertions(+), 18 deletions(-) diff --git a/src/GraphQL/DataObjectQueryOperatorConfigGenerator/Base.php b/src/GraphQL/DataObjectQueryOperatorConfigGenerator/Base.php index 9dc91347..9825a076 100644 --- a/src/GraphQL/DataObjectQueryOperatorConfigGenerator/Base.php +++ b/src/GraphQL/DataObjectQueryOperatorConfigGenerator/Base.php @@ -59,10 +59,7 @@ public function getGraphQlType($typeName, $nodeDef, $class = null, $container = public function getGraphQlQueryOperatorConfig($typeName, $nodeDef, $class = null, $container = null, $params = []) { $attributes = $nodeDef['attributes']; - $label = (isset($attributes['label']) ? $attributes['label'] : '#' . uniqid()); - $label = lcfirst($label); - $fieldname = preg_replace('/[^A-Za-z0-9\-\.~_]+/', '_', $label); - + $fieldname = $this->getFieldname($attributes); $type = $this->getGraphQlType($typeName, $nodeDef, $class, $container, $params); $resolver = new \Pimcore\Bundle\DataHubBundle\GraphQL\Resolver\Base($typeName, $attributes, $class, $container); @@ -105,4 +102,16 @@ public function getFieldType($attributes, $class = null, $container = null) { return Type::string(); } + + /** + * @param array{label?: string} $attributes + * + * @return string|null + */ + protected function getFieldname($attributes) + { + $label = $attributes['label'] ?? '#' . uniqid(); + + return preg_replace('/[^A-Za-z0-9\-\.~_]+/', '_', $label); + } } diff --git a/src/GraphQL/DataObjectQueryOperatorConfigGenerator/Merge.php b/src/GraphQL/DataObjectQueryOperatorConfigGenerator/Merge.php index f0b4151e..975801fa 100644 --- a/src/GraphQL/DataObjectQueryOperatorConfigGenerator/Merge.php +++ b/src/GraphQL/DataObjectQueryOperatorConfigGenerator/Merge.php @@ -26,20 +26,6 @@ */ class Merge extends StringBase { - /** - * @param array $attributes - * - * @return array|string|string[]|null - */ - protected function getFieldname($attributes) - { - $label = ($attributes['label'] ? $attributes['label'] : '#'.uniqid()); - $label = lcfirst($label); - $fieldname = preg_replace('/[^A-Za-z0-9\-\.~_]+/', '_', $label); - - return $fieldname; - } - /** * @param string $typeName * @param array $nodeConfig