aboutsummaryrefslogtreecommitdiffstats
path: root/lib/public/Files/Template/Fields/RichTextField.php
blob: 93ead68747c64b32e0a26d11866f84016555a191 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
<?php

declare(strict_types=1);

/**
 * SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
 * SPDX-License-Identifier: AGPL-3.0-or-later
 */

namespace OCP\Files\Template\Fields;

use OCP\Files\Template\Field;
use OCP\Files\Template\FieldType;

/**
 * @since 30.0.0
 */
class RichTextField extends Field {
	private string $content = '';

	/**
	 * @since 30.0.0
	 */
	public function __construct(string $index, FieldType $type) {
		parent::__construct($index, $type);
	}

	/**
	 * @since 30.0.0
	 */
	public function setValue(mixed $value): void {
		if (!is_string($value)) {
			throw new \Exception('Invalid value for rich-text field type');
		}

		$this->content = $value;
	}

	/**
	 * @return array{
	 *     index: string,
	 *     type: string,
	 *     alias: ?string,
	 *     tag: ?string,
	 *     id: ?int,
	 *     content?: string,
	 *     checked?: bool,
	 * }
	 * @since 30.0.0
	 */
	public function jsonSerialize(): array {
		$jsonProperties = parent::jsonSerialize();

		return array_merge($jsonProperties, ['content' => $this->content]);
	}
}