Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
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).
Comment | File | Size | Author |
---|---|---|---|
#10 | Screen Shot 2019-03-11 at 2.59.05 PM.png | 78.11 KB | minorOffense |
#4 | entityreference-undefined-index-notice-2299179-4-D7.patch | 973 bytes | prabeen.giri |
Comments
Comment #1
prabeen.giri CreditAttribution: prabeen.giri commentedComment #2
prabeen.giri CreditAttribution: prabeen.giri commentedComment #3
prabeen.giri CreditAttribution: prabeen.giri commentedComment #4
prabeen.giri CreditAttribution: prabeen.giri commentedAdded the patch!!
Comment #5
prabeen.giri CreditAttribution: prabeen.giri commentedComment #6
maen CreditAttribution: maen commentedI had exactly this problem and this patch solved it!
Comment #7
ongdesign CreditAttribution: ongdesign commentedResolved similar "undefined index" on Redhen contact entity.
Comment #8
DamienMcKennaComment #9
Yuri CreditAttribution: Yuri commentedI confirm that the patch works, thanks.
Comment #10
minorOffense CreditAttribution: minorOffense at Coldfront Labs Inc. commentedAll entities need a least one bundle even if it's just the single bundle. User is the perfect example.
Closing as works as designed.