Hi, I am creating an entity for my D7 Module and trying to include a user_reference auto-complete field in it. The autocomplete-field shows up correctly with the add-more option since I have set cardinality to unlimited.

However, nothing shows up in auto-complete suggestions and it doesn't accept any of the user-instances.

Even more annoying is that when I go and check the field settings in
Home » Administration » Structure » Content types » » Manage fields
and click on Save without making any changes, the suggestions start appearing correctly as they should.

I have written down the following settings for the field and the instance.

field :

 'vocabulary_authors' => array(
      'field_name' => 'vocabulary_authors',
      'type'        => 'user_reference',
      'settings' => array(
        'referenceable_roles' => array('2','3'),  // for authenticated user + administrator
        'referenceable_status' => array('1'),    // for active
      ),
      'default_widget' => 'user_reference_autocomplete', 
      'default_formatter' => 'user_reference_default',
      'cardinality' => FIELD_CARDINALITY_UNLIMITED,
    ),

instance :

 'vocabulary_authors' => array(
      'field_name'  => 'vocabulary_authors',
      'label'       => $t(' Authors'),
      'bundle' => 'vocabulary',
      'entity_type' => 'node',
      'description' => '',
      'required'    => FALSE,
      'widget' => array(
        'type'    => 'user_reference_autocomplete',
        'settings' => array(
         'autocomplete_match' => 'starts_with',
        ),
      ),

Please help me out here. I think I am I missing out on some required settings.

Comments

scor’s picture

have you tried setting up the user reference via the regular UI (not using code to create the field)? are you using the -dev version of the references module?

mayankkandpal’s picture

Version: 7.x-2.x-dev » 7.x-2.0-beta3

Yes @scor, I am able to set up the field using only UI.

Also, as I mentioned in the issue, it starts working as expected when I just open the UI and save it without making any changes to the settings inherited from the code I have shown above.

And I am using the 7.x-2.0-beta3 release, not the dev version.

scor’s picture

make sure to use the <code> tag to wrap your code in, so it looks better (I fixed your OP for now).

I would try to export this field using features and see how it gets exported, and check you haven't made any typo.

mayankkandpal’s picture

I was hoping that a maintainer of References could provide his opinion too.

mayankkandpal’s picture

Status: Active » Closed (fixed)