field_create_field enable chosen I am using field_create_field and field_create_instance to create a taxonomy_autocomplete field in a rules action.



Can anyone help me enable chosen by default for these fields?

$vocab = '[vocabulary:machine-name]';

$field = array(
  'field_name' =&gt; 'field_termref_' . $vocab,
  'type' =&gt; 'taxonomy_term_reference',
  'settings' =&gt; array(
    'allowed_values' =&gt; array(
      array(
        'vocabulary' =&gt; $vocab,
        'parent' =&gt; 0
      ),
    ),
  ),
);
field_create_field($field);

$instance = array(
    'field_name' =&gt; 'field_termref_' . $vocab,
    'entity_type' =&gt; 'node',
    'label' =&gt; '[vocabulary:name]',
    'bundle' =&gt; 'product',
    'required' =&gt; false,
    'widget' =&gt; array(
        'type' =&gt; 'taxonomy_autocomplete'
    ),
    'display' =&gt; array(
        'default' =&gt; array('type' =&gt; 'hidden'),
        'teaser' =&gt; array('type' =&gt; 'hidden')
    )
);

field_create_instance($instance);
Using devels dpm function i managed to find the correct name of the setting, so the following now works...

$vocab = '[vocabulary:machine-name]';

$field = array(
  'field_name' =&gt; 'field_termref_' . $vocab,
  'type' =&gt; 'taxonomy_term_reference',
  'cardinality' =&gt; -1,
  'settings' =&gt; array(
    'allowed_values' =&gt; array(
      array(
        'vocabulary' =&gt; $vocab,
        'parent' =&gt; 0
      ),
    ),
  ),
);
field_create_field($field);

$instance = array(
    'field_name' =&gt; 'field_termref_' . $vocab,
    'entity_type' =&gt; 'node',
    'label' =&gt; '[vocabulary:name]',
    'bundle' =&gt; 'product',
    'required' =&gt; false,
    'widget' =&gt; array(
        'type' =&gt; 'options_select',
        'settings' =&gt; array(
           'apply_chosen' =&gt; 1
        )
    ),
    'display' =&gt; array(
        'default' =&gt; array('type' =&gt; 'hidden'),
        'teaser' =&gt; array('type' =&gt; 'hidden')
    )
);