spicywebau / craft-neo

A Matrix-like field type for Craft CMS that uses existing fields
Other
403 stars 63 forks source link

Programmatically populating Neo field value with multiple blocks only creates first block #898

Closed corneliusio closed 1 week ago

corneliusio commented 2 weeks ago

Bug Description

I'm needing to populate a neo field with multiple blocks in Craft 4.x, however only the first block is ever saved. This does not appear to be an issue in Craft 5.x.

This didn't use to be an issue but I'm not sure when it started.

Steps to reproduce

$entry = Entry::find()->section('sectionHandle')->one();

$entry->setFieldValue('fieldHandle', [
    [
        'modified' => 1,
        'type' => 'blockType',
        'enabled' => 1,
        'collapsed' => 0,
        'level' => 1,
        'fields' => [
            // …
        ],
    ],
    [
        'modified' => 1,
        'type' => 'blockType',
        'enabled' => 1,
        'collapsed' => 0,
        'level' => 1,
        'fields' => [
            // …
        ],
    ],
]);

Craft::$app->elements->saveElement($entry);

Expected behaviour

In the above example only the first block is saved but would expect to have two blocks.

Neo version

4.2.4

Craft CMS version

4.10.2

What is the affected Neo field's propagation method?

Only save blocks to the site they were created in

Does this issue involve templating, and if so, is eager-loading used?

This is not a templating issue

corneliusio commented 2 weeks ago

Noting that this is also happening for a non-multisite setup with no propagation method.

ttempleton commented 1 week ago

Thanks for reporting that - fixed now in 4.2.5.