getkirby / kirby

Kirby's core application folder
https://getkirby.com
Other
1.27k stars 167 forks source link

Selected image get's removed from content block when changing status directly draft to listed #4824

Closed teichsta closed 1 year ago

teichsta commented 1 year ago

Description

It seems the files field knows different options to store the URL of the selected image. There are different pages in my content which either shows an url like "61tup44laul._ac_sl1000.jpg" or "news/1654862078883/img_7327.jpeg" (see more complete example below). As long as the parent page doesn't change this makes no different. However when changing the URL of the page or duplicating the page this leads to problems.

Expected behavior

I would expect to see the image URL without the page part of the URL as this would help duplicating pages and alike.

Screenshots

Blueprint of the image block

name: field.blocks.image.name
icon: file-image
preview: image

tabs:
  main:
    label: Datei
    fields:
      image:
        label: field.blocks.image.name
        type: files
        search: false
        multiple: false
        required: true
        query: page.images
        image:
          back: black
        uploads: poolfile
      caption:
        label: Bildunterschrift
        type: text
        icon: text
      credits:
        label: Quelle
        type: hidden
        icon: text
[
    {
        "content": {
            "image": [
                "61tup44laul._ac_sl1000.jpg"
            ],
            "caption": "",
            "credits": null,
            "headline": "",
            "link": "",
            "ratio": "",
            "crop": "false",
            "width": "col-lg-auto",
            "width_mobile": "col",
            "no_padding_top": "false",
            "no_padding_bottom": "false"
        },
        "id": "4c63e77e-13d0-4bbb-b204-64b75ea0b017",
        "isHidden": false,
        "type": "image"
    }
]

and in another file (same blueprint)

