* @return string
* String identifying the data type, e.g. 'Int' or 'String'.
*/
- public static function typeToString($type) {
+ public static function typeToString($type): string {
// @todo Use constants in the case statements, e.g. "case T_INT:".
// @todo return directly, instead of assigning a value.
// @todo Use a lookup array, as a property or as a local variable.
break;
}
- return (isset($string)) ? $string : "";
+ return $string ?? '';
}
/**
* @return string
*/
private static function getDataType(array $data) {
- if (isset($data['data_type'])) {
- return !empty($data['time_format']) ? 'Timestamp' : $data['data_type'];
+ $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;
+ return $dataTypeName === 'Int' ? 'Integer' : $dataTypeName;
}
/**
self::setLegacyDateFormat($inputAttrs);
}
// Number input for numeric fields
- if ($inputType === 'Text' && in_array($dataTypeName, ['Int', 'Float'], TRUE)) {
+ if ($inputType === 'Text' && in_array($dataTypeName, ['Integer', 'Float'], TRUE)) {
$inputType = 'Number';
// Todo: make 'step' configurable for the custom field
- $inputAttrs['step'] = $dataTypeName === 'Int' ? 1 : .01;
+ $inputAttrs['step'] = $dataTypeName === 'Integer' ? 1 : .01;
}
// Date/time settings from custom fields
if ($inputType == 'Date' && !empty($data['custom_group_id'])) {
use Civi\Api4\CustomGroup;
use Civi\Api4\Email;
use Civi\Api4\EntityTag;
+use Civi\Api4\OptionValue;
use Civi\Api4\UserJob;
use Civi\Api4\Utils\CoreUtil;
use Civi\Test\TransactionalInterface;
$this->assertTrue($aclFields['is_active']['default_value']);
$this->assertFalse($aclFields['is_active']['nullable']);
$this->assertFalse($aclFields['is_active']['required']);
+
+ $optionValueFields = OptionValue::getFields(FALSE)
+ ->setAction('create')
+ ->execute()->indexBy('name');
+ $this->assertIsInt($optionValueFields['filter']['default_value']);
+ $this->assertEquals(0, $optionValueFields['filter']['default_value']);
}
public function testGetSuffixes(): void {