I want to add a user reference field in taxonomy term. I create field and it's instance:
$field = ['field_name' => 'mymodule_employee',
'label' => t('Employee'),
'type' => 'entityreference',
'cardinality' => 1,
'settings' => [
'target_type' => 'user',
'handler' => 'base',
'handler_settings' => [
'target_bundles' => ['user']
],
],
];
field_create_field($field);
$instance = ['mymodule_employee' => [
'entity_type' => 'taxonomy_term',
'bundle' => 'my_vocabulary',
'field_name' => 'mymodule_employee',
'label' => t('Employee'),
'widget' => array(
'type' => 'options_select',
'active' => 1,
),
'settings' => array(
'target_type' => 'user',
'handler_settings' => array('target_bundles' => null),
'handler' => 'base',
),
'display' => array(
'default' => array('label' => 'inline', 'type' => 'entityreference_label'),
),
'required' => 0,
'default_value' => null,
],
];
field_create_instance($instance);
Everything goes ok. But when I'm creating the term and try to choose a user there is an empty list. When I go to the field settings in admin form and just save it, everything begins to work.
What do I forget creating field and instance?