whitecube/nova-flexible-content

Migrating to flexible fields with images

merijnponzo opened this issue · 2 comments

I am trying to migrate content into flexible content with spaties media library

I first checked how the structure of my flexible field looks like whenever uploading an image:
Json in my table column 'content'

[{
  "key": "cYoFTE5H9jLBxZx1",
  "layout": "largevisual",
  "attributes": {
    "media": [
      {
        "key": "cPVsiltAD2JZ8Xci",
        "layout": "medialayout",
        "attributes": {
          "link": null,
          "title": null
        }
      }
    ]
  }
}]

And the related image:
Screenshot 2023-07-04 at 11 44 25

So after the migration it looks 1:1 similar (except for the key, this will be different with every image)

[{
  "key": "8yb8wIFW0QCzhF8K",
  "layout": "largevisual",
  "attributes": {
    "media": {
      "key": "cOhwRSY5LrTK06mp",
      "layout": "medialayout",
      "attributes": {
        "link": null,
        "title": null
      }
    }
  }
}]

I created key with Str helper like "cOhwRSY5LrTK06mp" and added them to my spatie image so the key of my related image is the same.

Screenshot 2023-07-04 at 11 44 43

However, after the migration i can see all the 'largevisual' blocks, but no images are attached.
And when i press update the media attribute get's empty.

The image key like "cOhwRSY5LrTK06mp" only occurs in my media table and my pages table.
Am i missing something ?

Any help appreciated

I changed my model_type to \Page but it's still not showing up

Okay after hours of debugging it looks likes my structure wasn't 1:1
The images should be stored into an array, while i was migrating one image as an object

if ($image_key) {
                                // 
                                $randomStringTwo = Str::random(16);
                                $new_block = [
                                    "key" => $randomStringTwo,
                                    "layout" => "largevisual",
                                    "attributes" =>  [
                                        "media" => [
                                                [
                                                // add collection key to image
                                                "key" => $image_key,
                                                "layout" => "medialayout",
                                                "attributes" => [
                                                    "link" => null,
                                                    "title" =>  null
                                                ]
                                            ]
                                        ],
                                        "title" => null,
                                        "heading" =>  null
                                    ]
                                ];
                                array_push($new_content, $new_block);
                            }

now it's working