When entity reference field is selected with the custom created entity with just one bundle, then bundle selection is not listed in the field settings and hence treats the bundle with same as the entity type name.

However, while listing the select options, it uses entity_get_info() which list all the bundles, but in the field_config table there is no any information of the bundle, i.e target_bundles does not have bundles thats listed in the custom hook_entity_info().

Entity reference field config:

array (
    'target_type' => 'manufacturer',
    'handler' => 'base',
    'handler_settings' => 
    array (
      'target_bundles' => 
      array (
      ),
      'sort' => 
      array (
        'type' => 'property',
        'property' => 'manufacturer_nm',
        'direction' => 'ASC',
      ),
      'behaviors' => 
      array (
        'views-select-list' => 
        array (
          'status' => 0,
        ),
      ),
    ),
    'handler_submit' => 'Change handler',
  ),

Custom Entity Definition

function my_module_entity_info() {
$return = array(
    'MyEntity' => array(
      'label' => t('MyEntity'),
      'controller class' => 'EntityAPIController',
      'base table' => 'my_entity',
      'entity keys' => array(
        'id' => 'eid',
        'uuid' => 'uuid',
        'label' => 'my_entity_name',
      ),
      'uri callback' => 'entity_class_uri',
      'module' => 'my_entity',
      'fieldable' => TRUE,
    	'bundles' => array(
        'my_entity_instance'=> array(
          'label' => 'My Entity',
          'admin' => array(
            'path' => 'admin/structure/my_entity/manage/%bundle_key',
            // This is unique to each bundle.
            'real path' => 'admin/structure/my_entity/manage/manufacturer',
            'bundle argument' => 4,  // Arg 4 is %bundle_key.
            // What ever permission that you've assigned in hook_permissions.
            'access arguments' => array('administer users'),
          ),
        ),
      ),
      'uuid' => TRUE,
    ),
  );
  return $return;
}

As a result it generates

Notice: Undefined index: my_entity in entityreference_options_list() (line 778 of C:\wamp\www\miconnect\sites\all\modules\entityreference\entityreference.module).
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

prabeen.giri’s picture

Issue summary: View changes
prabeen.giri’s picture

Issue summary: View changes
prabeen.giri’s picture

Title: Undefined Index when used to custom entity » Undefined Index when used with custom entity
prabeen.giri’s picture

Added the patch!!

prabeen.giri’s picture

Status: Needs work » Needs review
maen’s picture

I had exactly this problem and this patch solved it!

ongdesign’s picture

Status: Needs review » Reviewed & tested by the community

Resolved similar "undefined index" on Redhen contact entity.

DamienMcKenna’s picture

Yuri’s picture

I confirm that the patch works, thanks.

minorOffense’s picture

Status: Reviewed & tested by the community » Closed (works as designed)
FileSize
78.11 KB

All entities need a least one bundle even if it's just the single bundle. User is the perfect example.

User Bundle

Closing as works as designed.