protected function ViewsResultTreeValues::normalizeKey in Views tree 8.2
Normalize a value out of the record to an int.
If the field in question comes from Field API, then it will be an array, not an int. We need to detect that and extract the int value we want from it. Note that because Field API structures are so free-form, we have to specifically support each field type. For now we support entityreference (target_id), nodereference (nid), userreference (uid), organic groups (gid), and taxonomyreference (tid).
Parameters
mixed $value: The value to normalize. It should be either an int or an array. If an int, it is returned unaltered. If it's an array, we extract the int we want and return that.
\Drupal\views\Plugin\views\field\FieldPluginBase $field: Metadata about the field we are extracting information from.
Return value
int The value of this key, normalized to an int.
1 call to ViewsResultTreeValues::normalizeKey()
- ViewsResultTreeValues::setTreeValues in src/
ViewsResultTreeValues.php - Sets tree values given a view and result set.
File
- src/
ViewsResultTreeValues.php, line 127
Class
- ViewsResultTreeValues
- Methods to get result tree based on views results.
Namespace
Drupal\views_treeCode
protected function normalizeKey($value, FieldPluginBase $field) {
if (is_array($value) && count($value)) {
return reset($value);
}
else {
return $value ? $value : 0;
}
}