Skip to content

Commit 483899e

Browse files
committed
fix(Export): also return uuid for selection options
Signed-off-by: Arthur Schiwon <blizzz@arthur-schiwon.de>
1 parent 0757454 commit 483899e

1 file changed

Lines changed: 19 additions & 2 deletions

File tree

lib/Model/SelectionOption.php

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,17 @@
1010
namespace OCA\Tables\Model;
1111

1212
class SelectionOption implements \JsonSerializable {
13+
private string $uuid;
1314

1415
public function __construct(
1516
private readonly int $key,
1617
private readonly string $label,
1718
) {
1819
}
1920

21+
/**
22+
* @psalm-param array{id: int|string, label: string, uuid?: string} $data
23+
*/
2024
public static function createFromInputArray(array $data, bool $allowPassingUuid = false): self {
2125
if (!isset($data['id']) || !is_numeric($data['id'])) {
2226
throw new \InvalidArgumentException('Only integer keys are allowed for options');
@@ -30,7 +34,11 @@ public static function createFromInputArray(array $data, bool $allowPassingUuid
3034
throw new \InvalidArgumentException('It is forbidden to set the Uuid from external');
3135
}
3236

33-
return new self((int)$data['id'], $data['label']);
37+
$instance = new self((int)$data['id'], $data['label']);
38+
if (isset($data['uuid'])) {
39+
$instance->setUuid($data['uuid']);
40+
}
41+
return $instance;
3442
}
3543

3644
public function key(): int {
@@ -41,11 +49,20 @@ public function label(): string {
4149
return $this->label;
4250
}
4351

52+
protected function setUuid(string $uuid): void {
53+
$this->uuid = $uuid;
54+
}
55+
4456
#[\Override]
4557
public function jsonSerialize(): array {
46-
return [
58+
$out = [
4759
'id' => $this->key,
4860
'label' => $this->label,
4961
];
62+
/** @psalm-suppress RedundantPropertyInitializationCheck */
63+
if (isset($this->uuid)) {
64+
$out['uuid'] = $this->uuid;
65+
}
66+
return $out;
5067
}
5168
}

0 commit comments

Comments
 (0)