function entity_reference_options_list

Implements hook_options_list().

File

drupal/core/modules/entity_reference/entity_reference.module, line 366
Provides a field that can reference other entities.

Code

function entity_reference_options_list($field, $instance, $entity_type = NULL, $entity = NULL) {
  if (!($options = entity_reference_get_selection_handler($field, $instance, $entity)
    ->getReferencableEntities())) {
    return array();
  }

  // Rebuild the array by changing the bundle key into the bundle label.
  $target_type = $field['settings']['target_type'];
  $bundles = entity_get_bundles($target_type);
  $return = array();
  foreach ($options as $bundle => $entity_ids) {
    $bundle_label = check_plain($bundles[$bundle]['label']);
    $return[$bundle_label] = $entity_ids;
  }
  return count($return) == 1 ? reset($return) : $return;
}