diff --git a/modules/callbacks.inc b/modules/callbacks.inc index 1ece786..64d020a 100644 --- a/modules/callbacks.inc +++ b/modules/callbacks.inc @@ -436,13 +436,24 @@ function entity_metadata_field_property_set($entity, $name, $value, $langcode, $ * Callback returning the options list of a field. */ 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)) { - return (array) module_invoke($field['module'], 'options_list', $field); + 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; + } + $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); } }