diff --git a/entityreference.module b/entityreference.module index 6609672..0e76562 100644 --- a/entityreference.module +++ b/entityreference.module @@ -762,12 +762,21 @@ function entityreference_field_widget_settings_form($field, $instance) { * Implements hook_options_list(). */ function entityreference_options_list($field, $instance = NULL, $entity_type = NULL, $entity = NULL) { - $options = entityreference_get_selection_handler($field, $instance, $entity_type, $entity)->getReferencableEntities(); - if (count($options) == 1) { - $key = key($options); - $options = $options[$key]; + if (!$options = entityreference_get_selection_handler($field, $instance, $entity_type, $entity)->getReferencableEntities()) { + return array(); } - return $options; + + // Rebuild the array, by changing the bundle key into the bundle label. + $target_type = $field['settings']['target_type']; + $entity_info = entity_get_info($target_type); + + $return = array(); + foreach ($options as $bundle => $entity_ids) { + $bundle_label = check_plain($entity_info['bundles'][$bundle]['label']); + $return[$bundle_label] = $entity_ids; + } + + return count($return) == 1 ? reset($return) : $return; } /** diff --git a/plugins/selection/EntityReference_SelectionHandler_Generic.class.php b/plugins/selection/EntityReference_SelectionHandler_Generic.class.php index bf5e1a0..35f06f5 100644 --- a/plugins/selection/EntityReference_SelectionHandler_Generic.class.php +++ b/plugins/selection/EntityReference_SelectionHandler_Generic.class.php @@ -167,12 +167,10 @@ class EntityReference_SelectionHandler_Generic implements EntityReference_Select $results = $query->execute(); if (!empty($results[$entity_type])) { - $entity_info = entity_get_info($entity_type); $entities = entity_load($entity_type, array_keys($results[$entity_type])); foreach ($entities as $entity_id => $entity) { list(,, $bundle) = entity_extract_ids($entity_type, $entity); - $bundle_label = check_plain($entity_info['bundles'][$bundle]['label']); - $options[$bundle_label][$entity_id] = check_plain($this->getLabel($entity)); + $options[$bundle][$entity_id] = check_plain($this->getLabel($entity)); } } @@ -509,7 +507,7 @@ class EntityReference_SelectionHandler_Generic_taxonomy_term extends EntityRefer if ($vocabulary = taxonomy_vocabulary_machine_name_load($bundle)) { if ($terms = taxonomy_get_tree($vocabulary->vid, 0)) { foreach ($terms as $term) { - $options[$vocabulary->name][$term->tid] = str_repeat('-', $term->depth) . check_plain($term->name); + $options[$vocabulary->machine_name][$term->tid] = str_repeat('-', $term->depth) . check_plain($term->name); } } } diff --git a/plugins/selection/EntityReference_SelectionHandler_Views.class.php b/plugins/selection/EntityReference_SelectionHandler_Views.class.php index 8f9d368..1b036a7 100644 --- a/plugins/selection/EntityReference_SelectionHandler_Views.class.php +++ b/plugins/selection/EntityReference_SelectionHandler_Views.class.php @@ -114,12 +114,10 @@ class EntityReference_SelectionHandler_Views implements EntityReference_Selectio $return = array(); if ($result) { $target_type = $this->field['settings']['target_type']; - $entity_info = entity_get_info($target_type); $entities = entity_load($target_type, array_keys($result)); foreach($entities as $entity) { list($id,, $bundle) = entity_extract_ids($target_type, $entity); - $bundle_label = check_plain($entity_info['bundles'][$bundle]['label']); - $return[$bundle_label][$id] = $result[$id]; + $return[$bundle][$id] = $result[$id]; } } return $return;