protected function Field::createEntityForGroupBy in Zircon Profile 8
Same name and namespace in other branches
- 8.0 core/modules/views/src/Plugin/views/field/Field.php \Drupal\views\Plugin\views\field\Field::createEntityForGroupBy()
Creates a fake entity with grouped field values.
Parameters
\Drupal\Core\Entity\EntityInterface $entity: The entity to be processed.
\Drupal\views\ResultRow $row: The result row object containing the values.
Return value
bool|\Drupal\Core\Entity\FieldableEntityInterface Returns a new entity object containing the grouped field values.
File
- core/
modules/ views/ src/ Plugin/ views/ field/ Field.php, line 863 - Contains \Drupal\views\Plugin\views\field\Field.
Class
- Field
- A field that displays entity field data.
Namespace
Drupal\views\Plugin\views\fieldCode
protected function createEntityForGroupBy(EntityInterface $entity, ResultRow $row) {
// Retrieve the correct translation object.
$processed_entity = clone $this
->getEntityFieldRenderer()
->getEntityTranslation($entity, $row);
// Copy our group fields into the cloned entity. It is possible this will
// cause some weirdness, but there is only so much we can hope to do.
if (!empty($this->group_fields) && isset($entity->{$this->definition['field_name']})) {
// 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 does not appear anywhere in the field definition so we cannot
// affect it. Other side effects could happen similarly.
$data = FALSE;
foreach ($this->group_fields as $field_name => $column) {
if (property_exists($row, $this->aliases[$column])) {
$base_value[$field_name] = $row->{$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.
$processed_entity->{$this->definition['field_name']} = array(
$base_value,
);
}
else {
$processed_entity->{$this->definition['field_name']} = array();
}
}
return $processed_entity;
}