1

I am trying to programatiacally add two new neo blocks to an entry. It works, but it overwrites any manual added blocks that already exists in that entry.

For context:
I have an entry with three neo blocks, textModule, imageGallery and logoBlock. So I just want to update the entry with two more blocks, hero and a second textModule.

'projectBuilder' => [ // Neo field handle
        'blocks' => [
          'new0' => [
            'modified' => 1,
            'type' => 'hero', // Neo block handle
            'enabled' => 1,
            'collapsed' => 0,
            'level' => 0,
            'fields' => [
              'pageHeading' => "Heading", // Neo block field
            ]
          ],
          'new1' => [
            'modified' => 1,
            'type' => 'textModule', // Neo block handle
            'enabled' => 1,
            'collapsed' => 0,
            'level' => 1,
            'fields' => [
              'moduleHeading' => "Heading", // Neo block field
              'paragraph' => "Description", // Neo block field
            ],
          ],
        ],
        'sortOrder' => [
          'new0',
          'new1',
        ],

How do I add new blocks to an existing entry without deleting the existing blocks?

1 Answer 1

2

First, get values of existing block and append with values of new block and update with looping neo field blocks one by one.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.