function views_handler_field_field::get_value
Overrides views_handler_field::get_value
1 call to views_handler_field_field::get_value()
- views_handler_field_field::set_items in modules/
field/ views_handler_field_field.inc - Return an array of items for the field.
File
-
modules/
field/ views_handler_field_field.inc, line 755
Class
- views_handler_field_field
- A field that displays fieldapi fields.
Code
public function get_value($values, $field = NULL) {
if (!isset($values->_field_data[$this->field_alias]['entity']) || !is_object($values->_field_data[$this->field_alias]['entity'])) {
return array();
}
// Go ahead and render and store in $this->items.
$entity = clone $values->_field_data[$this->field_alias]['entity'];
$entity_type = $values->_field_data[$this->field_alias]['entity_type'];
$langcode = $this->field_language($entity_type, $entity);
// If we are grouping, copy our group fields into the cloned entity.
// It's possible this will cause some weirdness, but there's only
// so much we can hope to do.
if (!empty($this->group_fields)) {
// first, test to see if we have a base value.
$base_value = array();
// Note: We would copy original values here, but it can cause problems.
// For example, text fields store cached filtered values as
// 'safe_value' which doesn't appear anywhere in the field definition
// so we can't affect it. Other side effects could happen similarly.
$data = FALSE;
foreach ($this->group_fields as $field_name => $column) {
if (property_exists($values, $this->aliases[$column])) {
$base_value[$field_name] = $values->{$this->aliases[$column]};
if (isset($base_value[$field_name])) {
$data = TRUE;
}
}
}
// If any of our aggregated fields have data, fake it.
if ($data) {
// Now, overwrite the original value with our aggregated value.
// This overwrites it so there is always just one entry.
$entity->{$this->definition['field_name']}[$langcode] = array(
$base_value,
);
}
else {
$entity->{$this->definition['field_name']}[$langcode] = array();
}
}
// The field we are trying to display doesn't exist on this entity.
if (!isset($entity->{$this->definition['field_name']})) {
return array();
}
// If requested, randomize the order of the deltas.
if ($this->options['delta_random'] && !empty($entity->{$this->definition['field_name']})) {
shuffle($entity->{$this->definition['field_name']}[$langcode]);
}
// We are supposed to show only certain deltas.
if ($this->limit_values && !empty($entity->{$this->definition['field_name']})) {
$all_values = !empty($entity->{$this->definition['field_name']}[$langcode]) ? $entity->{$this->definition['field_name']}[$langcode] : array();
if ($this->options['delta_reversed']) {
$all_values = array_reverse($all_values);
}
// Offset is calculated differently when row grouping for a field is
// not enabled. Since there are multiple rows, the delta needs to be
// taken into account, so that different values are shown per row.
if (!$this->options['group_rows'] && isset($this->aliases['delta']) && isset($values->{$this->aliases['delta']})) {
$delta_limit = 1;
$offset = $values->{$this->aliases['delta']};
}
elseif (!$this->options['group_rows'] && !$this->multiple) {
$delta_limit = 1;
$offset = 0;
}
else {
$delta_limit = $this->options['delta_limit'];
$offset = intval($this->options['delta_offset']);
// We should only get here in this case if there's an offset, and
// in that case we're limiting to all values after the offset.
if ($delta_limit == 'all') {
$delta_limit = count($all_values) - $offset;
}
}
// Determine if only the first and last values should be shown.
$delta_first_last = $this->options['delta_first_last'];
$new_values = array();
for ($i = 0; $i < $delta_limit; $i++) {
$new_delta = $offset + $i;
if (isset($all_values[$new_delta])) {
// If first-last option was selected, only use the first and last
// values.
if (!$delta_first_last || $new_delta == $offset || $new_delta == $delta_limit + $offset - 1) {
$new_values[] = $all_values[$new_delta];
}
}
}
$entity->{$this->definition['field_name']}[$langcode] = $new_values;
}
if ($field == 'entity') {
return $entity;
}
else {
return !empty($entity->{$this->definition['field_name']}[$langcode]) ? $entity->{$this->definition['field_name']}[$langcode] : array();
}
}