[
    {
        "content": {
            "image": [
                "news/1654862078883/img_7327.jpeg"
            ],
            "caption": "",
            "credits": "Klasse 2c",
            "headline": "",
            "link": "",
            "ratio": "",
            "crop": "false",
            "width": "col-lg-auto",
            "width_mobile": "col"
        },
        "id": "3cdf314c-48a3-416e-8082-a8c97dd0a21f",
        "isHidden": false,
        "type": "image"
    },
    [...]

To reproduce

unfortunately i cannot really tell … 

Your setup

php 8.1, kirby 3.7.5.1

Thanks for having an educated look into this. If i can assist with any more details, please let me know.

teichsta commented 1 year ago

Investigated further and found this:

Start with creating a post i see this in the content file:

Article-content:

[
    {
        "content": {
            "image": [
                "klasse-4d-schwarzer-fuerst-1.jpg"
            ],
            "caption": "",
            "credits": null,
            "headline": "",
            "link": "",
            "ratio": "",
            "crop": "false",
            "width": "col-lg-auto",
            "width_mobile": "col",
            "no_padding_top": "false",
            "no_padding_bottom": "false"
        },
        "id": "2882b258-f82a-4cac-ab83-77d6e6735c89",
        "isHidden": false,
        "type": "image"
    },
    {
        "content": {
            "title": "Raster",
            "grid": "[{\"attrs\":[],\"columns\":[{\"blocks\":[{\"content\":{\"image\":[\"klasse-4d-schwarzer-fuerst-2.jpg\"],\"caption\":\"\",\"credits\":null,\"headline\":\"\",\"link\":\"\",\"ratio\":\"\",\"crop\":\"false\",\"width\":\"col-lg-auto\",\"width_mobile\":\"col\",\"no_padding_top\":\"false\",\"no_padding_bottom\":\"false\"},\"id\":\"0aa70932-d884-45e7-808a-5a24590de4a2\",\"isHidden\":false,\"type\":\"image\"}],\"id\":\"fd4a3196-2682-484b-a5d8-96dce565db30\",\"width\":\"1\\/2\"},{\"blocks\":[{\"content\":{\"image\":[\"klasse-4d-schwarzer-fuerst-3.jpg\"],\"caption\":\"\",\"credits\":null,\"headline\":\"\",\"link\":\"\",\"ratio\":\"\",\"crop\":\"false\",\"width\":\"col-lg-auto\",\"width_mobile\":\"col\",\"no_padding_top\":\"false\",\"no_padding_bottom\":\"false\"},\"id\":\"5f5bb3dc-10d5-4f62-8a6e-97411875f539\",\"isHidden\":false,\"type\":\"image\"}],\"id\":\"cde001fa-24f3-4a27-a6b2-460019970bb5\",\"width\":\"1\\/2\"}],\"id\":\"17d7f7d0-57e1-4c1b-bc21-d60eaf793f42\"}]"
        },
        "id": "37c14849-9c4e-4782-bab3-6e58c64bb8d9",
        "isHidden": false,
        "type": "grid"
    }
]

change status to unlisted:

 Article-content:

[
    {
        "content": {
            "image": [
                "klasse-4d-schwarzer-fuerst-1.jpg"
            ],
            "caption": "",
            "credits": null,
            "headline": "",
            "link": "",
            "ratio": "",
            "crop": "false",
            "width": "col-lg-auto",
            "width_mobile": "col",
            "no_padding_top": "false",
            "no_padding_bottom": "false"
        },
        "id": "2882b258-f82a-4cac-ab83-77d6e6735c89",
        "isHidden": false,
        "type": "image"
    },
    {
        "content": {
            "title": "Raster",
            "grid": "[{\"attrs\":[],\"columns\":[{\"blocks\":[{\"content\":{\"image\":[\"klasse-4d-schwarzer-fuerst-2.jpg\"],\"caption\":\"\",\"credits\":null,\"headline\":\"\",\"link\":\"\",\"ratio\":\"\",\"crop\":\"false\",\"width\":\"col-lg-auto\",\"width_mobile\":\"col\",\"no_padding_top\":\"false\",\"no_padding_bottom\":\"false\"},\"id\":\"0aa70932-d884-45e7-808a-5a24590de4a2\",\"isHidden\":false,\"type\":\"image\"}],\"id\":\"fd4a3196-2682-484b-a5d8-96dce565db30\",\"width\":\"1\\/2\"},{\"blocks\":[{\"content\":{\"image\":[\"klasse-4d-schwarzer-fuerst-3.jpg\"],\"caption\":\"\",\"credits\":null,\"headline\":\"\",\"link\":\"\",\"ratio\":\"\",\"crop\":\"false\",\"width\":\"col-lg-auto\",\"width_mobile\":\"col\",\"no_padding_top\":\"false\",\"no_padding_bottom\":\"false\"},\"id\":\"5f5bb3dc-10d5-4f62-8a6e-97411875f539\",\"isHidden\":false,\"type\":\"image\"}],\"id\":\"cde001fa-24f3-4a27-a6b2-460019970bb5\",\"width\":\"1\\/2\"}],\"id\":\"17d7f7d0-57e1-4c1b-bc21-d60eaf793f42\"}]"
        },
        "id": "37c14849-9c4e-4782-bab3-6e58c64bb8d9",
        "isHidden": false,
        "type": "grid"
    }
]

BUT after changing to listed the image urls change to

[
    {
        "content": {
            "image": [
                "news/laternen-test/klasse-4d-schwarzer-fuerst-1.jpg"
            ],
            "caption": "",
            "credits": null,
            "headline": "",
            "link": "",
            "ratio": "",
            "crop": "false",
            "width": "col-lg-auto",
            "width_mobile": "col",
            "no_padding_top": "false",
            "no_padding_bottom": "false"
        },
        "id": "2882b258-f82a-4cac-ab83-77d6e6735c89",
        "isHidden": false,
        "type": "image"
    },
    {
        "content": {
            "title": "Raster",
            "grid": "[{\"attrs\":[],\"columns\":[{\"blocks\":[{\"content\":{\"image\":[\"news\\/laternen-test\\/klasse-4d-schwarzer-fuerst-2.jpg\"],\"caption\":\"\",\"credits\":null,\"headline\":\"\",\"link\":\"\",\"ratio\":\"\",\"crop\":\"false\",\"width\":\"col-lg-auto\",\"width_mobile\":\"col\",\"no_padding_top\":\"false\",\"no_padding_bottom\":\"false\"},\"id\":\"0aa70932-d884-45e7-808a-5a24590de4a2\",\"isHidden\":false,\"type\":\"image\"}],\"id\":\"fd4a3196-2682-484b-a5d8-96dce565db30\",\"width\":\"1\\/2\"},{\"blocks\":[{\"content\":{\"image\":[\"news\\/laternen-test\\/klasse-4d-schwarzer-fuerst-3.jpg\"],\"caption\":\"\",\"credits\":null,\"headline\":\"\",\"link\":\"\",\"ratio\":\"\",\"crop\":\"false\",\"width\":\"col-lg-auto\",\"width_mobile\":\"col\",\"no_padding_top\":\"false\",\"no_padding_bottom\":\"false\"},\"id\":\"5f5bb3dc-10d5-4f62-8a6e-97411875f539\",\"isHidden\":false,\"type\":\"image\"}],\"id\":\"cde001fa-24f3-4a27-a6b2-460019970bb5\",\"width\":\"1\\/2\"}],\"id\":\"17d7f7d0-57e1-4c1b-bc21-d60eaf793f42\"}]"
        },
        "id": "37c14849-9c4e-4782-bab3-6e58c64bb8d9",
        "isHidden": false,
        "type": "grid"
    }
]

This is the "good" case, because when changing the status from draft to listed the content gets changed and all referenced files gets deleted, see:

Article-content:

[
    {
        "content": {
            "image": [],
            "caption": "",
            "credits": null,
            "headline": "",
            "link": "",
            "ratio": "",
            "crop": "false",
            "width": "col-lg-auto",
            "width_mobile": "col",
            "no_padding_top": "false",
            "no_padding_bottom": "false"
        },
        "id": "2882b258-f82a-4cac-ab83-77d6e6735c89",
        "isHidden": false,
        "type": "image"
    },
    {
        "content": {
            "title": "Raster",
            "grid": "[{\"attrs\":[],\"columns\":[{\"blocks\":[{\"content\":{\"image\":[],\"caption\":\"\",\"credits\":null,\"headline\":\"\",\"link\":\"\",\"ratio\":\"\",\"crop\":\"false\",\"width\":\"col-lg-auto\",\"width_mobile\":\"col\",\"no_padding_top\":\"false\",\"no_padding_bottom\":\"false\"},\"id\":\"0aa70932-d884-45e7-808a-5a24590de4a2\",\"isHidden\":false,\"type\":\"image\"}],\"id\":\"fd4a3196-2682-484b-a5d8-96dce565db30\",\"width\":\"1\\/2\"},{\"blocks\":[{\"content\":{\"image\":[],\"caption\":\"\",\"credits\":null,\"headline\":\"\",\"link\":\"\",\"ratio\":\"\",\"crop\":\"false\",\"width\":\"col-lg-auto\",\"width_mobile\":\"col\",\"no_padding_top\":\"false\",\"no_padding_bottom\":\"false\"},\"id\":\"5f5bb3dc-10d5-4f62-8a6e-97411875f539\",\"isHidden\":false,\"type\":\"image\"}],\"id\":\"cde001fa-24f3-4a27-a6b2-460019970bb5\",\"width\":\"1\\/2\"}],\"id\":\"17d7f7d0-57e1-4c1b-bc21-d60eaf793f42\"}]"
        },
        "id": "37c14849-9c4e-4782-bab3-6e58c64bb8d9",
        "isHidden": false,
        "type": "grid"
    }
]

Any idea @afbora why this could happen? I am going to reproduce this issue with a clean starterkit now.

teichsta commented 1 year ago

update: clean startetkit 3.7.5 works … also the URLs remain unchanged in starterkit. So the culprit seems to be one of the plugins. Will keep you posted …