I have a problem. In elastic search, we have data returned as follows:
"uuid": "8f39a450-64c2-407c-9836-32ed3b4db1ce",
"locale": "de",
"title": "Blah nedvsger",
"route_path": "/articles/blah-nedvsger",
"type": "news",
"type_translation": "sulu_article.news",
"structure_type": "news",
"changer_full_name": "Adam Ministrator",
"creator_full_name": "Adam Ministrator",
"changed": "2021-07-06T09:52:42+0000",
"created": "2021-07-06T09:49:50+0000",
"excerpt": {},
"seo": {},
"authored": "2021-07-06T09:49:50+0000",
"author_full_name": "Adam Ministrator",
"teaser_description": "",
"published": "2021-07-06T09:49:51+0000",
"published_state": true,
"localization_state": {},
"author_id": 1,
"creator_contact_id": 1,
"changer_contact_id": 1,
"pages": [],
"content_data": "{\"title\":\"Blah nedvsger\",\"routePath\":\"\\/articles\\/blah-nedvsger\",\"hero_image\":{\"id\":null},\"overline\":\"asfdafasdf\",\"headline\":\"adfgasdf\",\"auth\":[\"c1\"],\"introduction\":\"asdfd\",\"blocks\":[],\"related\":{\"audienceTargeting\":null,\"categories\":null,\"categoryOperator\":\"or\",\"dataSource\":null,\"includeSubFolders\":null,\"limitResult\":null,\"presentAs\":null,\"sortBy\":\"published\",\"sortMethod\":\"asc\",\"tagOperator\":\"or\",\"types\":[\"country\",\"default\",\"fascination\",\"news\"],\"tags\":null}}",
"main_webspace": "magazine",
"additional_webspaces": [
"olympics2021"
],
"content_fields": []
Now, I want to show value of field "headline" from content_data, and we've done this:
ADDDED articles.xml column as:
<property
name="contentData"
visibility="always"
translation="Content data"
>
<transformer type="json.headline" />
</property>
Created Json.js, with code (npm run build, and all):
import React from 'react';
import type {Node} from 'react';
import type {FieldTransformer} from 'sulu-admin-bundle/types';
export default class JsonHeadlineTransformer implements FieldTransformer {
transform(value: *): Node
{
console.log(value);
let json = {};
try
{
json = JSON.parse(value);
}
catch (error)
{
return;
}
if('headline' in json)
{
return json.headline;
}
}
}
And it returns empty string. In console it returns undefined. Where are we wrong?