I'm using Neo blocks as part of an import process and I'm struggling to figure out how to do this via PHP.

The following code snippet (a standard approach of setting the field value with an array which I've used hundreds of times) doesn't seem to work with Neo as it does with Matrix and SuperTable:

$blocks = [
    'new1' => [
        'id' => 'blockid'
        'type' => 'somehandle'
        'enabled' => true,
        'fields' => [

The following snippet was the only way I was actually able to get the parent block to save was:

$field = Craft::$app->fields->getFieldById($entry->myNeoField->fieldId);
$entry->setFieldValue('myNeoField', $field->normalizeValue($blocks, $entry));
// Then save the entry

Now I'm really getting nowhere trying to save any blocks within the Neo block. Any help would be appreciated, there doesn't appear to be any documentation for how to do this, nor are there any answers on GitHub or on here.

  • For now I'm just going to have to do it manually, e.g. find the block, set the ownerId, typeId, fieldId etc for each sub block, was just hoping there was an easier way! – Jay May 16 '19 at 17:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.