Skip to content

Commit 44514c4

Browse files
committed
refactor: implement JsonSerializable in wysiwyg_editor_data
1 parent 796802b commit 44514c4

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

classes/local/api/wysiwyg_editor_data.php

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,12 @@
1616

1717
namespace qtype_questionpy\local\api;
1818

19+
use coding_exception;
20+
use JsonSerializable;
21+
use qtype_questionpy\local\array_converter\array_converter;
1922
use qtype_questionpy\local\array_converter\attributes\array_element_class;
2023
use qtype_questionpy\local\array_converter\attributes\array_key;
24+
use qtype_questionpy\local\array_converter\conversion_exception;
2125
use qtype_questionpy\local\files\file_metadata;
2226

2327
/**
@@ -28,7 +32,7 @@
2832
* @copyright 2025 TU Berlin, innoCampus {@link https://www.questionpy.org}
2933
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
3034
*/
31-
class wysiwyg_editor_data {
35+
class wysiwyg_editor_data implements JsonSerializable {
3236
/**
3337
* Initialize a new WYSIWYG editor data instance.
3438
*
@@ -47,4 +51,16 @@ public function __construct(
4751
public array $files = [],
4852
) {
4953
}
54+
55+
/**
56+
* Specify data which should be serialized to JSON
57+
* @link https://php.net/manual/en/jsonserializable.jsonserialize.php
58+
* @return mixed data which can be serialized by <b>json_encode</b>,
59+
* which is a value of any type other than a resource.
60+
* @throws coding_exception
61+
* @throws conversion_exception
62+
*/
63+
public function jsonSerialize(): mixed {
64+
return array_converter::to_array($this);
65+
}
5066
}

0 commit comments

Comments
 (0)