Reputation: 1709
I have searched extensively for an answer to this, contacted contentful support (and being ignored) and tried every permutation I can possible think of. Any help would be appreciated.
I want to create a new entry via the contentful management sdk with RichText content.
The setter:
$entry->setField('rtf', 'en-GB', file_get_contents('content-blocks/rtf/zzz.rtf'));
The contents of that file are:
{
"nodeType": "document",
"data": {},
"content": [
{
"nodeType": "paragraph",
"content": [
{
"nodeType": "text",
"value": "Test text",
"marks": [],
"data": {}
}
],
"data": {}
}
]
}
I have also tried directly inputting the contents, stripping whitespace etc. This json block is also generated from contentfuls own markdown to richtext converter.
The response:
{\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
The docs for this scenario are non-existent so any help you can give would be appreciated.
Upvotes: 1
Views: 1172
Reputation: 173
This is an old question but if anyone stumbles upon it there is a closed Github Issue that contains the answer.
HTML String to RichText via PHP SDK #160
And an Example with a more simplified structure:
$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);
Upvotes: 0