Skip to content

Commit 95ceaa9

Browse files
authored
Merge pull request #27 from LibreCodeCoop/feat/multiselect-field-type
feat: add multiselect profile field type
2 parents 2ab1020 + 0b2b815 commit 95ceaa9

25 files changed

+414
-44
lines changed
-4.7 KB
Loading

img/screenshots/admin-catalog.png

3.67 KB
Loading
-83 Bytes
Loading
-1.46 KB
Loading
2.02 KB
Loading
11.6 KB
Loading
0 Bytes
Loading

lib/Enum/FieldType.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ enum FieldType: string {
1313
case TEXT = 'text';
1414
case NUMBER = 'number';
1515
case SELECT = 'select';
16+
case MULTISELECT = 'multiselect';
1617

1718
/**
1819
* @return list<string>
@@ -22,6 +23,7 @@ public static function values(): array {
2223
self::TEXT->value,
2324
self::NUMBER->value,
2425
self::SELECT->value,
26+
self::MULTISELECT->value,
2527
];
2628
}
2729

lib/ResponseDefinitions.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
namespace OCA\ProfileFields;
1111

1212
/**
13-
* @psalm-type ProfileFieldsType = 'text'|'number'|'select'
13+
* @psalm-type ProfileFieldsType = 'text'|'number'|'select'|'multiselect'
1414
* @psalm-type ProfileFieldsVisibility = 'private'|'users'|'public'
1515
* @psalm-type ProfileFieldsEditPolicy = 'admins'|'users'
1616
* @psalm-type ProfileFieldsExposurePolicy = 'hidden'|'private'|'users'|'public'

lib/Service/FieldDefinitionValidator.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class FieldDefinitionValidator {
2929
* @return array{
3030
* field_key: non-empty-string,
3131
* label: non-empty-string,
32-
* type: 'text'|'number'|'select',
32+
* type: 'text'|'number'|'select'|'multiselect',
3333
* edit_policy: 'admins'|'users',
3434
* exposure_policy: 'hidden'|'private'|'users'|'public',
3535
* sort_order: int,
@@ -78,12 +78,13 @@ public function validate(array $definition): array {
7878
* @return list<string>|null
7979
*/
8080
private function validateOptions(string $type, mixed $options): ?array {
81-
if ($type !== FieldType::SELECT->value) {
81+
$isSelectLike = in_array($type, [FieldType::SELECT->value, FieldType::MULTISELECT->value], true);
82+
if (!$isSelectLike) {
8283
return null;
8384
}
8485

8586
if (!is_array($options) || count($options) === 0) {
86-
throw new InvalidArgumentException('select fields require at least one option');
87+
throw new InvalidArgumentException($type . ' fields require at least one option');
8788
}
8889

8990
$normalized = [];

0 commit comments

Comments
 (0)