<p>I just figured it out.</p>

<p>For anyone facing the same issue, here is what worked for me:</p>

<pre><code>$entryData = self::setupEntryData($item);
$entry = new Entry($entryData);

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

$entry-&gt;setFieldValues($fieldValues);
</code></pre>

CC BY-SA 4.0
2020-05-29T13:50:31.710Z
2020-05-29T13:50:31.710Z
Danail Emandiev
<p>I wish to programmatically set the value of a Neo field.<br>
This is my current approach:</p>

<pre><code>$entryData = self::setupEntryData($item);
$entry = new Entry($entryData);

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

$entry-&gt;setFieldValues($fieldValues);
</code></pre>

<p>Of course this doesn't work.<br>
Can someone point me in the right direction?<br>
Here is a screenshot of the Form Data that is passed when setting the value manually from Craft CMS.<br>
<a href="https://i.sstatic.net/PmHJ0.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/PmHJ0.png" alt="enter image description here"></a></p>

<p>Just to confirm, my Neo field is called <code>blocks</code>.<br>
My target blog type has a handle of <code>wysiwyg</code>.<br>
The Redactor field I target has a handle of <code>wysiwyg</code>.  </p>

<p>Thank you!</p>

<saveentry><plugin-neo>
How can I set a Neo field's values from my plugin/module?
# How can I set a Neo field's values from my plugin/module?

(Asked by: username_0 on 2020-05-29)

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' => 'test',
                    '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.

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!

**Tags:** saveentry, plugin-neo

---

## 1 answers

### Answer by username_0 on 2020-05-29. Score: 4

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' => 'test', // Neo block field
                'buttons' => null, // Neo block field
            ]
        ]
    ],
];

$entry->setFieldValues($fieldValues);


---

