You are here

function entity_metadata_field_options_list in Entity API 7

Callback returning the options list of a field.

2 string references to 'entity_metadata_field_options_list'
entity_metadata_field_default_property_callback in modules/field.info.inc
Callback to add in property info defaults per field instance.
entity_metadata_field_term_reference_callback in modules/field.info.inc
Additional callback to adapt the property info for term reference fields.

File

modules/callbacks.inc, line 490
Provides various callbacks for the whole core module integration.

Code

function entity_metadata_field_options_list($name, $info) {
  $field_property_info = $info;
  if (is_numeric($name) && isset($info['parent'])) {

    // The options list is to be returned for a single item of a multiple field.
    $field_property_info = $info['parent']
      ->info();
    $name = $field_property_info['name'];
  }
  if (($field = field_info_field($name)) && isset($field_property_info['parent'])) {

    // Retrieve the wrapped entity holding the field.
    $wrapper = $field_property_info['parent'];
    try {
      $entity = $wrapper
        ->value();
    } catch (EntityMetadataWrapperException $e) {

      // No data available.
      $entity = NULL;
    }

    // Support translating labels via i18n field.
    if (module_exists('i18n_field') && ($translate = i18n_field_type_info($field['type'], 'translate_options'))) {
      return $translate($field);
    }
    else {
      $instance = $wrapper
        ->getBundle() ? field_info_instance($wrapper
        ->type(), $name, $wrapper
        ->getBundle()) : NULL;
      return (array) module_invoke($field['module'], 'options_list', $field, $instance, $wrapper
        ->type(), $entity);
    }
  }
}