Set value for custom field
You don't need to worry as the entity API should take care of the specific structure and just set it via:

$entity-&gt;set('field_myfield', 'some value');
$entity-&gt;save();