fix: `Field` and `FieldType` implementation

Signed-off-by: Elizabeth Danzberger <lizzy7128@tutanota.de>
pull/46383/head
Elizabeth Danzberger 7 months ago committed by Julius Härtl
parent 4efdb9b438
commit 49cc5beccc
No known key found for this signature in database
GPG Key ID: 4C614C6ED2CDE6DF
  1. 34
      lib/public/Files/Template/Field.php
  2. 6
      lib/public/Files/Template/FieldType.php

@ -5,14 +5,38 @@
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace OCA\Richdocuments\Template;
namespace OCP\Files\Template;
class Field {
private FieldType $type;
class Field implements \JsonSerializable {
private int $index;
private string $content;
private FieldType $type;
private ?int $id;
private ?string $tag;
public function __construct($index, $content, $type, $id = null, $tag = null) {
$this->index = $index;
$this->id = $id;
$this->tag = $tag;
// TODO: Sanitize content
$this->content = $content;
if ($type instanceof FieldType) {
$this->type = $type;
} else {
// TODO: Throw a proper enum with descriptive message
$this->type = FieldType::tryFrom($type) ?? throw new \Exception();
}
}
public function __construct(FieldType $type) {
$this->type = $type;
public function jsonSerialize(): array {
return [
"index" => $this->index,
"content" => $this->content,
"type" => $this->type->value,
"id" => $this->id,
"tag" => $this->tag,
];
}
}

@ -5,8 +5,8 @@
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace OCA\Richdocuments\Template;
namespace OCP\Files\Template;
enum FieldType {
case PlainText;
enum FieldType: string {
case PlainText = "plain-text";
}

Loading…
Cancel
Save