From 0f8be143dfb50ee029d0e1be828997fb45a2d798 Mon Sep 17 00:00:00 2001 From: Jens Schuppe Date: Wed, 17 Jul 2024 11:08:39 +0200 Subject: [PATCH] follow-up to #136: copy missing core function --- .../Spec/Provider/EckEntitySpecProvider.php | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/Civi/Api4/Service/Spec/Provider/EckEntitySpecProvider.php b/Civi/Api4/Service/Spec/Provider/EckEntitySpecProvider.php index b77ba91..9e9d0a1 100644 --- a/Civi/Api4/Service/Spec/Provider/EckEntitySpecProvider.php +++ b/Civi/Api4/Service/Spec/Provider/EckEntitySpecProvider.php @@ -116,6 +116,26 @@ private static function arrayToField(array $data, string $entityName): FieldSpec return $field; } + /** + * Get the data type from an array. Defaults to 'data_type' with fallback to + * mapping for the integer value 'type' + * + * @param array $data + * + * @return string + */ + private static function getDataType(array $data) { + $dataType = $data['data_type'] ?? $data['dataType'] ?? NULL; + if (isset($dataType)) { + return !empty($data['time_format']) ? 'Timestamp' : $dataType; + } + + $dataTypeInt = $data['type'] ?? NULL; + $dataTypeName = \CRM_Utils_Type::typeToString($dataTypeInt); + + return $dataTypeName === 'Int' ? 'Integer' : $dataTypeName; + } + /** * Copied from \Civi\Api4\Service\Spec\SpecFormatter *