1

I wish to programmatically set the value of a Neo field.
This is my current approach:

$entryData = self::setupEntryData($item);
$entry = new Entry($entryData);

$fieldValues = [
    'heading' => $entryData['title'],
    'blocks' => [
        'blocks' => [
            'new0' => [
                'modified' => 1,
                'type' => 'wysiwyg',
                'enabled' => 1,
                'collapsed' => 0,
                'level' => 0,
                'fields' => [
                    'grayBackground' => true,
                    'wysiwyg' => '<p>test</p>',
                    'buttons' => null,
                ]
            ]
        ]
    ],
];

$entry->setFieldValues($fieldValues);

Of course this doesn't work.
Can someone point me in the right direction?
Here is a screenshot of the Form Data that is passed when setting the value manually from Craft CMS.
enter image description here

Just to confirm, my Neo field is called blocks.
My target blog type has a handle of wysiwyg.
The Redactor field I target has a handle of wysiwyg.

Thank you!

3

I just figured it out.

For anyone facing the same issue, here is what worked for me:

$entryData = self::setupEntryData($item);
$entry = new Entry($entryData);

$fieldValues = [
    'blocks' => [ // Neo field handle
        'new0' => [
            'modified' => 1,
            'type' => 'wysiwyg', // Neo block handle
            'enabled' => 1,
            'collapsed' => 0,
            'level' => 0,
            'fields' => [
                'grayBackground' => true, // Neo block field
                'wysiwyg' => '<p>test</p>', // Neo block field
                'buttons' => null, // Neo block field
            ]
        ]
    ],
];

$entry->setFieldValues($fieldValues);

Your Answer

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

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