public function Field::getValue in Zircon Profile 8.0
Same name and namespace in other branches
- 8 core/modules/views/src/Plugin/views/field/Field.php \Drupal\views\Plugin\views\field\Field::getValue()
Gets the value that's supposed to be rendered.
This api exists so that other modules can easy set the values of the field without having the need to change the render method as well.
Parameters
\Drupal\views\ResultRow $values: An object containing all retrieved values.
string $field: Optional name of the field where the value is stored.
Overrides FieldPluginBase::getValue
File
- core/
modules/ views/ src/ Plugin/ views/ field/ Field.php, line 1001 - Contains \Drupal\views\Plugin\views\field\Field.
Class
- Field
- A field that displays entity field data.
Namespace
Drupal\views\Plugin\views\fieldCode
public function getValue(ResultRow $values, $field = NULL) {
/** @var \Drupal\Core\Field\FieldItemListInterface $field_item_list */
$field_item_list = $this
->getEntity($values)->{$this->definition['field_name']};
$field_item_definition = $field_item_list
->getFieldDefinition();
if ($field_item_definition
->getFieldStorageDefinition()
->getCardinality() == 1) {
return $field ? $field_item_list->{$field} : $field_item_list->value;
}
$values = [];
foreach ($field_item_list as $field_item) {
$values[] = $field ? $field_item->{$field} : $field_item->value;
}
return $values;
}