xiaohutai / jsonapi

[Bolt Extension] JSON API for Bolt CMS

Home Page:https://market.bolt.cm/view/bolt/jsonapi

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Fieldtype „block“ contains wrong content

binarykiwi opened this issue · comments

I defined a contenttype using the 'block' fieldtype like this one:

test:
    name: Test
    singular_name: Test
    singular_slug: test
    fields:
        title:
            label: Global Heading
            type: text
        description:
            label: Global Text
            type: html
        blocks:
            label: Content Elements
            type: block
            fields:
                titlesection:
                    label: Title Section
                    fields:
                        heading:
                            type: text
                textsection:
                    label: Text Section
                    fields:
                        heading:
                            type: text
                        description:
                            type: textarea
                videosection:
                    label: Video Section
                    fields:
                        heading:
                            type: text
                        video:
                            type: video

Now, entering some test content and calling /json/test/1 gives this result:

{
    "links": {
        "self": "http:\/\/test.local\/json\/test\/1"
    },
    "data": {
        "id": "1",
        "type": "test",
        "attributes": {
            "datechanged": "2018-04-11T16:58:58+02:00",
            "title": "Global Heading",
            "description": "<p>Global Text<\/p>\r\n",
            "blocks": [
                {
                    "heading": "Title Section Heading",
                    "_block": "titlesection"
                },
                {
                    "heading": "",
                    "_block": "textsection",
                    "description": "Text Description with no defined heading."
                },
                {
                    "heading": "Video Section Heading",
                    "_block": "videosection",
                    "description": "Text Description with no defined heading.",
                    "video": {
                        "url": "",
                        "width": "",
                        "height": "",
                        "title": "",
                        "authorname": "",
                        "ratio": "",
                        "authorurl": "",
                        "html": "",
                        "thumbnail": ""
                    }
                },
                {
                    "heading": "",
                    "_block": "textsection",
                    "description": "see what happpens",
                    "video": {
                        "url": "",
                        "width": "",
                        "height": "",
                        "title": "",
                        "authorname": "",
                        "ratio": "",
                        "authorurl": "",
                        "html": "",
                        "thumbnail": ""
                    }
                }
            ]
        },
        "links": {
            "self": "http:\/\/test.local\/json\/test\/1"
        }
    }
}

Look at the result. If a block does not contain an element of the previous block the content of the previous block shows up in its successor. Eg. the textsection has no field video but in the json there is one - or the videosection has no field description but in the json there is one...

I guess this might be a bug and should be fixed.

Just made a release. Fixed in v3.0.18