public static function EntityFieldHandlerHelper::get_value in Entity API 7
Get the value of a certain data selector.
Uses $values->_entity_properties to look for already extracted properties.
Parameters
$handler: The field handler for which to return a value.
$values: The values for the current row retrieved from the Views query, as an object.
$field: The field to extract. If no value is given, the field of the given handler is used instead. The special "entity object" value can be used to get the base entity instead of a special field.
$default: The value to return if the entity or field are not present.
9 calls to EntityFieldHandlerHelper::get_value()
- entity_views_handler_field_boolean::get_value in views/
handlers/ entity_views_handler_field_boolean.inc - Overridden to use a metadata wrapper.
- entity_views_handler_field_date::get_value in views/
handlers/ entity_views_handler_field_date.inc - Overridden to use a metadata wrapper.
- entity_views_handler_field_duration::get_value in views/
handlers/ entity_views_handler_field_duration.inc - Overridden to use a metadata wrapper.
- entity_views_handler_field_entity::get_value in views/
handlers/ entity_views_handler_field_entity.inc - Overridden to use a metadata wrapper.
- entity_views_handler_field_field::get_items in views/
handlers/ entity_views_handler_field_field.inc - Overridden to get the items our way.
File
- views/
handlers/ entity_views_field_handler_helper.inc, line 319 - Contains the EntityFieldHandlerHelper class.
Class
- EntityFieldHandlerHelper
- Helper class containing static implementations of common field handler methods.
Code
public static function get_value($handler, $values, $field = NULL, $default = NULL) {
// There is a value cache on each handler so parent handlers rendering a
// single field value from a list will get the single value, not the whole
// list.
if (!isset($field) && isset($handler->current_value)) {
return $handler->current_value;
}
$field = isset($field) ? $field : self::get_selector_field_name($handler->real_field);
$selector = self::construct_property_selector($handler);
$selector = $selector ? "{$selector}:{$field}" : $field;
if (!isset($values->_entity_properties)) {
$values->_entity_properties = array();
}
if (!array_key_exists($selector, $values->_entity_properties)) {
if (!isset($handler->wrappers[$handler->view->row_index])) {
$values->_entity_properties[$selector] = $default;
}
elseif (is_array($handler->wrappers[$handler->view->row_index])) {
$values->_entity_properties[$selector] = self::extract_list_wrapper_values($handler->wrappers[$handler->view->row_index], $field);
}
else {
$wrapper = $handler->wrappers[$handler->view->row_index];
try {
if ($field === 'entity object') {
$values->_entity_properties[$selector] = $wrapper
->value();
}
else {
$values->_entity_properties[$selector] = isset($wrapper->{$field}) ? $wrapper->{$field}
->value(array(
'identifier' => TRUE,
'sanitize' => TRUE,
)) : $default;
}
} catch (EntityMetadataWrapperException $e) {
$values->_entity_properties[$selector] = $default;
}
}
}
return $values->_entity_properties[$selector];
}