1
0

RichTextField.php 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
  5. * SPDX-License-Identifier: AGPL-3.0-or-later
  6. */
  7. namespace OCP\Files\Template\Fields;
  8. use OCP\Files\Template\Field;
  9. use OCP\Files\Template\FieldType;
  10. /**
  11. * @since 30.0.0
  12. */
  13. class RichTextField extends Field {
  14. private string $content = '';
  15. /**
  16. * @since 30.0.0
  17. */
  18. public function __construct(string $index, FieldType $type) {
  19. parent::__construct($index, $type);
  20. }
  21. /**
  22. * @since 30.0.0
  23. */
  24. public function setValue(mixed $value): void {
  25. if (!is_string($value)) {
  26. throw new \Exception('Invalid value for rich-text field type');
  27. }
  28. $this->content = $value;
  29. }
  30. /**
  31. * @return array{
  32. * index: string,
  33. * type: string,
  34. * alias: ?string,
  35. * tag: ?string,
  36. * id: ?int,
  37. * content?: string,
  38. * checked?: bool,
  39. * }
  40. * @since 30.0.0
  41. */
  42. public function jsonSerialize(): array {
  43. $jsonProperties = parent::jsonSerialize();
  44. return array_merge($jsonProperties, ['content' => $this->content]);
  45. }
  46. }