I've created custom entity. In addition I want to add user reference field to my entity:
if (! field_info_field(MY_FIELD_NAME)) {
// Create the field.
$field = array(
'field_name' => MY_FIELD_NAME,
'type' => 'entityreference',
'cardinality' => FIELD_CARDINALITY_UNLIMITED,
'settings' => array(
'target_type' => 'user',
'handler' => 'base',
'handler_settings' => array(
'target_bundles' => array()
),
),
'bundles' => array (
MY_ENTITY_NAME =>
array (
0 => MY_ENTITY_BUNDLE_NAME,
),
),
);
field_create_field($field);
// Create the instance.
$instance = array(
'field_name' => MY_FIELD_NAME,
'entity_type' => MY_ENTITY_NAME,
'bundle' => MY_ENTITY_BUNDLE_NAME,
'label' => '',
'description' => '',
'required' => TRUE,
'widget' => array(),
'display' => array(
'default' => array(
'label' => 'hidden',
),
),
);
field_create_instance($instance);
}
In form submit I want to add users references to this field:
foreach($result as $recipient) {
$wrapper->{MY_FIELD_NAME}[] = $recipient->uid;
}
I gets:
Fatal error: Cannot use object of type EntityDrupalWrapper as array
What I am missing?