通过内容管理php-sdk创建一个包含RichText数据的条目



我已经广泛搜索了这个问题的答案,联系了满足的支持(但被忽略了(,并尝试了我能想到的每一种排列。如有任何帮助,我们将不胜感激。

我想通过具有RichText内容的内容管理sdk创建一个新条目。

设置者:

$entry->setField('rtf', 'en-GB', file_get_contents('content-blocks/rtf/zzz.rtf'));

该文件的内容为:

{
"nodeType": "document",
"data": {},
"content": [
{
"nodeType": "paragraph",
"content": [
{
"nodeType": "text",
"value": "Test text",
"marks": [],
"data": {}
}
],
"data": {}
}
]
}

我还尝试过直接输入内容、去除空白等。这个json块也是由contentlets自己的markdown到richtext转换器生成的。

响应:

{n
"sys": {n
"type": "Error",n
"id": "InvalidEntry"n
},n
"message": "Validation error",n
"details": {n
"errors": [n
{n
"name": "type",n
"value": "{n  "nodeType": "document",n  "data": {},n  "content": [n    {n      "nodeType": "paragraph",n      "content": [n        {n          "nodeType": "text",n          "value": "Test text",n          "marks": [],n          "data": {}n        }n      ],n      "data": {}n    }n  ]n}n",n
"type": "RichText",n
"details": "The type of "value" is incorrect, expected type: RichText",n
"path": [n
"fields",n
"rtf",n
"en-US"n
]n
}n
]n
},n
"requestId": "a603e57d716b7af9c5c8078f2701fc41"n
}n

该场景的文档不存在,因此您能提供的任何帮助都将不胜感激。

这是一个老问题,但如果有人偶然发现它,就会有一个封闭的Github问题包含答案。

通过PHP SDK#160 将HTML字符串转换为RichText

还有一个结构更简化的例子:

$bodyValue = [
'data' => [],
'content' => [
[
'nodeType' => 'paragraph',
'content' => [
[
'nodeType' => 'text',
'data' => [],
'value' => 'Hello, is it me you're looking for?',
'marks' => [
['type' => 'code'],
],
],
],
'data' => [],
],
],
'nodeType' => 'document',
];
$entry->setField('rtf', 'en-GB', $bodyValue);

相关内容

最新更新