mirror of
https://github.com/nextcloud/server.git
synced 2026-02-20 00:12:30 -05:00
fix: Field and FieldType implementation
Signed-off-by: Elizabeth Danzberger <lizzy7128@tutanota.de>
This commit is contained in:
parent
4efdb9b438
commit
49cc5beccc
2 changed files with 32 additions and 8 deletions
|
|
@ -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(FieldType $type) {
|
||||
$this->type = $type;
|
||||
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 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…
Reference in a new issue